diff options
| author | Yong He <yonghe@outlook.com> | 2024-01-18 16:46:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-18 16:46:00 -0800 |
| commit | c5c1a25ab6d0e509e893d737a679ac47949df2f6 (patch) | |
| tree | e60d4f96ae5105ef19c6b238a4d98467ff58975d /source/slang/slang-ir.cpp | |
| parent | 1a13842f7ece9f3c492a7017509b75eafa903bbf (diff) | |
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 58 |
1 files changed, 41 insertions, 17 deletions
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<CapabilityAtom> atoms; - - Index count = (Index) getOperandCount(); - for(Index i = 0; i < count; ++i) + switch (getOp()) { - auto operand = cast<IRIntLit>(getOperand(i)); - atoms.add(CapabilityAtom(operand->getValue())); - } + case kIROp_CapabilityConjunction: + { + List<CapabilityName> atoms; + + Index count = (Index)getOperandCount(); + for (Index i = 0; i < count; ++i) + { + auto operand = cast<IRIntLit>(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<IRCapabilitySet>(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<CapabilityAtom> compactedAtoms; + List<List<CapabilityAtom>> compactedAtoms; caps.calcCompactedAtoms(compactedAtoms); - - List<IRInst*> args; - for( auto atom : compactedAtoms ) + List<IRInst*> conjunctions; + for( auto atomConjunction : compactedAtoms ) { - args.add(getIntValue(capabilityAtomType, Int(atom))); + List<IRInst*> 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<IRInst*> operands) @@ -8004,7 +8028,7 @@ namespace Slang IRTargetSpecificDecoration* findBestTargetDecoration( IRInst* val, - CapabilityAtom targetCapabilityAtom) + CapabilityName targetCapabilityAtom) { return findBestTargetDecoration(val, CapabilitySet(targetCapabilityAtom)); } |
