class TestAssemblyFileAsOnlyParameter(expect.ValidObjectFile1_5): """Tests that spirv-opt accepts a SPIR-V object file.""" shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') output = placeholder.TempFileName('output.spv') spirv_args = [shader, '-o', output] expected_object_filenames = (output)
class TestSizeOptimizationPasses(expect.ValidObjectFile1_3, expect.ExecutedListOfPasses): """Tests that spirv-opt schedules all the passes triggered by -Os.""" flags = ['-Os'] expected_passes = [ 'merge-return', 'inline-entry-points-exhaustive', 'eliminate-dead-code-aggressive', 'private-to-local', 'scalar-replacement=100', 'convert-local-access-chains', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'simplify-instructions', 'eliminate-dead-inserts', 'eliminate-local-multi-store', 'eliminate-dead-code-aggressive', 'ccp', 'eliminate-dead-code-aggressive', 'eliminate-dead-branches', 'if-conversion', 'eliminate-dead-code-aggressive', 'merge-blocks', 'simplify-instructions', 'eliminate-dead-inserts', 'redundancy-elimination', 'cfg-cleanup', 'eliminate-dead-code-aggressive', ] shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') output = placeholder.TempFileName('output.spv') spirv_args = [shader, '-o', output, '--print-all'] + flags expected_object_filenames = (output)
class TestLegalizationPasses(expect.ValidObjectFile1_3, expect.ExecutedListOfPasses): """Tests that spirv-opt schedules all the passes triggered by --legalize-hlsl. """ flags = ['--legalize-hlsl'] expected_passes = [ 'eliminate-dead-branches', 'merge-return', 'inline-entry-points-exhaustive', 'eliminate-dead-functions', 'private-to-local', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'scalar-replacement=0', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'eliminate-local-multi-store', 'eliminate-dead-code-aggressive', 'ccp', 'eliminate-dead-branches', 'simplify-instructions', 'eliminate-dead-code-aggressive', 'copy-propagate-arrays', 'vector-dce', 'eliminate-dead-inserts', 'reduce-load-size', 'eliminate-dead-code-aggressive', ] shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') output = placeholder.TempFileName('output.spv') spirv_args = [shader, '-o', output, '--print-all'] + flags expected_object_filenames = (output)
class TestPerformanceOptimizationPasses(expect.ValidObjectFile1_6, expect.ExecutedListOfPasses): """Tests that spirv-opt schedules all the passes triggered by -O.""" flags = ['-O'] expected_passes = [ 'wrap-opkill', 'eliminate-dead-branches', 'merge-return', 'inline-entry-points-exhaustive', 'eliminate-dead-functions', 'eliminate-dead-code-aggressive', 'private-to-local', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'scalar-replacement=100', 'convert-local-access-chains', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'ssa-rewrite', 'eliminate-dead-code-aggressive', 'ccp', 'eliminate-dead-code-aggressive', 'loop-unroll', 'eliminate-dead-branches', 'redundancy-elimination', 'combine-access-chains', 'simplify-instructions', 'scalar-replacement=100', 'convert-local-access-chains', 'eliminate-local-single-block', 'eliminate-local-single-store', 'eliminate-dead-code-aggressive', 'ssa-rewrite', 'eliminate-dead-code-aggressive', 'vector-dce', 'eliminate-dead-inserts', 'eliminate-dead-branches', 'simplify-instructions', 'if-conversion', 'copy-propagate-arrays', 'reduce-load-size', 'eliminate-dead-code-aggressive', 'merge-blocks', 'redundancy-elimination', 'eliminate-dead-branches', 'merge-blocks', 'simplify-instructions', ] shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') output = placeholder.TempFileName('output.spv') spirv_args = [shader, '-o', output, '--print-all'] + flags expected_object_filenames = (output)
class TestOconfigComments(expect.SuccessfulReturn): """Tests empty config files are accepted. https://github.com/KhronosGroup/SPIRV-Tools/issues/1778 """ shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') config = placeholder.ConfigFlagsFile(""" # This is a comment. -O --loop-unroll """, '.cfg') spirv_args = [shader, '-o', placeholder.TempFileName('output.spv'), config]
class TestValidPassFlags(expect.ValidObjectFile1_5, expect.ExecutedListOfPasses): """Tests that spirv-opt accepts all valid optimization flags.""" flags = [ '--wrap-opkill', '--ccp', '--cfg-cleanup', '--combine-access-chains', '--compact-ids', '--convert-local-access-chains', '--copy-propagate-arrays', '--eliminate-dead-branches', '--eliminate-dead-code-aggressive', '--eliminate-dead-const', '--eliminate-dead-functions', '--eliminate-dead-inserts', '--eliminate-dead-variables', '--eliminate-insert-extract', '--eliminate-local-multi-store', '--eliminate-local-single-block', '--eliminate-local-single-store', '--flatten-decorations', '--fold-spec-const-op-composite', '--freeze-spec-const', '--if-conversion', '--inline-entry-points-exhaustive', '--loop-fission', '20', '--loop-fusion', '5', '--loop-unroll', '--loop-unroll-partial', '3', '--loop-peeling', '--merge-blocks', '--merge-return', '--loop-unswitch', '--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', '--unify-const', '--legalize-vector-shuffle', '--split-invalid-unreachable', '--generate-webgpu-initializers', '--decompose-initialized-variables', '--graphics-robust-access', '--wrap-opkill', '--amd-ext-to-khr' ] expected_passes = [ 'wrap-opkill', 'ccp', 'cfg-cleanup', 'combine-access-chains', 'compact-ids', 'convert-local-access-chains', 'copy-propagate-arrays', 'eliminate-dead-branches', 'eliminate-dead-code-aggressive', 'eliminate-dead-const', 'eliminate-dead-functions', 'eliminate-dead-inserts', 'eliminate-dead-variables', # --eliminate-insert-extract runs the simplify-instructions pass. 'simplify-instructions', 'ssa-rewrite', 'eliminate-local-single-block', 'eliminate-local-single-store', 'flatten-decorations', 'fold-spec-const-op-composite', 'freeze-spec-const', 'if-conversion', 'inline-entry-points-exhaustive', 'loop-fission', 'loop-fusion', 'loop-unroll', 'loop-unroll', 'loop-peeling', 'merge-blocks', 'merge-return', 'loop-unswitch', 'private-to-local', 'reduce-load-size', 'redundancy-elimination', 'remove-duplicates', 'replace-invalid-opcode', 'ssa-rewrite', 'scalar-replacement=100', 'scalar-replacement=42', 'strength-reduction', 'strip-debug', 'strip-reflect', 'vector-dce', 'workaround-1209', 'unify-const', 'legalize-vector-shuffle', 'split-invalid-unreachable', 'generate-webgpu-initializers', 'decompose-initialized-variables', 'graphics-robust-access', 'wrap-opkill', 'amd-ext-to-khr' ] shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') output = placeholder.TempFileName('output.spv') spirv_args = [shader, '-o', output, '--print-all'] + flags expected_object_filenames = (output)
class TestOconfigEmpty(expect.SuccessfulReturn): """Tests empty config files are accepted.""" shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm') config = placeholder.ConfigFlagsFile('', '.cfg') spirv_args = [shader, '-o', placeholder.TempFileName('output.spv'), config]