MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / GetInsertedValues

Function GetInsertedValues

source/opt/folding_rules.cpp:2707–2733  ·  view source on GitHub ↗

Returns a map with the set of values that were inserted into an object by the chain of OpCompositeInsertInstruction starting with |inst|. The map will map the index to the value inserted at that index. An empty map will be returned if the map could not be properly generated.

Source from the content-addressed store, hash-verified

2705// The map will map the index to the value inserted at that index. An empty map
2706// will be returned if the map could not be properly generated.
2707std::map<uint32_t, uint32_t> GetInsertedValues(Instruction* inst) {
2708 analysis::DefUseManager* def_use_mgr = inst->context()->get_def_use_mgr();
2709 std::map<uint32_t, uint32_t> values_inserted;
2710 Instruction* current_inst = inst;
2711 while (current_inst->opcode() == spv::Op::OpCompositeInsert) {
2712 if (current_inst->NumInOperands() > inst->NumInOperands()) {
2713 // This is to catch the case
2714 // %2 = OpCompositeInsert %m2x2int %v2int_1_0 %m2x2int_undef 0
2715 // %3 = OpCompositeInsert %m2x2int %int_4 %2 0 0
2716 // %4 = OpCompositeInsert %m2x2int %v2int_2_3 %3 1
2717 // In this case we cannot do a single construct to get the matrix.
2718 uint32_t partially_inserted_element_index =
2719 current_inst->GetSingleWordInOperand(inst->NumInOperands() - 1);
2720 if (values_inserted.count(partially_inserted_element_index) == 0)
2721 return {};
2722 }
2723 if (HaveSameIndexesExceptForLast(inst, current_inst)) {
2724 values_inserted.insert(
2725 {current_inst->GetSingleWordInOperand(current_inst->NumInOperands() -
2726 1),
2727 current_inst->GetSingleWordInOperand(kInsertObjectIdInIdx)});
2728 }
2729 current_inst = def_use_mgr->GetDef(
2730 current_inst->GetSingleWordInOperand(kInsertCompositeIdInIdx));
2731 }
2732 return values_inserted;
2733}
2734
2735// Returns true of there is an entry in |values_inserted| for every element of
2736// |Type|.

Callers 1

Calls 9

NumInOperandsMethod · 0.80
get_def_use_mgrMethod · 0.45
contextMethod · 0.45
opcodeMethod · 0.45
countMethod · 0.45
insertMethod · 0.45
GetDefMethod · 0.45

Tested by

no test coverage detected