#include "source/opt/interface_var_sroa.h"
#include <iostream>
#include "source/opt/decoration_manager.h"
#include "source/opt/def_use_manager.h"
#include "source/opt/function.h"
#include "source/opt/log.h"
#include "source/opt/type_manager.h"
#include "source/util/make_unique.h"
namespace spvtools {
namespace opt {
namespace {
constexpr uint32_t kOpDecorateDecorationInOperandIndex = …;
constexpr uint32_t kOpDecorateLiteralInOperandIndex = …;
constexpr uint32_t kOpEntryPointInOperandInterface = …;
constexpr uint32_t kOpVariableStorageClassInOperandIndex = …;
constexpr uint32_t kOpTypeArrayElemTypeInOperandIndex = …;
constexpr uint32_t kOpTypeArrayLengthInOperandIndex = …;
constexpr uint32_t kOpTypeMatrixColCountInOperandIndex = …;
constexpr uint32_t kOpTypeMatrixColTypeInOperandIndex = …;
constexpr uint32_t kOpTypePtrTypeInOperandIndex = …;
constexpr uint32_t kOpConstantValueInOperandIndex = …;
uint32_t GetArrayLength(analysis::DefUseManager* def_use_mgr,
Instruction* array_type) { … }
Instruction* GetArrayElementType(analysis::DefUseManager* def_use_mgr,
Instruction* array_type) { … }
Instruction* GetMatrixColumnType(analysis::DefUseManager* def_use_mgr,
Instruction* matrix_type) { … }
uint32_t GetComponentTypeOfArrayMatrix(analysis::DefUseManager* def_use_mgr,
uint32_t type_id,
uint32_t depth_to_component) { … }
void CreateDecoration(analysis::DecorationManager* decoration_mgr,
uint32_t var_id, spv::Decoration decoration,
uint32_t literal) { … }
void ReplaceLoadWithCompositeConstruct(
IRContext* context,
const std::unordered_map<Instruction*, Instruction*>& loads_to_composites) { … }
spv::StorageClass GetStorageClass(Instruction* var) { … }
}
bool InterfaceVariableScalarReplacement::HasExtraArrayness(
Instruction& entry_point, Instruction* var) { … }
bool InterfaceVariableScalarReplacement::
CheckExtraArraynessConflictBetweenEntries(Instruction* interface_var,
bool has_extra_arrayness) { … }
bool InterfaceVariableScalarReplacement::GetVariableLocation(
Instruction* var, uint32_t* location) { … }
bool InterfaceVariableScalarReplacement::GetVariableComponent(
Instruction* var, uint32_t* component) { … }
std::vector<Instruction*>
InterfaceVariableScalarReplacement::CollectInterfaceVariables(
Instruction& entry_point) { … }
void InterfaceVariableScalarReplacement::KillInstructionAndUsers(
Instruction* inst) { … }
void InterfaceVariableScalarReplacement::KillInstructionsAndUsers(
const std::vector<Instruction*>& insts) { … }
void InterfaceVariableScalarReplacement::KillLocationAndComponentDecorations(
uint32_t var_id) { … }
bool InterfaceVariableScalarReplacement::ReplaceInterfaceVariableWithScalars(
Instruction* interface_var, Instruction* interface_var_type,
uint32_t location, uint32_t component, uint32_t extra_array_length) { … }
bool InterfaceVariableScalarReplacement::ReplaceInterfaceVarWith(
Instruction* interface_var, uint32_t extra_array_length,
const NestedCompositeComponents& scalar_interface_vars) { … }
void InterfaceVariableScalarReplacement::AddLocationAndComponentDecorations(
const NestedCompositeComponents& vars, uint32_t* location,
uint32_t component) { … }
bool InterfaceVariableScalarReplacement::ReplaceComponentsOfInterfaceVarWith(
Instruction* interface_var,
const std::vector<Instruction*>& interface_var_users,
const NestedCompositeComponents& scalar_interface_vars,
std::vector<uint32_t>& interface_var_component_indices,
const uint32_t* extra_array_index,
std::unordered_map<Instruction*, Instruction*>* loads_to_composites,
std::unordered_map<Instruction*, Instruction*>*
loads_for_access_chain_to_composites) { … }
bool InterfaceVariableScalarReplacement::
ReplaceMultipleComponentsOfInterfaceVarWith(
Instruction* interface_var,
const std::vector<Instruction*>& interface_var_users,
const std::vector<NestedCompositeComponents>& components,
std::vector<uint32_t>& interface_var_component_indices,
const uint32_t* extra_array_index,
std::unordered_map<Instruction*, Instruction*>* loads_to_composites,
std::unordered_map<Instruction*, Instruction*>*
loads_for_access_chain_to_composites) { … }
bool InterfaceVariableScalarReplacement::ReplaceComponentOfInterfaceVarWith(
Instruction* interface_var, Instruction* interface_var_user,
Instruction* scalar_var,
const std::vector<uint32_t>& interface_var_component_indices,
const uint32_t* extra_array_index,
std::unordered_map<Instruction*, Instruction*>* loads_to_component_values,
std::unordered_map<Instruction*, Instruction*>*
loads_for_access_chain_to_component_values) { … }
void InterfaceVariableScalarReplacement::UseBaseAccessChainForAccessChain(
Instruction* access_chain, Instruction* base_access_chain) { … }
Instruction* InterfaceVariableScalarReplacement::CreateAccessChainToVar(
uint32_t var_type_id, Instruction* var,
const std::vector<uint32_t>& index_ids, Instruction* insert_before,
uint32_t* component_type_id) { … }
Instruction* InterfaceVariableScalarReplacement::CreateAccessChainWithIndex(
uint32_t component_type_id, Instruction* var, uint32_t index,
Instruction* insert_before) { … }
void InterfaceVariableScalarReplacement::ReplaceAccessChainWith(
Instruction* access_chain,
const std::vector<uint32_t>& interface_var_component_indices,
Instruction* scalar_var,
std::unordered_map<Instruction*, Instruction*>* loads_to_component_values) { … }
void InterfaceVariableScalarReplacement::CloneAnnotationForVariable(
Instruction* annotation_inst, uint32_t var_id) { … }
bool InterfaceVariableScalarReplacement::ReplaceInterfaceVarInEntryPoint(
Instruction* interface_var, Instruction* entry_point,
uint32_t scalar_var_id) { … }
uint32_t InterfaceVariableScalarReplacement::GetPointeeTypeIdOfVar(
Instruction* var) { … }
void InterfaceVariableScalarReplacement::StoreComponentOfValueToScalarVar(
uint32_t value_id, const std::vector<uint32_t>& component_indices,
Instruction* scalar_var, const uint32_t* extra_array_index,
Instruction* insert_before) { … }
Instruction* InterfaceVariableScalarReplacement::LoadScalarVar(
Instruction* scalar_var, const uint32_t* extra_array_index,
Instruction* insert_before) { … }
Instruction* InterfaceVariableScalarReplacement::CreateLoad(
uint32_t type_id, Instruction* ptr, Instruction* insert_before) { … }
void InterfaceVariableScalarReplacement::StoreComponentOfValueTo(
uint32_t component_type_id, uint32_t value_id,
const std::vector<uint32_t>& component_indices, Instruction* ptr,
const uint32_t* extra_array_index, Instruction* insert_before) { … }
Instruction* InterfaceVariableScalarReplacement::CreateCompositeExtract(
uint32_t type_id, uint32_t composite_id,
const std::vector<uint32_t>& indexes, const uint32_t* extra_first_index) { … }
void InterfaceVariableScalarReplacement::
StoreComponentOfValueToAccessChainToScalarVar(
uint32_t value_id, const std::vector<uint32_t>& component_indices,
Instruction* scalar_var,
const std::vector<uint32_t>& access_chain_indices,
Instruction* insert_before) { … }
Instruction* InterfaceVariableScalarReplacement::LoadAccessChainToVar(
Instruction* var, const std::vector<uint32_t>& indexes,
Instruction* insert_before) { … }
Instruction*
InterfaceVariableScalarReplacement::CreateCompositeConstructForComponentOfLoad(
Instruction* load, uint32_t depth_to_component) { … }
void InterfaceVariableScalarReplacement::AddComponentsToCompositesForLoads(
const std::unordered_map<Instruction*, Instruction*>&
loads_to_component_values,
std::unordered_map<Instruction*, Instruction*>* loads_to_composites,
uint32_t depth_to_component) { … }
uint32_t InterfaceVariableScalarReplacement::GetArrayType(
uint32_t elem_type_id, uint32_t array_length) { … }
uint32_t InterfaceVariableScalarReplacement::GetPointerType(
uint32_t type_id, spv::StorageClass storage_class) { … }
InterfaceVariableScalarReplacement::NestedCompositeComponents
InterfaceVariableScalarReplacement::CreateScalarInterfaceVarsForArray(
Instruction* interface_var_type, spv::StorageClass storage_class,
uint32_t extra_array_length) { … }
InterfaceVariableScalarReplacement::NestedCompositeComponents
InterfaceVariableScalarReplacement::CreateScalarInterfaceVarsForMatrix(
Instruction* interface_var_type, spv::StorageClass storage_class,
uint32_t extra_array_length) { … }
InterfaceVariableScalarReplacement::NestedCompositeComponents
InterfaceVariableScalarReplacement::CreateScalarInterfaceVarsForReplacement(
Instruction* interface_var_type, spv::StorageClass storage_class,
uint32_t extra_array_length) { … }
Instruction* InterfaceVariableScalarReplacement::GetTypeOfVariable(
Instruction* var) { … }
Pass::Status InterfaceVariableScalarReplacement::Process() { … }
bool InterfaceVariableScalarReplacement::
ReportErrorIfHasExtraArraynessForOtherEntry(Instruction* var) { … }
bool InterfaceVariableScalarReplacement::
ReportErrorIfHasNoExtraArraynessForOtherEntry(Instruction* var) { … }
Pass::Status
InterfaceVariableScalarReplacement::ReplaceInterfaceVarsWithScalars(
Instruction& entry_point) { … }
}
}