#include "source/opt/replace_desc_array_access_using_var_index.h"
#include "source/opt/desc_sroa_util.h"
#include "source/opt/ir_builder.h"
#include "source/util/string_utils.h"
namespace spvtools {
namespace opt {
namespace {
constexpr uint32_t kOpAccessChainInOperandIndexes = …;
constexpr uint32_t kOpTypePointerInOperandType = …;
constexpr uint32_t kOpTypeArrayInOperandType = …;
constexpr uint32_t kOpTypeStructInOperandMember = …;
IRContext::Analysis kAnalysisDefUseAndInstrToBlockMapping = …;
uint32_t GetValueWithKeyExistenceCheck(
uint32_t key, const std::unordered_map<uint32_t, uint32_t>& map) { … }
}
Pass::Status ReplaceDescArrayAccessUsingVarIndex::Process() { … }
bool ReplaceDescArrayAccessUsingVarIndex::
ReplaceVariableAccessesWithConstantElements(Instruction* var) const { … }
void ReplaceDescArrayAccessUsingVarIndex::ReplaceAccessChain(
Instruction* var, Instruction* access_chain) const { … }
void ReplaceDescArrayAccessUsingVarIndex::ReplaceUsersOfAccessChain(
Instruction* access_chain, uint32_t number_of_elements) const { … }
void ReplaceDescArrayAccessUsingVarIndex::CollectRecursiveUsersWithConcreteType(
Instruction* access_chain, std::vector<Instruction*>* final_users) const { … }
std::deque<Instruction*>
ReplaceDescArrayAccessUsingVarIndex::CollectRequiredImageAndAccessInsts(
Instruction* user) const { … }
bool ReplaceDescArrayAccessUsingVarIndex::HasImageOrImagePtrType(
const Instruction* inst) const { … }
bool ReplaceDescArrayAccessUsingVarIndex::IsImageOrImagePtrType(
const Instruction* type_inst) const { … }
bool ReplaceDescArrayAccessUsingVarIndex::IsConcreteType(
uint32_t type_id) const { … }
BasicBlock* ReplaceDescArrayAccessUsingVarIndex::CreateCaseBlock(
Instruction* access_chain, uint32_t element_index,
const std::deque<Instruction*>& insts_to_be_cloned,
uint32_t branch_target_id,
std::unordered_map<uint32_t, uint32_t>* old_ids_to_new_ids) const { … }
void ReplaceDescArrayAccessUsingVarIndex::CloneInstsToBlock(
BasicBlock* block, Instruction* inst_to_skip_cloning,
const std::deque<Instruction*>& insts_to_be_cloned,
std::unordered_map<uint32_t, uint32_t>* old_ids_to_new_ids) const { … }
void ReplaceDescArrayAccessUsingVarIndex::UseNewIdsInBlock(
BasicBlock* block,
const std::unordered_map<uint32_t, uint32_t>& old_ids_to_new_ids) const { … }
void ReplaceDescArrayAccessUsingVarIndex::ReplaceNonUniformAccessWithSwitchCase(
Instruction* access_chain_final_user, Instruction* access_chain,
uint32_t number_of_elements,
const std::deque<Instruction*>& insts_to_be_cloned) const { … }
BasicBlock*
ReplaceDescArrayAccessUsingVarIndex::SeparateInstructionsIntoNewBlock(
BasicBlock* block, Instruction* separation_begin_inst) const { … }
BasicBlock* ReplaceDescArrayAccessUsingVarIndex::CreateNewBlock() const { … }
void ReplaceDescArrayAccessUsingVarIndex::UseConstIndexForAccessChain(
Instruction* access_chain, uint32_t const_element_idx) const { … }
void ReplaceDescArrayAccessUsingVarIndex::AddConstElementAccessToCaseBlock(
BasicBlock* case_block, Instruction* access_chain,
uint32_t const_element_idx,
std::unordered_map<uint32_t, uint32_t>* old_ids_to_new_ids) const { … }
void ReplaceDescArrayAccessUsingVarIndex::AddBranchToBlock(
BasicBlock* parent_block, uint32_t branch_destination) const { … }
BasicBlock* ReplaceDescArrayAccessUsingVarIndex::CreateDefaultBlock(
bool null_const_for_phi_is_needed, std::vector<uint32_t>* phi_operands,
uint32_t merge_block_id) const { … }
Instruction* ReplaceDescArrayAccessUsingVarIndex::GetConstNull(
uint32_t type_id) const { … }
void ReplaceDescArrayAccessUsingVarIndex::AddSwitchForAccessChain(
BasicBlock* parent_block, uint32_t access_chain_index_var_id,
uint32_t default_id, uint32_t merge_id,
const std::vector<uint32_t>& case_block_ids) const { … }
uint32_t ReplaceDescArrayAccessUsingVarIndex::CreatePhiInstruction(
BasicBlock* parent_block, const std::vector<uint32_t>& phi_operands,
const std::vector<uint32_t>& case_block_ids,
uint32_t default_block_id) const { … }
void ReplaceDescArrayAccessUsingVarIndex::ReplacePhiIncomingBlock(
uint32_t old_incoming_block_id, uint32_t new_incoming_block_id) const { … }
}
}