// Copyright (c) 2023 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef SOURCE_OPT_TRIM_CAPABILITIES_PASS_H_ #define SOURCE_OPT_TRIM_CAPABILITIES_PASS_H_ #include <algorithm> #include <array> #include <functional> #include <optional> #include <unordered_map> #include <unordered_set> #include "source/enum_set.h" #include "source/extensions.h" #include "source/opt/ir_context.h" #include "source/opt/module.h" #include "source/opt/pass.h" #include "source/spirv_target_env.h" namespace spvtools { namespace opt { // This is required for NDK build. The unordered_set/unordered_map // implementation don't work with class enums. struct ClassEnumHash { … }; // An opcode handler is a function which, given an instruction, returns either // the required capability, or nothing. // Each handler checks one case for a capability requirement. // // Example: // - `OpTypeImage` can have operand `A` operand which requires capability 1 // - `OpTypeImage` can also have operand `B` which requires capability 2. // -> We have 2 handlers: `Handler_OpTypeImage_1` and // `Handler_OpTypeImage_2`. OpcodeHandler; // This pass tried to remove superfluous capabilities declared in the module. // - If all the capabilities listed by an extension are removed, the extension // is also trimmed. // - If the module countains any capability listed in `kForbiddenCapabilities`, // the module is left untouched. // - No capabilities listed in `kUntouchableCapabilities` are trimmed, even when // not used. // - Only capabilitied listed in `kSupportedCapabilities` are supported. // - If the module contains unsupported capabilities, results might be // incorrect. class TrimCapabilitiesPass : public Pass { … }; } // namespace opt } // namespace spvtools #endif // SOURCE_OPT_TRIM_CAPABILITIES_H_