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

Function HaveSameIndexesExceptForLast

source/opt/folding_rules.cpp:2368–2389  ·  view source on GitHub ↗

Returns true of |inst_1| and |inst_2| have the same indexes that will be used to index into a composite object, excluding the last index. The two instructions must have the same opcode, and be either OpCompositeExtract or OpCompositeInsert instructions.

Source from the content-addressed store, hash-verified

2366// instructions must have the same opcode, and be either OpCompositeExtract or
2367// OpCompositeInsert instructions.
2368bool HaveSameIndexesExceptForLast(Instruction* inst_1, Instruction* inst_2) {
2369 assert(inst_1->opcode() == inst_2->opcode() &&
2370 "Expecting the opcodes to be the same.");
2371 assert((inst_1->opcode() == spv::Op::OpCompositeInsert ||
2372 inst_1->opcode() == spv::Op::OpCompositeExtract) &&
2373 "Instructions must be OpCompositeInsert or OpCompositeExtract.");
2374
2375 if (inst_1->NumInOperands() != inst_2->NumInOperands()) {
2376 return false;
2377 }
2378
2379 uint32_t first_index_position =
2380 (inst_1->opcode() == spv::Op::OpCompositeInsert ? 2 : 1);
2381 for (uint32_t i = first_index_position; i < inst_1->NumInOperands() - 1;
2382 i++) {
2383 if (inst_1->GetSingleWordInOperand(i) !=
2384 inst_2->GetSingleWordInOperand(i)) {
2385 return false;
2386 }
2387 }
2388 return true;
2389}
2390
2391// If the OpCompositeConstruct is simply putting back together elements that
2392// where extracted from the same source, we can simply reuse the source.

Callers 2

GetInsertedValuesFunction · 0.85

Calls 3

NumInOperandsMethod · 0.80
opcodeMethod · 0.45

Tested by

no test coverage detected