Minor re-factoring: Move the logic to decide if a given instruction can be (easily) duplicated into SILInstruction. So far it was mainly used by jump-threading related optimizations. But it could be generally useful, or at least generally important, to optimizations that want to duplicate code.

Swift SVN r23213
This commit is contained in:
Roman Levenstein
2014-11-10 23:15:07 +00:00
parent 5e9e68c568
commit 3910c25da1
4 changed files with 35 additions and 41 deletions

View File

@@ -668,6 +668,23 @@ SILInstruction *SILInstruction::clone(SILInstruction *InsertPt) {
return NewInst;
}
/// Returns true if the instruction can be duplicated without any special
/// additional handling. It is important to know this information when
/// you perform such optimizations like e.g. jump-threading.
bool SILInstruction::isTriviallyDuplicatable() const {
if (isa<AllocStackInst>(this) || isa<DeallocStackInst>(this)) {
return false;
} else if (isa<OpenExistentialInst>(this) ||
isa<OpenExistentialRefInst>(this) ||
isa<OpenExistentialMetatypeInst>(this)) {
// Don't know how to duplicate these properly yet. Inst.clone() per
// instruction does not work. Because the follow-up instructions need to
// reuse the same archetype uuid which would only work if we used a
// cloner.
return false;
}
return true;
}
//===----------------------------------------------------------------------===//
// SILInstruction Subclasses