chromium/third_party/vulkan-validation-layers/src/layers/gpu/spirv/type_manager.h

/* Copyright (c) 2024 LunarG, 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.
 */
#pragma once

#include <vector>
#include "instruction.h"
#include "generated/spirv_grammar_helper.h"

namespace gpu {
namespace spirv {

class Module;
class TypeManager;

// These are the constant operations that we plan to handle in for shader instrumentation
static constexpr bool ConstantOperation(uint32_t opcode) {}

// There is a LOT that can be done with types, but for simplicity it only does what is needed.
// The main thing is to try find the type so we don't add a duplicate (but not end of the world if 1 or 2 are duplicated as a
// trade-off to doing complex logic to resolve more complex types). The class also takes advantage that while Instrumenting we are
// always aware of our types we are adding or just explictly found.
struct Type {};

// Represents a OpConstant*
// Will not be a OpSpecConstant* because we don't know if the value will change
struct Constant {};

// Represents a global OpVariable found before the first function
struct Variable {};

// In charge of tracking all Types, Constants, and Variable in the module.
// Since both Variable and Constant both rely on Types, the Types are the core thing we track
//
// Function naming guide:
//      Find*() - searches if type/constant/var is already there, will return null if not
//       Get*() - searches if type/constant/var is already there, will create one if not
//    Create*() - just makes the type/constant/var, doesn't attempt to search for a duplicate
class TypeManager {};

}  // namespace spirv
}  // namespace gpu