Skip to content

Commit ae8b2ba

Browse files
committed
Add a helper method mayHaveOpenedArchetypeOperands to SILInstruction
This method returns true if a given kind of instructions may have opened archetype operands. It does not mean that a concrete instruction instance necessarily has such operands.
1 parent a7ee8ba commit ae8b2ba

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class SILInstruction : public ValueBase,public llvm::ilist_node<SILInstruction>{
178178
/// Return the array of opened archetypes operands for this instruction.
179179
MutableArrayRef<Operand> getOpenedArchetypeOperands();
180180

181+
/// Returns true if a given kind of instruciton may have opened archetype
182+
/// operands.
183+
bool mayHaveOpenedArchetypeOperands() const;
184+
181185
unsigned getNumOperands() const { return getAllOperands().size(); }
182186

183187
unsigned getNumOpenedArchetypeOperands() const {

lib/SIL/SILInstruction.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,23 @@ namespace {
704704
return {}; \
705705
return I->getOpenedArchetypeOperands(); \
706706
}
707+
#include "swift/SIL/SILNodes.def"
708+
};
709+
710+
class MayHaveOpenedArchetypeOperandsAccessor
711+
: public SILVisitor<MayHaveOpenedArchetypeOperandsAccessor,
712+
bool> {
713+
public:
714+
#define VALUE(CLASS, PARENT) \
715+
bool visit##CLASS(const CLASS *I) { \
716+
llvm_unreachable("accessing non-instruction " #CLASS); \
717+
}
718+
#define INST(CLASS, PARENT, MEMBEHAVIOR, RELEASINGBEHAVIOR) \
719+
bool visit##CLASS(const CLASS *I) { \
720+
return IMPLEMENTS_METHOD(CLASS, SILInstruction, \
721+
getOpenedArchetypeOperands, \
722+
ArrayRef<Operand>() const); \
723+
}
707724
#include "swift/SIL/SILNodes.def"
708725
};
709726
} // end anonymous namespace
@@ -725,6 +742,11 @@ MutableArrayRef<Operand> SILInstruction::getOpenedArchetypeOperands() {
725742
return OpenedArchetypeOperandsMutableAccessor().visit(this);
726743
}
727744

745+
bool SILInstruction::mayHaveOpenedArchetypeOperands() const {
746+
return MayHaveOpenedArchetypeOperandsAccessor().visit(
747+
const_cast<SILInstruction *>(this));
748+
}
749+
728750
/// getOperandNumber - Return which operand this is in the operand list of the
729751
/// using instruction.
730752
unsigned Operand::getOperandNumber() const {

0 commit comments

Comments
 (0)