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

Method LogicallyMatch

source/val/validation_state.cpp:1963–2033  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1961}
1962
1963bool ValidationState_t::LogicallyMatch(const Instruction* lhs,
1964 const Instruction* rhs,
1965 bool check_decorations) {
1966 if (lhs->opcode() != rhs->opcode()) {
1967 return false;
1968 }
1969
1970 if (check_decorations) {
1971 const auto& dec_a = id_decorations(lhs->id());
1972 const auto& dec_b = id_decorations(rhs->id());
1973
1974 for (const auto& dec : dec_b) {
1975 if (std::find(dec_a.begin(), dec_a.end(), dec) == dec_a.end()) {
1976 return false;
1977 }
1978 }
1979 }
1980
1981 if (lhs->opcode() == spv::Op::OpTypeArray) {
1982 // Size operands must match.
1983 if (lhs->GetOperandAs<uint32_t>(2u) != rhs->GetOperandAs<uint32_t>(2u)) {
1984 return false;
1985 }
1986
1987 // Elements must match or logically match.
1988 const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(1u);
1989 const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(1u);
1990 if (lhs_ele_id == rhs_ele_id) {
1991 return true;
1992 }
1993
1994 const auto lhs_ele = FindDef(lhs_ele_id);
1995 const auto rhs_ele = FindDef(rhs_ele_id);
1996 if (!lhs_ele || !rhs_ele) {
1997 return false;
1998 }
1999 return LogicallyMatch(lhs_ele, rhs_ele, check_decorations);
2000 } else if (lhs->opcode() == spv::Op::OpTypeStruct) {
2001 // Number of elements must match.
2002 if (lhs->operands().size() != rhs->operands().size()) {
2003 return false;
2004 }
2005
2006 for (size_t i = 1u; i < lhs->operands().size(); ++i) {
2007 const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(i);
2008 const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(i);
2009 // Elements must match or logically match.
2010 if (lhs_ele_id == rhs_ele_id) {
2011 continue;
2012 }
2013
2014 const auto lhs_ele = FindDef(lhs_ele_id);
2015 const auto rhs_ele = FindDef(rhs_ele_id);
2016 if (!lhs_ele || !rhs_ele) {
2017 return false;
2018 }
2019
2020 if (!LogicallyMatch(lhs_ele, rhs_ele, check_decorations)) {

Callers 3

ValidateAbortFunction · 0.80
DoPointeesLogicallyMatchFunction · 0.80
ValidateCopyLogicalFunction · 0.80

Calls 7

findFunction · 0.85
operandsMethod · 0.80
opcodeMethod · 0.45
idMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected