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

Method GetNullCompositeConstant

source/opt/constants.cpp:404–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404const Constant* ConstantManager::GetNullCompositeConstant(const Type* type) {
405 std::vector<uint32_t> literal_words_or_id;
406
407 if (type->AsVector()) {
408 const Type* element_type = type->AsVector()->element_type();
409 const uint32_t null_id = GetNullConstId(element_type);
410 const uint32_t element_count = type->AsVector()->element_count();
411 for (uint32_t i = 0; i < element_count; i++) {
412 literal_words_or_id.push_back(null_id);
413 }
414 } else if (type->AsMatrix()) {
415 const Type* element_type = type->AsMatrix()->element_type();
416 const uint32_t null_id = GetNullConstId(element_type);
417 const uint32_t element_count = type->AsMatrix()->element_count();
418 for (uint32_t i = 0; i < element_count; i++) {
419 literal_words_or_id.push_back(null_id);
420 }
421 } else if (type->AsStruct()) {
422 // TODO (sfricke-lunarg) add proper struct support
423 return nullptr;
424 } else if (type->AsArray()) {
425 const Type* element_type = type->AsArray()->element_type();
426 const uint32_t null_id = GetNullConstId(element_type);
427 assert(type->AsArray()->length_info().words[0] ==
428 analysis::Array::LengthInfo::kConstant &&
429 "unexpected array length");
430 const uint32_t element_count = type->AsArray()->length_info().words[0];
431 for (uint32_t i = 0; i < element_count; i++) {
432 literal_words_or_id.push_back(null_id);
433 }
434 } else {
435 return nullptr;
436 }
437
438 return GetConstant(type, literal_words_or_id);
439}
440
441const Constant* ConstantManager::GetNumericVectorConstantWithWords(
442 const Vector* type, const std::vector<uint32_t>& literal_words) {

Callers 3

FoldInsertWithConstantsFunction · 0.80
TransposeMatrixFunction · 0.80
TEST_PFunction · 0.80

Calls 7

AsVectorMethod · 0.80
AsMatrixMethod · 0.80
AsStructMethod · 0.80
AsArrayMethod · 0.80
element_typeMethod · 0.45
element_countMethod · 0.45
push_backMethod · 0.45

Tested by 1

TEST_PFunction · 0.64