diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h index 5000e289f12..0a4e4e770e9 100644 --- a/include/swift/SIL/SILInstruction.h +++ b/include/swift/SIL/SILInstruction.h @@ -178,6 +178,10 @@ public: /// Return the array of opened archetypes operands for this instruction. MutableArrayRef getOpenedArchetypeOperands(); + /// Returns true if a given kind of instruciton may have opened archetype + /// operands. + bool mayHaveOpenedArchetypeOperands() const; + unsigned getNumOperands() const { return getAllOperands().size(); } unsigned getNumOpenedArchetypeOperands() const { diff --git a/lib/SIL/SILInstruction.cpp b/lib/SIL/SILInstruction.cpp index 71f416afdea..6d646070b4f 100644 --- a/lib/SIL/SILInstruction.cpp +++ b/lib/SIL/SILInstruction.cpp @@ -704,6 +704,23 @@ namespace { return {}; \ return I->getOpenedArchetypeOperands(); \ } +#include "swift/SIL/SILNodes.def" + }; + + class MayHaveOpenedArchetypeOperandsAccessor + : public SILVisitor { + public: +#define VALUE(CLASS, PARENT) \ + bool visit##CLASS(const CLASS *I) { \ + llvm_unreachable("accessing non-instruction " #CLASS); \ + } +#define INST(CLASS, PARENT, MEMBEHAVIOR, RELEASINGBEHAVIOR) \ + bool visit##CLASS(const CLASS *I) { \ + return IMPLEMENTS_METHOD(CLASS, SILInstruction, \ + getOpenedArchetypeOperands, \ + ArrayRef() const); \ + } #include "swift/SIL/SILNodes.def" }; } // end anonymous namespace @@ -725,6 +742,11 @@ MutableArrayRef SILInstruction::getOpenedArchetypeOperands() { return OpenedArchetypeOperandsMutableAccessor().visit(this); } +bool SILInstruction::mayHaveOpenedArchetypeOperands() const { + return MayHaveOpenedArchetypeOperandsAccessor().visit( + const_cast(this)); +} + /// getOperandNumber - Return which operand this is in the operand list of the /// using instruction. unsigned Operand::getOperandNumber() const {