| 1961 | } |
| 1962 | |
| 1963 | bool 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)) { |
no test coverage detected