mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
LoopRotate: limit the size of the block to be duplicated.
This avoids significant code size regressions if the loop block to be duplicated is very large. Also remove the ShouldRotate option. It's not needed anymore as disabling the pass can be done by -sil-disable-pass. rdar://problem/33970453
This commit is contained in:
@@ -25,14 +25,20 @@
|
||||
#include "swift/SILOptimizer/Utils/CFGOptUtils.h"
|
||||
#include "swift/SILOptimizer/Utils/LoopUtils.h"
|
||||
#include "swift/SILOptimizer/Utils/SILSSAUpdater.h"
|
||||
#include "swift/SILOptimizer/Utils/SILInliner.h"
|
||||
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
static llvm::cl::opt<bool> ShouldRotate("sil-looprotate",
|
||||
llvm::cl::init(true));
|
||||
/// The size limit for the loop block to duplicate.
|
||||
///
|
||||
/// Larger blocks will not be duplicated to avoid too much code size increase.
|
||||
/// It's very seldom that the default value of 20 is exceeded (< 0.3% of all
|
||||
/// loops in the swift benchmarks).
|
||||
static llvm::cl::opt<int> LoopRotateSizeLimit("looprotate-size-limit",
|
||||
llvm::cl::init(20));
|
||||
|
||||
/// Check whether all operands are loop invariant.
|
||||
static bool
|
||||
@@ -59,6 +65,7 @@ canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
|
||||
SILBasicBlock *bb,
|
||||
SmallVectorImpl<SILInstruction *> &moves) {
|
||||
llvm::DenseSet<SILInstruction *> invariants;
|
||||
int cost = 0;
|
||||
for (auto &instRef : *bb) {
|
||||
auto *inst = &instRef;
|
||||
if (auto *MI = dyn_cast<MethodInst>(inst)) {
|
||||
@@ -92,10 +99,12 @@ canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
|
||||
hasLoopInvariantOperands(inst, loop, invariants)) {
|
||||
moves.push_back(inst);
|
||||
invariants.insert(inst);
|
||||
} else {
|
||||
cost += (int)instructionInlineCost(instRef);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return cost < LoopRotateSizeLimit;
|
||||
}
|
||||
|
||||
static void mapOperands(SILInstruction *inst,
|
||||
@@ -440,11 +449,6 @@ class LoopRotation : public SILFunctionTransform {
|
||||
LLVM_DEBUG(llvm::dbgs() << "No loops in " << f->getName() << "\n");
|
||||
return;
|
||||
}
|
||||
if (!ShouldRotate) {
|
||||
LLVM_DEBUG(llvm::dbgs()
|
||||
<< "Skipping loop rotation in " << f->getName() << "\n");
|
||||
return;
|
||||
}
|
||||
LLVM_DEBUG(llvm::dbgs() << "Rotating loops in " << f->getName() << "\n");
|
||||
bool shouldVerify = getOptions().VerifyAll;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user