Squashed 'third_party/SPIRV-Tools/' changes from d14db341b..9559cdbdf
9559cdbdf Fix #2609 - Handle out-of-bounds scalar replacements. (#2767)
f54b8653d Limit fuzzer tests so that they take less time to run (#2763)
bb0e2f65b Fix check for unreachable blocks in merge-return (#2762)
1a89ac8b2 Transformation and fuzzer pass to add dead continues (#2758)
65f49dfc3 Remove unneeded future imports (#2739)
c7fcb8c3b Process OpDecorateId in ADCE (#2761)
fb83b6fbb Record correct dominators in merge return (#2760)
c9190a54d SSA rewriter: Don't use trivial phis (#2757)
aea4e6b1b Fix block depth rule priority (#2755)
a94ddc267 Case validation with repeated labels (#2689)
3855447d9 Bindless Instrument: Make init check depend solely on input_init_enabled (#2753)
11516c0b9 Validate storage class OpenCL environment rules for atomics (#2750)
bac82f49a Allow LOD ops in compute shaders with derivative group execution modes (#2752)
76b75c40a Document opt::Instruction::InsertBefore methods (#2751)
aa9e8f538 Revert "Do not inline OpKill Instructions (#2713)" (#2749)
58e2ec25b For Vulkan, disallow structures containing opaque types (#2546)
230c9e437 Fix bug in merge return (#2734)
1fedf72e5 Allow ray tracing shaders in inst bindle check pass. (#2733)
032adc4d7 Correctly implement WebGPU related flag exclusions (#2737)
92c41ff1e Remove Common Uniform Elimination Pass (#2731)
59de04ad6 BUILD.gn: Add deps and move files for `gn check` (#2735)
55adf4cf7 Update execution scope rules for WebGPU (#2730)
1a2de48a1 Extra small storage validation (#2732)
327963765 Add validation for SPV_EXT_demote_to_helper_invocation (#2707)
508151250 BUILD.gn: Add targets to build all command-line tools (#2727)
5ce8cf781 Change the order branches are simplified in dead branch elim (#2728)
cd153db8e Add —preserve-bindings and —preserve-spec-constants (#2693)
86e45efe1 Handle decorations better in some optimizations (#2716)
3a252a267 Update memory scope rules for WebGPU (#2725)
0c4feb643 Remove extra semis (#2717)
456cc598a Validate usage of 8- and 16-bit types with only storage capabilities (#2704)
b8ab80843 Shrinker for spirv-fuzz (#2708)
37e8f7994 Perform merge return with single return in loop. (#2714)
fe7cc9c61 Do not inline OpKill Instructions (#2713)
5a93e0739 Refactor reducer options (#2709)
a6bfc26e5 Fix BUILD.gn for Fuchsia platform build. (#2692)
9702d47c6 Validate that in OpenGL env block variables have Binding (#2685)
e6e3e2ccc Update type for loaded builtin GlobalInvocationID in pass instrumentation (#2705)
6ccb52b86 Warn when input facts are invalid. (#2699)
88183041d Got rid of redundant declaration. (#2698)
efde68236 Disallow movement of unreachable blocks. (#2700)
dfcb5a1e1 Refactor fuzzer transformations (#2694)
888aeef8a Fix Component decoration validation for arrays (#2697)
df86bb44f Replace global static map with an array of pairs (#2691)
7c294608c Basic validation for Component decorations (#2679)
69b945992 Add infrastructure for maintaining and using DEPS (#2684)
2b84d25f1 Fix store to uniform Vulkan check (#2688)
bec7e0393 Add all accepted target environments to the tools' help texts (#2687)
51b0d5ce5 Represent uniform facts via descriptor set and binding. (#2681)
fa981bc24 Roll external/spirv-headers/ 8b911bd2b..de99d4d83 (8 commits) (#2682)
a132c9b64 Whitelist SPV_GOOGLE_user_type. (#2673)
001e823b6 Add fuzzer pass to obfuscate constants. (#2671)
2090d7a2d Handle volatile memory semantics in upgrade (#2674)
3d5fb7b90 Validate Volatile memory semantics bit (#2672)
400dbde0b Disallow stores to UBOs (#2651)
6cc2c8f4a Another fix uint -> uint32_t (#2676)
59983a601 Validate variable initializer type (#2668)
9477c91de Fix uint -> uint32_t in fuzz.cpp (#2675)
42830e5a6 Add replayer tool for spirv-fuzz. (#2664)
b4bf7bcf0 Add validation for Subgroup builtins (#2637)
9c0830133 Add constant == uniform facts. (#2660)
208d3132e Cast __LINE__ to size_t (#2661)
a8ae579f7 Add transformation to replace a boolean constant with a numeric comparison (#2659)
0755d6ce8 Add builtin validation for SPV_NV_shader_sm_builtins (#2656)
43fb2403a Instrument: Fix code for version 2 output format. (#2655)
08cc49ec5 Fix bug in 'split blocks', and add tests for fuzzer. (#2658)
d01a3c3b4 Optimizer: Handle array type with OpSpecConstantOp length (#2652)
4a00a80c4 Add fuzzer pass to add dead breaks. (#2654)
620197bd6 Add fuzzer pass that adds useful constructs to a module (#2647)
2c0111e6e Add validation for SPV_EXT_fragment_shader_interlock (#2650)
699e167d7 Remove asserts from GetUnderlyingType (#2646)
7919b877c Close opened file handles. (#2644)
f99d7ad5c Validate OpenCL rules for ImageRead and OpImageSampleExplicitLod (#2643)
209ff0ce9 Add spirv-fuzz pass to permute blocks. (#2642)
e7866de4b Linker: Better type comparison for OpTypeArray and OpTypeForwardPointer (#2580)
0125b28ed Add compact ids to WebGPU <-> Vulkan transformations (#2639)
3d62cb814 Instrument: Add version 2 of record formats (#2630)
1b71e4533 Add "split block" transformation. (#2633)
f05181234 Add WebGPU specific fuzzer for validation (#2628)
5a06fa466 Add fuzzer for Vulkan->WebGPU spirv-opt passes (#2626)
78b2b1866 Add fuzzer for WebGPU->Vulkan spirv-opt passes (#2625)
6c7db9c63 Handle nested breaks from switches. (#2624)
37ae8671a Add spirv-fuzz tool. (#2631)
fe9f87013 Add library for spirv-fuzz (#2618)
42abaa099 Remove MarkV and Stats code. (#2576)
3b5ab540c linker: Add tests for various type comparisons (#2613)
4c73ebc46 Enable the base branch to be overridden in the code format check script (#2607)
b8fe7211c Allow arrays of out per-primitive builtins for mesh shaders (#2617)
07a101971 Validate OpenCL environment rules for OpImageWrite (#2619)
b0504239a Added an external dependency on protobufs, included when SPIRV_BUILD_FUZZER is defined, so that they can be used by the (upcoming) spirv-fuzz tool. Also updated the kokoro build scripts, for relevant targets, to clone an appropriate tag of the protobufs repo, and to pass -DSPIRV_BUILD_FUZZER to the configurations for which we intend to ultimately build spirv-fuzz. (#2616)
4557d0858 Add in individual flags for Vulkan <-> WebGPU passes (#2615)
13f61bf85 Update vloadn and vstoren validation to match the OpenCL Extended Instruction Set Specification (#2599)
d9c00e1d2 Add folding rules for OpQuantizeToF16 (#2614)
713da30b6 Disallow merge targeting block with OpLoopMerge (#2610)
60aaafbc7 Allows breaks selection breaks to switches (#2605)
0982f0212 Using the instruction folder to fold OpSpecConstantOp (#2598)
9f035269d Validate OpenCL environment rules for OpTypeImage (#2606)
47741f050 Validate OpenCL memory and addressing model environment rules (#2589)
ff4feb44b Validate construct exits (#2459)
9dfd4b835 Bindless Validation: Instrument descriptor-based loads and stores (#2583)
7e7745fce Validate loop merge (#2579)
fc7b5d8c6 Mem model spv 1.4 (#2565)
84aa4946e Start SPIRV-Tools v2019.4
ce19e217b Finalize SPIRV-Tools v2019.3
84503583c Handle id overflow in sroa better. (#2582)
f815e6fe5 Update CHANGES
e935dac9e Make pointers to isomorphic type interchangeable with option. (#2570)
2947e88f7 Update instrumentation passes to handle 1.4 interfaces (#2573)
06ce59b0b Instrument: Fix load type of pre-existing builtin (#2575)
87c4ef8a9 Do not fold floating point if float controls used (#2569)
45fb69666 Use last version (#2578)
f6d9a1784 Add pass to fix some invalid unreachable blocks for WebGPU (#2563)
89fe836fe Fix clang-tidy warning about definition/declaration mismatch. (#2571)
f2803c4a7 VK_KHR_uniform_buffer_standard_layout validation (#2562)
cc3e93c4e Add tests for folding 1.4 selects (#2568)
ea5e1b62e Update priv-to-local for SPIR-V 1.4 (#2567)
d0a1f5a05 spvtest::Validate::CompileFailure: Don't leak the diagnostic (#2564)
b74d92a8c ADCE support for SPIR-V 1.4 entry points (#2561)
2b65a71d4 Fix use of 'is' operator for comparison (#2547)
63f57d95d Support SPIR-V 1.4 (#2550)
106c98d0f Validate sign of int types. (#2549)
eef11cdb7 Update README with links to build artifacts. (#2548)
5fc5303ee [spirv] Package and upload builds. (#2544)
6d04da22c Fix up type mismatches. (#2545)
c8b09744c Add validation specific to OpExecutionModeId (#2536)
a5da68d44 Remove stale comment (#2542)
32af42616 Change implementation of post order CFG traversal (#2543)
64faf6d9c Fix undefined bit shift in sroa. (#2532)
dca3ea5e1 fix example.cpp (#2540)
2de3e3c02 Add spirv-lesspipe.sh into SPIRV_SKIP_EXECUTABLES umbrella (https://github.com/KhronosGroup/SPIRV-Tools/issues/2497) (#2504)
fb08224f8 Fix spirv-headers link in the README. (#2516)
b68af7ca8 Add support for Private & Output to initializer decompose flag (#2537)
736376dbf Remove Acquire, Release, and Relaxed from allowed Mem Sem bits for WebGPU (#2526)
07c4dd4b9 Reduce runtime of array layout checks (#2534)
7aad9653f Remove legacy utility functions (#2530)
d754b7059 Shorten names of cmake targets (#2531)
ac878fcbd Remove unreachable block validation (#2525)
21712068f Validate that SPIR-V binary is encoded as little endian for WebGPU (#2523)
3aad3e922 Change validation of memory semantics for OpAtomics* in WebGPU (#2519)
048dcd38c Implement WebGPU->Vulkan initializer conversion for 'Function' variables (#2513)
3335c6114 reduce: Add two branch reduction passes (#2507)
102e430a8 Add pass to legalize OpVectorShuffle for WebGPU (#2509)
07ac7dee5 SPIRV-Tools requires python3 (#2510)
98b3f26c2 Gate formatless checks on Vulkan env (#2486)
2b46521cd Add -fsantize to link flags. (#2506)
82ebbbba1 README: fix formatting of requiring Python 'future' (#2500)
9047de51c Accept OpBitCast in fix storage class. (#2505)
d90aae9a5 reduce: miscellaneous fixes (#2494)
7ce37d66a Fix use of Logf to avoid format security warning (#2498)
0cb2d4079 Add WebGPU->Vulkan and Vulkan->WebGPU flags in spirv-opt (#2496)
9766b22b3 spirv-opt: Behave a bit better in the face of unknown instructions (#2487)
3a0bc9e72 Add fix storage class code. (#2434)
e8c2d95ed Fix webgpu header file name in BUILD.gn (#2493)
26c1b8878 Update CHANGES
236bdc006 Change prioritization of unreachable merge and continue (#2460)
12e4a7b64 Handle variable pointer in some optimizations (#2490)
01964e325 Add pass to generate needed initializers for WebGPU (#2481)
4bd106b08 Handle dead infinite loops in DCE (#2471)
8129cf2f9 Remove merge assert in block calculation (#2489)
e2ddb9371 reduce: add remove_selection_reduction_opportunity (#2485)
c9874e509 Fix merge return in the face of breaks (#2466)
0300a464a Maintain inst to block mapping in merge return (#2469)
320a7de5c Validate that OpUnreacahble is not statically reachable (#2473)
fcb845310 reduce: fix loop to selection pass for loops with combined header/continue block (#2480)
2ff54e34e Handle function decls in Structured CFG analysis (#2474)
42e6f1aa6 Add option to validate after each pass (#2462)
fb0753640 reduce: fix loop to selection dominance query (#2477)
7d1b176c1 Improve reducer algorithm and other changes (#2472)
ffbecae56 Check OpSampledImage is only passed into valid instructions (#2467)
2d52cbee4 Add some val options to reduce (#2401)
1f60f9896 reduce: remove unreferenced blocks pass (#2398)
08b54d9e4 Convert sampled consumers to being Instructions instead of IDs (#2464)
e1a76269b Bindless Validation: Descriptor Initialization Check (#2419)
9244e6ff6 Reverting commit da5a780ff9fff7e226ca84728075adabc4d1608c
da5a780ff Variable pointers cannot be an operand to OpArrayLength
2ac348b5c Repair test for unused storage buffer with descriptor (#2436)
e54552214 Add --strip-atomic-counter-memory (#2413)
bdcb15516 Relax function call parameter check (#2448)
5186ffedb Remove duplicates from list of interface IDs in OpEntryPoint instruction (#2449)
6df8a917a Add validation of storage classes for WebGPU (#2446)
a5c06c903 Validator: no Storage comparison for pointer param (#2428)
9d29c37ac Removing decorations when doing constant propagation. (#2444)
b75f4362f Add validation for ExecutionMode in WebGPU (#2443)
b1ff15f22 Add missing DepthGreater case to Fragment only check (#2440)
b12e7338e Implement WebGPU specific CFG validation (#2386)
a2ef7be24 Add Linux ASAN bot configs. (#2427)
07f80c4df Fix python scripts to work with python3 (#2426)
86f6ac086 Add a test for two back-edges in a continue (#2418)
5fb83a970 Allow NonWritable to target struct members. (#2420)
32b0f6739 Use correct option in spvTextToBinary. (#2416)
d800bbbac Handle back edges better in dead branch elim. (#2417)
002ef361c Add validation for SPV_NV_cooperative_matrix (#2404)
fc3897b5f Validate: (data) Block can't appear within a Block (#2410)
37b584a73 Fixed undefined reference to 'clock_gettime' by linking rt library (#2409)
a006cbc1d Non memory object as parameters. (#2415)
4c43afcad It is invalid to apply both Restrict and Aliased to the same <id> (#2408)
fde69dcd8 Fix OpDot folding of half float vectors. (#2411)
8eddde2e7 Don't change type of input and output var in dead member elim (#2412)
76730a46a In Vulkan, disallow BufferBlock on StorageBuffer variables (#2380)
5994ae2a0 Start SPIRV-Tools 2019.3
61dfd8492 Finalize SPIRV-Tools 2019.2
bf23ed887 OpAtomicLoad, OpAtomicStore, OpAtomicExchange can operate on int or float value. Except for Vulkan environment that only operates on int value. (#2385)
80496f42a Update CHANGES
2f84b5de9 Bindless: Fix computation of set and binding for runtime bounds check (#2384)
528fea2b1 Fixup unused variables (#2402)
4b42cd19d BUILD.gn: Only build tests in Chromium. (#2392)
6d20f6257 Refactor webgpu-mode pass ran tests to be parameterized (#2395)
78ac954c4 Mark type id of unknown instructions at fully used. (#2399)
9540f2d98 Instrumentation: Fix instruction index when multiple functions (#2389)
1b0047f21 Add pass to remove dead members. (#2379)
0167a20b0 Move usage detection to after all instructions are registered (#2378)
0187c190b Fix BUILD.gn (#2381)
354205b3d Don't merge unreachable blocks (#2375)
40a7940e0 Fix merge blocks opportunity to check if still enabled (#2370)
12b3d7e9d Add strip-debug to webgpu-mode passes (#2368)
a0ff7c512 Add better error message to ValidateInstructions (#2365)
34c5ac614 Fixes #2358. Added to the reducer the ability to remove a function t… (#2361)
10a7def6c Smoketest should use KhronosGroup glslang (#2363)
39bfb6b97 Make spvParseTargetEnv public (#2362)
cf2114613 Expand bindless bounds checking to runtime-sized descriptor arrays (#2316)
9b6ba4d1c Allow arrayed storage images for NonWritable decoration (#2358)
117a1fd11 Validate variable pointer related function call rules (#2270)
0f4bf0720 Add flatten-decorations flag to webgpu-mode flags (#2348)
368567bc5 Convert deprecated GoogleTest fixture to the new version (#2357)
adbbe2024 Mention the reducer tool and location in the README. (#2341)
e3c64a374 Do not build spirv-reduce on iOS/tvOS/watchOS - it requires std::system which is not available on those platforms (#2355)
37861ac10 Merge blocks in reducer (#2353)
453b7c85c Fix up some test (#2351)
846d12afe Add whitelist for decorations in WebGPU (#2346)
63e032f91 Remove unused lambda capture (#2350)
3b6fee3da Fixes #2338. Added functionality to remove OpPhi instructions (replacing their uses) when merging blocks (#2339)
2acbf488b Add WebGPU specific validation for WorkgroupSize BuiltIn decoration (#2334)
e2f462262 Add WebGPU specific validation for multiple BuiltIn decorations (#2333)
3d2afb78c Add whitelist of allowed BuiltIn decorations for WebGPU (#2337)
d17fcf8ab Add WebGPU validation for LocalInvocationIndex BuiltIn decoration (#2335)
837153ccd Add WebGPU specific validation for FragDepth BuiltIn decoration (#2332)
0c14583f1 Add WebGPU specific validation for FragCoord BuiltIn decoration (#2331)
b6698e0d8 Add WebGPU specific validation for FrontFacing BuiltIn decoration (#2330)
734def144 Add WebGPU specific validation for InstanceIndex BuiltIn decoration (#2329)
b947ecfe7 Add WebGPU specific validation for VertexIndex BuiltIn decoration (#2328)
464111eae Remove use of deprecated googletest macro (#2286)
7f1a020ab Fix test_val_limits MSVC build (#2347)
5d6b4c4b1 Move CodeGenerator to be accessible by other validation tests (#2343)
cf7834623 Add source/opt/block_merge_util.* to BUILD.gn (#2344)
7f3679a8b Validate NonWritable decoration (#2263)
9ab1c0ddd Remove code sinking for -O. (#2340)
98c67d385 Fixed names in ifdefs and GetName functions that had been forgotten in a previous refactoring. Also shortened names of test files as those files test both the new 'finder' classes introduced in the refactoring, as well as the 'reduction pass' class; the shorter names capture both. (#2336)
3345fe6a9 Extracted block merging functionality into its own utility file (#2325)
cf011f990 More layout check fixes (#2315)
e2279da71 Remove the static maps from CheckDecorationsCompatibility (#2327)
8915a7c8f spirv-val: Emit an error when an OpSwitch target is not an OpLabel (#2298)
1e3c589a6 Add WebGPU specific validation for Position BuiltIn decoration (#2309)
20b2e2b9f Add SpirvTools::IsValid(). (#2326)
86d0d9be2 Refactored reducer so that the 'finding' functionality of a reduction pass are separated from the generic functionality for tracking progress of a pass. With this change, we now have a ReductionOpportunityFinder abstract class, with many subclasses for each type of reduction, and just one ReductionPass class, which has an associated finder. (#2321)
b1be6763f Add helper for 'is Vulkan or WebGPU' (#2324)
3d7102424 Added some documentation about the reducer. (#2318)
4a405eda5 Fix layout checks for nested struct in relaxed layout; and descriptor arrays (#2312)
3a3ad2ec5 Add utility to generate a logging string for a given environment (#2314)
a64c651e1 Fix Constants Analyses bug inserted by #2302 (#2306)
eab06d669 Check forward reference in OpTypeArray. (#2307)
8df947d2d Handle instructions not in blocks in code sinking. (#2308)
git-subtree-dir: third_party/SPIRV-Tools
git-subtree-split: 9559cdbdf011c487f67f89e2d694bd4a18d5c1e0
diff --git a/source/opt/optimizer.cpp b/source/opt/optimizer.cpp
index 30e80d7..5c1e6ca 100644
--- a/source/opt/optimizer.cpp
+++ b/source/opt/optimizer.cpp
@@ -21,7 +21,6 @@
#include <vector>
#include <source/spirv_optimizer_options.h>
-#include "code_sink.h"
#include "source/opt/build_module.h"
#include "source/opt/log.h"
#include "source/opt/pass_manager.h"
@@ -57,8 +56,8 @@
struct Optimizer::Impl {
explicit Impl(spv_target_env env) : target_env(env), pass_manager() {}
- spv_target_env target_env; // Target environment.
- opt::PassManager pass_manager; // Internal implementation pass manager.
+ spv_target_env target_env; // Target environment.
+ opt::PassManager pass_manager; // Internal implementation pass manager.
};
Optimizer::Optimizer(spv_target_env env) : impl_(new Impl(env)) {}
@@ -116,6 +115,10 @@
// Make private variable function scope
.RegisterPass(CreateEliminateDeadFunctionsPass())
.RegisterPass(CreatePrivateToLocalPass())
+ // Fix up the storage classes that DXC may have purposely generated
+ // incorrectly. All functions are inlined, and a lot of dead code has
+ // been removed.
+ .RegisterPass(CreateFixStorageClassPass())
// Propagate the value stored to the loads in very simple cases.
.RegisterPass(CreateLocalSingleBlockLoadStoreElimPass())
.RegisterPass(CreateLocalSingleStoreElimPass())
@@ -182,10 +185,7 @@
.RegisterPass(CreateRedundancyEliminationPass())
.RegisterPass(CreateDeadBranchElimPass())
.RegisterPass(CreateBlockMergePass())
- .RegisterPass(CreateSimplificationPass())
- .RegisterPass(CreateCodeSinkingPass());
- // Currently exposing driver bugs resulting in crashes (#946)
- // .RegisterPass(CreateCommonUniformElimPass())
+ .RegisterPass(CreateSimplificationPass());
}
Optimizer& Optimizer::RegisterSizePasses() {
@@ -213,14 +213,25 @@
.RegisterPass(CreateDeadInsertElimPass())
.RegisterPass(CreateRedundancyEliminationPass())
.RegisterPass(CreateCFGCleanupPass())
- // Currently exposing driver bugs resulting in crashes (#946)
- // .RegisterPass(CreateCommonUniformElimPass())
.RegisterPass(CreateAggressiveDCEPass());
}
-Optimizer& Optimizer::RegisterWebGPUPasses() {
- return RegisterPass(CreateAggressiveDCEPass())
- .RegisterPass(CreateDeadBranchElimPass());
+Optimizer& Optimizer::RegisterVulkanToWebGPUPasses() {
+ return RegisterPass(CreateStripDebugInfoPass())
+ .RegisterPass(CreateStripAtomicCounterMemoryPass())
+ .RegisterPass(CreateGenerateWebGPUInitializersPass())
+ .RegisterPass(CreateLegalizeVectorShufflePass())
+ .RegisterPass(CreateSplitInvalidUnreachablePass())
+ .RegisterPass(CreateEliminateDeadConstantPass())
+ .RegisterPass(CreateFlattenDecorationPass())
+ .RegisterPass(CreateAggressiveDCEPass())
+ .RegisterPass(CreateDeadBranchElimPass())
+ .RegisterPass(CreateCompactIdsPass());
+}
+
+Optimizer& Optimizer::RegisterWebGPUToVulkanPasses() {
+ return RegisterPass(CreateDecomposeInitializedVariablesPass())
+ .RegisterPass(CreateCompactIdsPass());
}
bool Optimizer::RegisterPassesFromFlags(const std::vector<std::string>& flags) {
@@ -265,7 +276,9 @@
//
// Both Pass::name() and Pass::desc() should be static class members so they
// can be invoked without creating a pass instance.
- if (pass_name == "strip-debug") {
+ if (pass_name == "strip-atomic-counter-memory") {
+ RegisterPass(CreateStripAtomicCounterMemoryPass());
+ } else if (pass_name == "strip-debug") {
RegisterPass(CreateStripDebugInfoPass());
} else if (pass_name == "strip-reflect") {
RegisterPass(CreateStripReflectInfoPass());
@@ -323,14 +336,14 @@
RegisterPass(CreateEliminateDeadFunctionsPass());
} else if (pass_name == "eliminate-local-multi-store") {
RegisterPass(CreateLocalMultiStoreElimPass());
- } else if (pass_name == "eliminate-common-uniform") {
- RegisterPass(CreateCommonUniformElimPass());
} else if (pass_name == "eliminate-dead-const") {
RegisterPass(CreateEliminateDeadConstantPass());
} else if (pass_name == "eliminate-dead-inserts") {
RegisterPass(CreateDeadInsertElimPass());
} else if (pass_name == "eliminate-dead-variables") {
RegisterPass(CreateDeadVariableEliminationPass());
+ } else if (pass_name == "eliminate-dead-members") {
+ RegisterPass(CreateEliminateDeadMembersPass());
} else if (pass_name == "fold-spec-const-op-composite") {
RegisterPass(CreateFoldSpecConstantOpAndCompositePass());
} else if (pass_name == "loop-unswitch") {
@@ -380,7 +393,7 @@
} else if (pass_name == "replace-invalid-opcode") {
RegisterPass(CreateReplaceInvalidOpcodePass());
} else if (pass_name == "inst-bindless-check") {
- RegisterPass(CreateInstBindlessCheckPass(7, 23));
+ RegisterPass(CreateInstBindlessCheckPass(7, 23, true, true, 1));
RegisterPass(CreateSimplificationPass());
RegisterPass(CreateDeadBranchElimPass());
RegisterPass(CreateBlockMergePass());
@@ -443,12 +456,22 @@
RegisterPass(CreateCCPPass());
} else if (pass_name == "code-sink") {
RegisterPass(CreateCodeSinkingPass());
+ } else if (pass_name == "fix-storage-class") {
+ RegisterPass(CreateFixStorageClassPass());
} else if (pass_name == "O") {
RegisterPerformancePasses();
} else if (pass_name == "Os") {
RegisterSizePasses();
} else if (pass_name == "legalize-hlsl") {
RegisterLegalizationPasses();
+ } else if (pass_name == "generate-webgpu-initializers") {
+ RegisterPass(CreateGenerateWebGPUInitializersPass());
+ } else if (pass_name == "legalize-vector-shuffle") {
+ RegisterPass(CreateLegalizeVectorShufflePass());
+ } else if (pass_name == "split-invalid-unreachable") {
+ RegisterPass(CreateLegalizeVectorShufflePass());
+ } else if (pass_name == "decompose-initialized-variables") {
+ RegisterPass(CreateDecomposeInitializedVariablesPass());
} else {
Errorf(consumer(), nullptr, {},
"Unknown flag '--%s'. Use --help for a list of valid flags",
@@ -499,12 +522,28 @@
if (context == nullptr) return false;
context->set_max_id_bound(opt_options->max_id_bound_);
+ context->set_preserve_bindings(opt_options->preserve_bindings_);
+ context->set_preserve_spec_constants(opt_options->preserve_spec_constants_);
+ impl_->pass_manager.SetValidatorOptions(&opt_options->val_options_);
+ impl_->pass_manager.SetTargetEnv(impl_->target_env);
auto status = impl_->pass_manager.Run(context.get());
- if (status == opt::Pass::Status::SuccessWithChange ||
- (status == opt::Pass::Status::SuccessWithoutChange &&
- (optimized_binary->data() != original_binary ||
- optimized_binary->size() != original_binary_size))) {
+
+ bool binary_changed = false;
+ if (status == opt::Pass::Status::SuccessWithChange) {
+ binary_changed = true;
+ } else if (status == opt::Pass::Status::SuccessWithoutChange) {
+ if (optimized_binary->size() != original_binary_size ||
+ (memcmp(optimized_binary->data(), original_binary,
+ original_binary_size) != 0)) {
+ binary_changed = true;
+ Log(consumer(), SPV_MSG_WARNING, nullptr, {},
+ "Binary unexpectedly changed despite optimizer saying there was no "
+ "change");
+ }
+ }
+
+ if (binary_changed) {
optimized_binary->clear();
context->module()->ToBinary(optimized_binary, /* skip_nop = */ true);
}
@@ -522,10 +561,20 @@
return *this;
}
+Optimizer& Optimizer::SetValidateAfterAll(bool validate) {
+ impl_->pass_manager.SetValidateAfterAll(validate);
+ return *this;
+}
+
Optimizer::PassToken CreateNullPass() {
return MakeUnique<Optimizer::PassToken::Impl>(MakeUnique<opt::NullPass>());
}
+Optimizer::PassToken CreateStripAtomicCounterMemoryPass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::StripAtomicCounterMemoryPass>());
+}
+
Optimizer::PassToken CreateStripDebugInfoPass() {
return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::StripDebugInfoPass>());
@@ -541,6 +590,11 @@
MakeUnique<opt::EliminateDeadFunctionsPass>());
}
+Optimizer::PassToken CreateEliminateDeadMembersPass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::EliminateDeadMembersPass>());
+}
+
Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
const std::unordered_map<uint32_t, std::string>& id_value_map) {
return MakeUnique<Optimizer::PassToken::Impl>(
@@ -653,11 +707,6 @@
MakeUnique<opt::ProcessLinesPass>(opt::kLinesEliminateDeadLines));
}
-Optimizer::PassToken CreateCommonUniformElimPass() {
- return MakeUnique<Optimizer::PassToken::Impl>(
- MakeUnique<opt::CommonUniformElimPass>());
-}
-
Optimizer::PassToken CreateCompactIdsPass() {
return MakeUnique<Optimizer::PassToken::Impl>(
MakeUnique<opt::CompactIdsPass>());
@@ -789,9 +838,14 @@
}
Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t desc_set,
- uint32_t shader_id) {
+ uint32_t shader_id,
+ bool input_length_enable,
+ bool input_init_enable,
+ uint32_t version) {
return MakeUnique<Optimizer::PassToken::Impl>(
- MakeUnique<opt::InstBindlessCheckPass>(desc_set, shader_id));
+ MakeUnique<opt::InstBindlessCheckPass>(desc_set, shader_id,
+ input_length_enable,
+ input_init_enable, version));
}
Optimizer::PassToken CreateCodeSinkingPass() {
@@ -799,4 +853,29 @@
MakeUnique<opt::CodeSinkingPass>());
}
+Optimizer::PassToken CreateGenerateWebGPUInitializersPass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::GenerateWebGPUInitializersPass>());
+}
+
+Optimizer::PassToken CreateFixStorageClassPass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::FixStorageClass>());
+}
+
+Optimizer::PassToken CreateLegalizeVectorShufflePass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::LegalizeVectorShufflePass>());
+}
+
+Optimizer::PassToken CreateDecomposeInitializedVariablesPass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::DecomposeInitializedVariablesPass>());
+}
+
+Optimizer::PassToken CreateSplitInvalidUnreachablePass() {
+ return MakeUnique<Optimizer::PassToken::Impl>(
+ MakeUnique<opt::SplitInvalidUnreachablePass>());
+}
+
} // namespace spvtools