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

Function CheckForExpectedVectorConstant

test/opt/fold_test.cpp:161–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159
160template <class ElementType, class Function>
161void CheckForExpectedVectorConstant(Instruction* inst,
162 std::vector<ElementType> expected_result,
163 Function GetValue) {
164 ASSERT_TRUE(inst);
165
166 IRContext* context = inst->context();
167 EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
168 analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
169 inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
170 std::vector<spv::Op> opcodes = {spv::Op::OpConstantComposite};
171 EXPECT_THAT(opcodes, Contains(inst->opcode()));
172 analysis::ConstantManager* const_mrg = context->get_constant_mgr();
173 const analysis::Constant* result = const_mrg->GetConstantFromInst(inst);
174 EXPECT_NE(result, nullptr);
175 if (result != nullptr) {
176 const std::vector<const analysis::Constant*>& componenets =
177 result->AsVectorConstant()->GetComponents();
178 EXPECT_EQ(componenets.size(), expected_result.size());
179 for (size_t i = 0; i < componenets.size(); i++) {
180 EXPECT_EQ(expected_result[i], GetValue(componenets[i]));
181 }
182 }
183}
184
185using IntegerInstructionFoldingTest =
186 ::testing::TestWithParam<InstructionFoldingCase<uint32_t>>;

Callers 1

TEST_PFunction · 0.85

Calls 9

get_constant_mgrMethod · 0.80
GetConstantFromInstMethod · 0.80
contextMethod · 0.45
opcodeMethod · 0.45
get_def_use_mgrMethod · 0.45
GetDefMethod · 0.45
AsVectorConstantMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected