#include "source/opt/trim_capabilities_pass.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <optional>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "source/enum_set.h"
#include "source/enum_string_mapping.h"
#include "source/opt/ir_context.h"
#include "source/opt/reflect.h"
#include "source/spirv_target_env.h"
#include "source/util/string_utils.h"
namespace spvtools {
namespace opt {
namespace {
constexpr uint32_t kOpTypeFloatSizeIndex = …;
constexpr uint32_t kOpTypePointerStorageClassIndex = …;
constexpr uint32_t kTypeArrayTypeIndex = …;
constexpr uint32_t kOpTypeScalarBitWidthIndex = …;
constexpr uint32_t kTypePointerTypeIdInIndex = …;
constexpr uint32_t kOpTypeIntSizeIndex = …;
constexpr uint32_t kOpTypeImageDimIndex = …;
constexpr uint32_t kOpTypeImageArrayedIndex = …;
constexpr uint32_t kOpTypeImageMSIndex = …;
constexpr uint32_t kOpTypeImageSampledIndex = …;
constexpr uint32_t kOpTypeImageFormatIndex = …;
constexpr uint32_t kOpImageReadImageIndex = …;
constexpr uint32_t kOpImageSparseReadImageIndex = …;
template <class UnaryPredicate>
static void DFSWhile(const Instruction* instruction, UnaryPredicate condition) { … }
template <class UnaryPredicate>
static bool AnyTypeOf(const Instruction* instruction,
UnaryPredicate predicate) { … }
static bool is16bitType(const Instruction* instruction) { … }
static bool Has16BitCapability(const FeatureManager* feature_manager) { … }
}
static std::optional<spv::Capability> Handler_OpTypeFloat_Float16(
const Instruction* instruction) { … }
static std::optional<spv::Capability> Handler_OpTypeFloat_Float64(
const Instruction* instruction) { … }
static std::optional<spv::Capability>
Handler_OpTypePointer_StorageInputOutput16(const Instruction* instruction) { … }
static std::optional<spv::Capability>
Handler_OpTypePointer_StoragePushConstant16(const Instruction* instruction) { … }
static std::optional<spv::Capability>
Handler_OpTypePointer_StorageUniformBufferBlock16(
const Instruction* instruction) { … }
static std::optional<spv::Capability> Handler_OpTypePointer_StorageUniform16(
const Instruction* instruction) { … }
static std::optional<spv::Capability> Handler_OpTypeInt_Int16(
const Instruction* instruction) { … }
static std::optional<spv::Capability> Handler_OpTypeInt_Int64(
const Instruction* instruction) { … }
static std::optional<spv::Capability> Handler_OpTypeImage_ImageMSArray(
const Instruction* instruction) { … }
static std::optional<spv::Capability>
Handler_OpImageRead_StorageImageReadWithoutFormat(
const Instruction* instruction) { … }
static std::optional<spv::Capability>
Handler_OpImageSparseRead_StorageImageReadWithoutFormat(
const Instruction* instruction) { … }
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 12> kOpcodeHandlers{ … };
namespace {
ExtensionSet getExtensionsRelatedTo(const CapabilitySet& capabilities,
const AssemblyGrammar& grammar) { … }
bool hasOpcodeConflictingCapabilities(spv::Op opcode) { … }
}
TrimCapabilitiesPass::TrimCapabilitiesPass()
: … { … }
void TrimCapabilitiesPass::addInstructionRequirementsForOpcode(
spv::Op opcode, CapabilitySet* capabilities,
ExtensionSet* extensions) const { … }
void TrimCapabilitiesPass::addInstructionRequirementsForOperand(
const Operand& operand, CapabilitySet* capabilities,
ExtensionSet* extensions) const { … }
void TrimCapabilitiesPass::addInstructionRequirements(
Instruction* instruction, CapabilitySet* capabilities,
ExtensionSet* extensions) const { … }
void TrimCapabilitiesPass::AddExtensionsForOperand(
const spv_operand_type_t type, const uint32_t value,
ExtensionSet* extensions) const { … }
std::pair<CapabilitySet, ExtensionSet>
TrimCapabilitiesPass::DetermineRequiredCapabilitiesAndExtensions() const { … }
Pass::Status TrimCapabilitiesPass::TrimUnrequiredCapabilities(
const CapabilitySet& required_capabilities) const { … }
Pass::Status TrimCapabilitiesPass::TrimUnrequiredExtensions(
const ExtensionSet& required_extensions) const { … }
bool TrimCapabilitiesPass::HasForbiddenCapabilities() const { … }
Pass::Status TrimCapabilitiesPass::Process() { … }
}
}