@@ -69,45 +69,59 @@ canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
69
69
llvm::DenseSet<SILInstruction *> invariants;
70
70
int cost = 0 ;
71
71
for (auto &instRef : *bb) {
72
- OwnershipForwardingMixin *ofm = nullptr ;
73
72
auto *inst = &instRef;
74
- if (auto *MI = dyn_cast<MethodInst>(inst)) {
75
- if (MI->getMember ().isForeign )
76
- return false ;
77
- if (!hasLoopInvariantOperands (inst, loop, invariants))
78
- continue ;
79
- moves.push_back (inst);
80
- invariants.insert (inst);
81
- } else if (!inst->isTriviallyDuplicatable ())
73
+ if (!inst->isTriviallyDuplicatable ()) {
82
74
return false ;
75
+ }
83
76
// It wouldn't make sense to rotate dealloc_stack without also rotating the
84
77
// alloc_stack, which is covered by isTriviallyDuplicatable.
85
- else if (isa<DeallocStackInst>(inst))
78
+ if (isa<DeallocStackInst>(inst)) {
86
79
return false ;
87
- else if (isa<FunctionRefInst>(inst)) {
80
+ }
81
+ OwnershipForwardingMixin *ofm = nullptr ;
82
+ if ((ofm = OwnershipForwardingMixin::get (inst)) &&
83
+ ofm->getForwardingOwnershipKind () == OwnershipKind::Guaranteed) {
84
+ return false ;
85
+ }
86
+ if (isa<FunctionRefInst>(inst)) {
88
87
moves.push_back (inst);
89
88
invariants.insert (inst);
90
- } else if (isa<DynamicFunctionRefInst>(inst)) {
89
+ continue ;
90
+ }
91
+ if (isa<DynamicFunctionRefInst>(inst)) {
92
+ moves.push_back (inst);
93
+ invariants.insert (inst);
94
+ continue ;
95
+ }
96
+ if (isa<PreviousDynamicFunctionRefInst>(inst)) {
91
97
moves.push_back (inst);
92
98
invariants.insert (inst);
93
- } else if (isa<PreviousDynamicFunctionRefInst>(inst)) {
99
+ continue ;
100
+ }
101
+ if (isa<IntegerLiteralInst>(inst)) {
94
102
moves.push_back (inst);
95
103
invariants.insert (inst);
96
- } else if (isa<IntegerLiteralInst>(inst)) {
104
+ continue ;
105
+ }
106
+ if (auto *MI = dyn_cast<MethodInst>(inst)) {
107
+ if (MI->getMember ().isForeign )
108
+ return false ;
109
+ if (!hasLoopInvariantOperands (inst, loop, invariants))
110
+ continue ;
97
111
moves.push_back (inst);
98
112
invariants.insert (inst);
99
- } else if ((ofm = OwnershipForwardingMixin::get (inst)) &&
100
- ofm->getForwardingOwnershipKind () == OwnershipKind::Guaranteed) {
101
- return false ;
102
- } else if (!inst->mayHaveSideEffects () && !inst->mayReadFromMemory ()
103
- && !isa<TermInst>(inst) && !isa<AllocationInst>(inst)
104
- && /* not marked mayhavesideffects */
105
- hasLoopInvariantOperands (inst, loop, invariants)) {
113
+ continue ;
114
+ }
115
+ if (!inst->mayHaveSideEffects () && !inst->mayReadFromMemory () &&
116
+ !isa<TermInst>(inst) &&
117
+ !isa<AllocationInst>(inst) && /* not marked mayhavesideffects */
118
+ hasLoopInvariantOperands (inst, loop, invariants)) {
106
119
moves.push_back (inst);
107
120
invariants.insert (inst);
108
- } else {
109
- cost += (int )instructionInlineCost (instRef);
121
+ continue ;
110
122
}
123
+
124
+ cost += (int )instructionInlineCost (instRef);
111
125
}
112
126
113
127
return cost < LoopRotateSizeLimit;
@@ -425,6 +439,7 @@ bool swift::rotateLoop(SILLoop *loop, DominanceInfo *domInfo,
425
439
426
440
// The other instructions are just cloned to the preheader.
427
441
TermInst *preheaderBranch = preheader->getTerminator ();
442
+
428
443
for (auto &inst : *header) {
429
444
if (SILInstruction *cloned = inst.clone (preheaderBranch)) {
430
445
mapOperands (cloned, valueMap);
@@ -488,16 +503,10 @@ namespace {
488
503
class LoopRotation : public SILFunctionTransform {
489
504
490
505
void run () override {
506
+ SILFunction *f = getFunction ();
491
507
SILLoopAnalysis *loopAnalysis = PM->getAnalysis <SILLoopAnalysis>();
492
- assert (loopAnalysis);
493
508
DominanceAnalysis *domAnalysis = PM->getAnalysis <DominanceAnalysis>();
494
- assert (domAnalysis);
495
-
496
- SILFunction *f = getFunction ();
497
- assert (f);
498
-
499
509
SILLoopInfo *loopInfo = loopAnalysis->get (f);
500
- assert (loopInfo);
501
510
DominanceInfo *domInfo = domAnalysis->get (f);
502
511
503
512
if (loopInfo->empty ()) {
0 commit comments