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

@@ -83,12 +83,12 @@ canDuplicateOrMoveToPreheader(SILLoop *L, SILBasicBlock *Preheader,
SmallVectorImpl<SILInstruction *> &Move) {
llvm::DenseSet<SILInstruction *> Invariant;
for (auto &I : *Blk) {
if (!I.isTriviallyDuplicatable())
return false;
auto *Inst = &I;
if (isa<FunctionRefInst>(Inst)) {
Move.push_back(Inst);
Invariant.insert(Inst);
} else if (isa<AllocStackInst>(Inst) || isa<DeallocStackInst>(Inst)) {
return false;
} else if (isa<IntegerLiteralInst>(Inst)) {
Move.push_back(Inst);
Invariant.insert(Inst);
@@ -97,14 +97,6 @@ canDuplicateOrMoveToPreheader(SILLoop *L, SILBasicBlock *Preheader,
continue;
Move.push_back(Inst);
Invariant.insert(Inst);
} else if (isa<OpenExistentialInst>(Inst) ||
isa<OpenExistentialRefInst>(Inst) ||
isa<OpenExistentialMetatypeInst>(Inst)) {
// Don't know how to clone 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;
} else if (!Inst->mayHaveSideEffects() &&
!Inst->mayReadFromMemory() &&
!isa<TermInst>(Inst) &&