Rename strip reflect to strip nonsemantic (#4661)

In https://github.com/KhronosGroup/SPIRV-Tools/pull/3110, the strip reflect
pass was changed to also remove all explicitly nonsemantic instructions.  This
makes it so that the name of the pass no longer reflects what the pass actually
does.  This change renames the pass so that it reflects what the pass actaully does.
This commit is contained in:
Steven Perron 2021-12-15 09:55:30 -05:00 committed by GitHub
parent 4322c4b5a7
commit 354a46a2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 51 additions and 43 deletions

View File

@ -168,7 +168,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/ssa_rewrite_pass.cpp \ source/opt/ssa_rewrite_pass.cpp \
source/opt/strength_reduction_pass.cpp \ source/opt/strength_reduction_pass.cpp \
source/opt/strip_debug_info_pass.cpp \ source/opt/strip_debug_info_pass.cpp \
source/opt/strip_reflect_info_pass.cpp \ source/opt/strip_nonsemantic_info_pass.cpp \
source/opt/struct_cfg_analysis.cpp \ source/opt/struct_cfg_analysis.cpp \
source/opt/type_manager.cpp \ source/opt/type_manager.cpp \
source/opt/types.cpp \ source/opt/types.cpp \

View File

@ -738,8 +738,8 @@ static_library("spvtools_opt") {
"source/opt/strength_reduction_pass.h", "source/opt/strength_reduction_pass.h",
"source/opt/strip_debug_info_pass.cpp", "source/opt/strip_debug_info_pass.cpp",
"source/opt/strip_debug_info_pass.h", "source/opt/strip_debug_info_pass.h",
"source/opt/strip_reflect_info_pass.cpp", "source/opt/strip_nonsemantic_info_pass.cpp",
"source/opt/strip_reflect_info_pass.h", "source/opt/strip_nonsemantic_info_pass.h",
"source/opt/struct_cfg_analysis.cpp", "source/opt/struct_cfg_analysis.cpp",
"source/opt/struct_cfg_analysis.h", "source/opt/struct_cfg_analysis.h",
"source/opt/tree_iterator.h", "source/opt/tree_iterator.h",

View File

@ -230,13 +230,14 @@ Optimizer::PassToken CreateNullPass();
// Section 3.32.2 of the SPIR-V spec) of the SPIR-V module to be optimized. // Section 3.32.2 of the SPIR-V spec) of the SPIR-V module to be optimized.
Optimizer::PassToken CreateStripDebugInfoPass(); Optimizer::PassToken CreateStripDebugInfoPass();
// Creates a strip-reflect-info pass. // [Deprecated] This will create a strip-nonsemantic-info pass. See below.
// A strip-reflect-info pass removes all reflections instructions.
// For now, this is limited to removing decorations defined in
// SPV_GOOGLE_hlsl_functionality1. The coverage may expand in
// the future.
Optimizer::PassToken CreateStripReflectInfoPass(); Optimizer::PassToken CreateStripReflectInfoPass();
// Creates a strip-nonsemantic-info pass.
// A strip-nonsemantic-info pass removes all reflections and explicitly
// non-semantic instructions.
Optimizer::PassToken CreateStripNonSemanticInfoPass();
// Creates an eliminate-dead-functions pass. // Creates an eliminate-dead-functions pass.
// An eliminate-dead-functions pass will remove all functions that are not in // An eliminate-dead-functions pass will remove all functions that are not in
// the call trees rooted at entry points and exported functions. These // the call trees rooted at entry points and exported functions. These

View File

@ -111,7 +111,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
ssa_rewrite_pass.h ssa_rewrite_pass.h
strength_reduction_pass.h strength_reduction_pass.h
strip_debug_info_pass.h strip_debug_info_pass.h
strip_reflect_info_pass.h strip_nonsemantic_info_pass.h
struct_cfg_analysis.h struct_cfg_analysis.h
tree_iterator.h tree_iterator.h
type_manager.h type_manager.h
@ -218,7 +218,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
ssa_rewrite_pass.cpp ssa_rewrite_pass.cpp
strength_reduction_pass.cpp strength_reduction_pass.cpp
strip_debug_info_pass.cpp strip_debug_info_pass.cpp
strip_reflect_info_pass.cpp strip_nonsemantic_info_pass.cpp
struct_cfg_analysis.cpp struct_cfg_analysis.cpp
type_manager.cpp type_manager.cpp
types.cpp types.cpp

View File

@ -288,6 +288,8 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag) {
RegisterPass(CreateStripDebugInfoPass()); RegisterPass(CreateStripDebugInfoPass());
} else if (pass_name == "strip-reflect") { } else if (pass_name == "strip-reflect") {
RegisterPass(CreateStripReflectInfoPass()); RegisterPass(CreateStripReflectInfoPass());
} else if (pass_name == "strip-nonsemantic") {
RegisterPass(CreateStripNonSemanticInfoPass());
} else if (pass_name == "set-spec-const-default-value") { } else if (pass_name == "set-spec-const-default-value") {
if (pass_args.size() > 0) { if (pass_args.size() > 0) {
auto spec_ids_vals = auto spec_ids_vals =
@ -653,8 +655,12 @@ Optimizer::PassToken CreateStripDebugInfoPass() {
} }
Optimizer::PassToken CreateStripReflectInfoPass() { Optimizer::PassToken CreateStripReflectInfoPass() {
return CreateStripNonSemanticInfoPass();
}
Optimizer::PassToken CreateStripNonSemanticInfoPass() {
return MakeUnique<Optimizer::PassToken::Impl>( return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::StripReflectInfoPass>()); MakeUnique<opt::StripNonSemanticInfoPass>());
} }
Optimizer::PassToken CreateEliminateDeadFunctionsPass() { Optimizer::PassToken CreateEliminateDeadFunctionsPass() {

View File

@ -74,7 +74,7 @@
#include "source/opt/ssa_rewrite_pass.h" #include "source/opt/ssa_rewrite_pass.h"
#include "source/opt/strength_reduction_pass.h" #include "source/opt/strength_reduction_pass.h"
#include "source/opt/strip_debug_info_pass.h" #include "source/opt/strip_debug_info_pass.h"
#include "source/opt/strip_reflect_info_pass.h" #include "source/opt/strip_nonsemantic_info_pass.h"
#include "source/opt/unify_const_pass.h" #include "source/opt/unify_const_pass.h"
#include "source/opt/upgrade_memory_model.h" #include "source/opt/upgrade_memory_model.h"
#include "source/opt/vector_dce.h" #include "source/opt/vector_dce.h"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "source/opt/strip_reflect_info_pass.h" #include "source/opt/strip_nonsemantic_info_pass.h"
#include <cstring> #include <cstring>
#include <vector> #include <vector>
@ -24,7 +24,7 @@
namespace spvtools { namespace spvtools {
namespace opt { namespace opt {
Pass::Status StripReflectInfoPass::Process() { Pass::Status StripNonSemanticInfoPass::Process() {
bool modified = false; bool modified = false;
std::vector<Instruction*> to_remove; std::vector<Instruction*> to_remove;

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SOURCE_OPT_STRIP_REFLECT_INFO_PASS_H_ #ifndef SOURCE_OPT_STRIP_NONSEMANTIC_INFO_PASS_H_
#define SOURCE_OPT_STRIP_REFLECT_INFO_PASS_H_ #define SOURCE_OPT_STRIP_NONSEMANTIC_INFO_PASS_H_
#include "source/opt/ir_context.h" #include "source/opt/ir_context.h"
#include "source/opt/module.h" #include "source/opt/module.h"
@ -23,9 +23,9 @@ namespace spvtools {
namespace opt { namespace opt {
// See optimizer.hpp for documentation. // See optimizer.hpp for documentation.
class StripReflectInfoPass : public Pass { class StripNonSemanticInfoPass : public Pass {
public: public:
const char* name() const override { return "strip-reflect"; } const char* name() const override { return "strip-nonsemantic"; }
Status Process() override; Status Process() override;
// Return the mask of preserved Analyses. // Return the mask of preserved Analyses.
@ -41,4 +41,4 @@ class StripReflectInfoPass : public Pass {
} // namespace opt } // namespace opt
} // namespace spvtools } // namespace spvtools
#endif // SOURCE_OPT_STRIP_REFLECT_INFO_PASS_H_ #endif // SOURCE_OPT_STRIP_NONSEMANTIC_INFO_PASS_H_

View File

@ -93,7 +93,7 @@ add_spvtools_unittest(TARGET opt
simplification_test.cpp simplification_test.cpp
strength_reduction_test.cpp strength_reduction_test.cpp
strip_debug_info_test.cpp strip_debug_info_test.cpp
strip_reflect_info_test.cpp strip_nonsemantic_info_test.cpp
struct_cfg_analysis_test.cpp struct_cfg_analysis_test.cpp
type_manager_test.cpp type_manager_test.cpp
types_test.cpp types_test.cpp

View File

@ -147,7 +147,7 @@ TEST(Optimizer, CanRegisterPassesFromFlags) {
std::vector<std::string> pass_flags = { std::vector<std::string> pass_flags = {
"--strip-debug", "--strip-debug",
"--strip-reflect", "--strip-nonsemantic",
"--set-spec-const-default-value=23:42 21:12", "--set-spec-const-default-value=23:42 21:12",
"--if-conversion", "--if-conversion",
"--freeze-spec-const", "--freeze-spec-const",

View File

@ -13,10 +13,9 @@
// limitations under the License. // limitations under the License.
#include <string> #include <string>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "spirv-tools/optimizer.hpp" #include "spirv-tools/optimizer.hpp"
#include "test/opt/pass_fixture.h" #include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h" #include "test/opt/pass_utils.h"
@ -24,7 +23,6 @@ namespace spvtools {
namespace opt { namespace opt {
namespace { namespace {
using StripLineReflectInfoTest = PassTest<::testing::Test>;
using StripNonSemanticInfoTest = PassTest<::testing::Test>; using StripNonSemanticInfoTest = PassTest<::testing::Test>;
// This test acts as an end-to-end code example on how to strip // This test acts as an end-to-end code example on how to strip
@ -33,7 +31,7 @@ using StripNonSemanticInfoTest = PassTest<::testing::Test>;
// option -fhlsl_functionality1 to insert reflection information, // option -fhlsl_functionality1 to insert reflection information,
// but then want to filter out the extra instructions before sending // but then want to filter out the extra instructions before sending
// it to a driver that does not implement VK_GOOGLE_hlsl_functionality1. // it to a driver that does not implement VK_GOOGLE_hlsl_functionality1.
TEST_F(StripLineReflectInfoTest, StripReflectEnd2EndExample) { TEST_F(StripNonSemanticInfoTest, StripReflectEnd2EndExample) {
// This is a non-sensical example, but exercises the instructions. // This is a non-sensical example, but exercises the instructions.
std::string before = R"(OpCapability Shader std::string before = R"(OpCapability Shader
OpCapability Linkage OpCapability Linkage
@ -49,11 +47,11 @@ OpDecorateStringGOOGLE %void HlslSemanticGOOGLE "my goodness"
std::vector<uint32_t> binary_in; std::vector<uint32_t> binary_in;
tools.Assemble(before, &binary_in); tools.Assemble(before, &binary_in);
// Instantiate the optimizer, and run the strip-reflection-info // Instantiate the optimizer, and run the strip-nonsemantic-info
// pass over the |binary_in| module, and place the modified module // pass over the |binary_in| module, and place the modified module
// into |binary_out|. // into |binary_out|.
spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_1); spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_1);
optimizer.RegisterPass(spvtools::CreateStripReflectInfoPass()); optimizer.RegisterPass(spvtools::CreateStripNonSemanticInfoPass());
std::vector<uint32_t> binary_out; std::vector<uint32_t> binary_out;
optimizer.Run(binary_in.data(), binary_in.size(), &binary_out); optimizer.Run(binary_in.data(), binary_in.size(), &binary_out);
@ -71,7 +69,7 @@ OpMemoryModel Logical Simple
// This test is functionally the same as the end-to-end test above, // This test is functionally the same as the end-to-end test above,
// but uses the test SinglePassRunAndCheck test fixture instead. // but uses the test SinglePassRunAndCheck test fixture instead.
TEST_F(StripLineReflectInfoTest, StripHlslSemantic) { TEST_F(StripNonSemanticInfoTest, StripHlslSemantic) {
// This is a non-sensical example, but exercises the instructions. // This is a non-sensical example, but exercises the instructions.
std::string before = R"(OpCapability Shader std::string before = R"(OpCapability Shader
OpCapability Linkage OpCapability Linkage
@ -90,10 +88,10 @@ OpMemoryModel Logical Simple
%float = OpTypeFloat 32 %float = OpTypeFloat 32
)"; )";
SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false); SinglePassRunAndCheck<StripNonSemanticInfoPass>(before, after, false);
} }
TEST_F(StripLineReflectInfoTest, StripHlslCounterBuffer) { TEST_F(StripNonSemanticInfoTest, StripHlslCounterBuffer) {
std::string before = R"(OpCapability Shader std::string before = R"(OpCapability Shader
OpCapability Linkage OpCapability Linkage
OpExtension "SPV_GOOGLE_hlsl_functionality1" OpExtension "SPV_GOOGLE_hlsl_functionality1"
@ -109,10 +107,10 @@ OpMemoryModel Logical Simple
%float = OpTypeFloat 32 %float = OpTypeFloat 32
)"; )";
SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false); SinglePassRunAndCheck<StripNonSemanticInfoPass>(before, after, false);
} }
TEST_F(StripLineReflectInfoTest, StripHlslSemanticOnMember) { TEST_F(StripNonSemanticInfoTest, StripHlslSemanticOnMember) {
// This is a non-sensical example, but exercises the instructions. // This is a non-sensical example, but exercises the instructions.
std::string before = R"(OpCapability Shader std::string before = R"(OpCapability Shader
OpCapability Linkage OpCapability Linkage
@ -130,7 +128,7 @@ OpMemoryModel Logical Simple
%_struct_3 = OpTypeStruct %float %_struct_3 = OpTypeStruct %float
)"; )";
SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false); SinglePassRunAndCheck<StripNonSemanticInfoPass>(before, after, false);
} }
TEST_F(StripNonSemanticInfoTest, StripNonSemanticImport) { TEST_F(StripNonSemanticInfoTest, StripNonSemanticImport) {
@ -144,7 +142,7 @@ OpExtension "SPV_KHR_non_semantic_info"
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
)"; )";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true); SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
} }
TEST_F(StripNonSemanticInfoTest, StripNonSemanticGlobal) { TEST_F(StripNonSemanticInfoTest, StripNonSemanticGlobal) {
@ -159,7 +157,7 @@ OpMemoryModel Logical GLSL450
%1 = OpExtInst %void %ext 1 %1 = OpExtInst %void %ext 1
)"; )";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true); SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
} }
TEST_F(StripNonSemanticInfoTest, StripNonSemanticInFunction) { TEST_F(StripNonSemanticInfoTest, StripNonSemanticInFunction) {
@ -179,7 +177,7 @@ OpReturn
OpFunctionEnd OpFunctionEnd
)"; )";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true); SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
} }
TEST_F(StripNonSemanticInfoTest, StripNonSemanticAfterFunction) { TEST_F(StripNonSemanticInfoTest, StripNonSemanticAfterFunction) {
@ -199,7 +197,7 @@ OpFunctionEnd
%1 = OpExtInst %void %ext 1 %foo %1 = OpExtInst %void %ext 1 %foo
)"; )";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true); SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
} }
TEST_F(StripNonSemanticInfoTest, StripNonSemanticBetweenFunctions) { TEST_F(StripNonSemanticInfoTest, StripNonSemanticBetweenFunctions) {
@ -223,7 +221,7 @@ OpReturn
OpFunctionEnd OpFunctionEnd
)"; )";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true); SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
} }
} // namespace } // namespace

View File

@ -72,7 +72,7 @@ class TestValidPassFlags(expect.ValidObjectFile1_5,
'--private-to-local', '--reduce-load-size', '--redundancy-elimination', '--private-to-local', '--reduce-load-size', '--redundancy-elimination',
'--remove-duplicates', '--replace-invalid-opcode', '--ssa-rewrite', '--remove-duplicates', '--replace-invalid-opcode', '--ssa-rewrite',
'--scalar-replacement', '--scalar-replacement=42', '--strength-reduction', '--scalar-replacement', '--scalar-replacement=42', '--strength-reduction',
'--strip-debug', '--strip-reflect', '--vector-dce', '--workaround-1209', '--strip-debug', '--strip-nonsemantic', '--vector-dce', '--workaround-1209',
'--unify-const', '--graphics-robust-access', '--wrap-opkill', '--amd-ext-to-khr' '--unify-const', '--graphics-robust-access', '--wrap-opkill', '--amd-ext-to-khr'
] ]
expected_passes = [ expected_passes = [
@ -117,7 +117,7 @@ class TestValidPassFlags(expect.ValidObjectFile1_5,
'scalar-replacement=42', 'scalar-replacement=42',
'strength-reduction', 'strength-reduction',
'strip-debug', 'strip-debug',
'strip-reflect', 'strip-nonsemantic',
'vector-dce', 'vector-dce',
'workaround-1209', 'workaround-1209',
'unify-const', 'unify-const',

View File

@ -479,10 +479,13 @@ Options (in lexicographical order):)",
--strip-debug --strip-debug
Remove all debug instructions.)"); Remove all debug instructions.)");
printf(R"( printf(R"(
--strip-nonsemantic
Remove all reflection and nonsemantic information.)");
printf(R"(
--strip-reflect --strip-reflect
Remove all reflection information. For now, this covers DEPRECATED. Remove all reflection information. For now, this
reflection information defined by SPV_GOOGLE_hlsl_functionality1 covers reflection information defined by
and SPV_KHR_non_semantic_info)"); SPV_GOOGLE_hlsl_functionality1 and SPV_KHR_non_semantic_info)");
printf(R"( printf(R"(
--target-env=<env> --target-env=<env>
Set the target environment. Without this flag the target Set the target environment. Without this flag the target