From c5c1a25ab6d0e509e893d737a679ac47949df2f6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 18 Jan 2024 16:46:00 -0800 Subject: Capability def parsing & codegen + disjoint sets (#3451) * Capability def parsing & codegen + disjoint sets This change adds a capability definition file, and a code generator to produce C++ code that defines the capability enums and necessary data structures around the capabilities. Extends the existing CapabilitySet class to support expressing disjoint sets of capabilities. This sets up for the next change that will enhance our type checking with reasoning of capability requirements. * Fix cmake. * Fix warning. * Fix. * Fix isBetterForTarget to prefer less specialized option. * Fix. * Fix premake. * Fix intrinsic. * Fix vs sln file. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 58 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index f9a1276fe..1dbb21a0d 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -287,16 +287,36 @@ namespace Slang CapabilitySet IRCapabilitySet::getCaps() { - List atoms; - - Index count = (Index) getOperandCount(); - for(Index i = 0; i < count; ++i) + switch (getOp()) { - auto operand = cast(getOperand(i)); - atoms.add(CapabilityAtom(operand->getValue())); - } + case kIROp_CapabilityConjunction: + { + List atoms; + + Index count = (Index)getOperandCount(); + for (Index i = 0; i < count; ++i) + { + auto operand = cast(getOperand(i)); + atoms.add(CapabilityName(operand->getValue())); + } - return CapabilitySet(atoms.getCount(), atoms.getBuffer()); + return CapabilitySet(atoms.getCount(), atoms.getBuffer()); + } + break; + case kIROp_CapabilityDisjunction: + { + CapabilitySet result; + Index count = (Index) getOperandCount(); + for (Index i = 0; i < count; ++i) + { + auto operand = cast(getOperand(i)); + result.getExpandedAtoms().addRange(operand->getCaps().getExpandedAtoms()); + } + return result; + } + break; + } + return CapabilitySet(); } @@ -2396,17 +2416,21 @@ namespace Slang // be a minimal list of atoms such that they will produce // the same `CapabilitySet` when expanded. - List compactedAtoms; + List> compactedAtoms; caps.calcCompactedAtoms(compactedAtoms); - - List args; - for( auto atom : compactedAtoms ) + List conjunctions; + for( auto atomConjunction : compactedAtoms ) { - args.add(getIntValue(capabilityAtomType, Int(atom))); + List args; + for (auto atom : atomConjunction) + args.add(getIntValue(capabilityAtomType, Int(atom))); + auto conjunctionInst = createIntrinsicInst( + capabilitySetType, kIROp_CapabilityConjunction, args.getCount(), args.getBuffer()); + conjunctions.add(conjunctionInst); } - - return createIntrinsicInst( - capabilitySetType, kIROp_CapabilitySet, args.getCount(), args.getBuffer()); + if (conjunctions.getCount() == 1) + return conjunctions[0]; + return createIntrinsicInst(capabilitySetType, kIROp_CapabilityDisjunction, conjunctions.getCount(), conjunctions.getBuffer()); } static void canonicalizeInstOperands(IRBuilder& builder, IROp op, ArrayView operands) @@ -8004,7 +8028,7 @@ namespace Slang IRTargetSpecificDecoration* findBestTargetDecoration( IRInst* val, - CapabilityAtom targetCapabilityAtom) + CapabilityName targetCapabilityAtom) { return findBestTargetDecoration(val, CapabilitySet(targetCapabilityAtom)); } -- cgit v1.2.3