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

Function ReassociateNestedGenericInt

source/opt/folding_rules.cpp:1650–1723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1648 spv::Op::OpBitwiseAnd};
1649
1650FoldingRule ReassociateNestedGenericInt(spv::Op opcode) {
1651 assert(std::find(std::begin(ReassociateNestedGenericIntOps),
1652 std::end(ReassociateNestedGenericIntOps),
1653 opcode) != std::end(ReassociateNestedGenericIntOps) &&
1654 "Wrong opcode.");
1655
1656 return [opcode](IRContext* context, Instruction* inst,
1657 const std::vector<const analysis::Constant*>& constants) {
1658 // Handled by other folding rules.
1659 if (constants[0] || constants[1]) {
1660 return false;
1661 }
1662
1663 if (inst->opcode() != opcode) {
1664 return false;
1665 }
1666
1667 const analysis::Type* type =
1668 context->get_type_mgr()->GetType(inst->type_id());
1669
1670 if (type->IsCooperativeMatrix()) {
1671 return false;
1672 }
1673
1674 uint32_t width = ElementWidth(type);
1675 if (width != 32 && width != 64) return false;
1676
1677 analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1678 Instruction* lhs = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1679 Instruction* rhs = def_use_mgr->GetDef(inst->GetSingleWordInOperand(1));
1680
1681 if (lhs->opcode() != opcode || rhs->opcode() != opcode) {
1682 return false;
1683 }
1684
1685 analysis::ConstantManager* const_mgr = context->get_constant_mgr();
1686 std::vector<const analysis::Constant*> lhs_constants =
1687 const_mgr->GetOperandConstants(lhs);
1688 const analysis::Constant* lhs_const = ConstInput(lhs_constants);
1689 if (!lhs_const) {
1690 return false;
1691 }
1692
1693 std::vector<const analysis::Constant*> rhs_constants =
1694 const_mgr->GetOperandConstants(rhs);
1695 const analysis::Constant* rhs_const = ConstInput(rhs_constants);
1696 if (!rhs_const) {
1697 return false;
1698 }
1699
1700 uint32_t merged_constant =
1701 PerformOperation(const_mgr, opcode, lhs_const, rhs_const);
1702 if (!merged_constant) {
1703 return false;
1704 }
1705
1706 InstructionBuilder ir_builder(
1707 context, inst,

Callers 1

AddFoldingRulesMethod · 0.85

Calls 15

findFunction · 0.85
ElementWidthFunction · 0.85
ConstInputFunction · 0.85
PerformOperationFunction · 0.85
NonConstInputFunction · 0.85
get_type_mgrMethod · 0.80
IsCooperativeMatrixMethod · 0.80
get_constant_mgrMethod · 0.80
GetOperandConstantsMethod · 0.80
AddBinaryOpMethod · 0.80
SetInOperandsMethod · 0.80

Tested by

no test coverage detected