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/strength_reduction_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/type_manager.cpp \
source/opt/types.cpp \

View File

@ -738,8 +738,8 @@ static_library("spvtools_opt") {
"source/opt/strength_reduction_pass.h",
"source/opt/strip_debug_info_pass.cpp",
"source/opt/strip_debug_info_pass.h",
"source/opt/strip_reflect_info_pass.cpp",
"source/opt/strip_reflect_info_pass.h",
"source/opt/strip_nonsemantic_info_pass.cpp",
"source/opt/strip_nonsemantic_info_pass.h",
"source/opt/struct_cfg_analysis.cpp",
"source/opt/struct_cfg_analysis.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.
Optimizer::PassToken CreateStripDebugInfoPass();
// Creates a strip-reflect-info pass.
// 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.
// [Deprecated] This will create a strip-nonsemantic-info pass. See below.
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.
// An eliminate-dead-functions pass will remove all functions that are not in
// 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
strength_reduction_pass.h
strip_debug_info_pass.h
strip_reflect_info_pass.h
strip_nonsemantic_info_pass.h
struct_cfg_analysis.h
tree_iterator.h
type_manager.h
@ -218,7 +218,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
ssa_rewrite_pass.cpp
strength_reduction_pass.cpp
strip_debug_info_pass.cpp
strip_reflect_info_pass.cpp
strip_nonsemantic_info_pass.cpp
struct_cfg_analysis.cpp
type_manager.cpp
types.cpp

View File

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

View File

@ -74,7 +74,7 @@
#include "source/opt/ssa_rewrite_pass.h"
#include "source/opt/strength_reduction_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/upgrade_memory_model.h"
#include "source/opt/vector_dce.h"

View File

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

View File

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

View File

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

View File

@ -13,10 +13,9 @@
// limitations under the License.
#include <string>
#include "gmock/gmock.h"
#include "spirv-tools/optimizer.hpp"
#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"
@ -24,7 +23,6 @@ namespace spvtools {
namespace opt {
namespace {
using StripLineReflectInfoTest = PassTest<::testing::Test>;
using StripNonSemanticInfoTest = PassTest<::testing::Test>;
// 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,
// but then want to filter out the extra instructions before sending
// 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.
std::string before = R"(OpCapability Shader
OpCapability Linkage
@ -49,11 +47,11 @@ OpDecorateStringGOOGLE %void HlslSemanticGOOGLE "my goodness"
std::vector<uint32_t> 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
// into |binary_out|.
spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_1);
optimizer.RegisterPass(spvtools::CreateStripReflectInfoPass());
optimizer.RegisterPass(spvtools::CreateStripNonSemanticInfoPass());
std::vector<uint32_t> 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,
// 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.
std::string before = R"(OpCapability Shader
OpCapability Linkage
@ -90,10 +88,10 @@ OpMemoryModel Logical Simple
%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
OpCapability Linkage
OpExtension "SPV_GOOGLE_hlsl_functionality1"
@ -109,10 +107,10 @@ OpMemoryModel Logical Simple
%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.
std::string before = R"(OpCapability Shader
OpCapability Linkage
@ -130,7 +128,7 @@ OpMemoryModel Logical Simple
%_struct_3 = OpTypeStruct %float
)";
SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false);
SinglePassRunAndCheck<StripNonSemanticInfoPass>(before, after, false);
}
TEST_F(StripNonSemanticInfoTest, StripNonSemanticImport) {
@ -144,7 +142,7 @@ OpExtension "SPV_KHR_non_semantic_info"
OpMemoryModel Logical GLSL450
)";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true);
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
}
TEST_F(StripNonSemanticInfoTest, StripNonSemanticGlobal) {
@ -159,7 +157,7 @@ OpMemoryModel Logical GLSL450
%1 = OpExtInst %void %ext 1
)";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true);
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
}
TEST_F(StripNonSemanticInfoTest, StripNonSemanticInFunction) {
@ -179,7 +177,7 @@ OpReturn
OpFunctionEnd
)";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true);
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
}
TEST_F(StripNonSemanticInfoTest, StripNonSemanticAfterFunction) {
@ -199,7 +197,7 @@ OpFunctionEnd
%1 = OpExtInst %void %ext 1 %foo
)";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true);
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
}
TEST_F(StripNonSemanticInfoTest, StripNonSemanticBetweenFunctions) {
@ -223,7 +221,7 @@ OpReturn
OpFunctionEnd
)";
SinglePassRunAndMatch<StripReflectInfoPass>(text, true);
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
}
} // namespace

View File

@ -72,7 +72,7 @@ class TestValidPassFlags(expect.ValidObjectFile1_5,
'--private-to-local', '--reduce-load-size', '--redundancy-elimination',
'--remove-duplicates', '--replace-invalid-opcode', '--ssa-rewrite',
'--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'
]
expected_passes = [
@ -117,7 +117,7 @@ class TestValidPassFlags(expect.ValidObjectFile1_5,
'scalar-replacement=42',
'strength-reduction',
'strip-debug',
'strip-reflect',
'strip-nonsemantic',
'vector-dce',
'workaround-1209',
'unify-const',

View File

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