Skip to content

Commit e3a98e8

Browse files
committed
Add new flags to enable specific SimplifyCFG operations
1 parent a303bb4 commit e3a98e8

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+19-23
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,21 @@
5858
#include "llvm/Support/CommandLine.h"
5959
#include "llvm/Support/Debug.h"
6060

61-
// This is temporarily used for testing until Swift 5.5 branches to reduce risk.
62-
llvm::cl::opt<bool> EnableOSSASimplifyCFG(
63-
"enable-ossa-simplify-cfg",
64-
llvm::cl::desc(
65-
"Enable non-trivial OSSA simplify-cfg and simple jump threading "
66-
"(staging)."));
67-
68-
// This requires new OwnershipOptUtilities which aren't well tested yet.
69-
llvm::cl::opt<bool> EnableOSSARewriteTerminator(
70-
"enable-ossa-rewriteterminator",
71-
llvm::cl::desc(
72-
"Enable OSSA simplify-cfg with non-trivial terminator rewriting "
73-
"(staging)."));
61+
llvm::cl::opt<bool> EnableOSSACheckedCastBrJumpThreading(
62+
"enable-ossa-checked-cast-br-jump-threading",
63+
llvm::cl::desc("Enable OSSA checked cast branch jump threading "
64+
"(staging)."),
65+
llvm::cl::init(true));
66+
67+
llvm::cl::opt<bool> EnableOSSASimpleJumpThreading(
68+
"enable-ossa-simple-jump-threading",
69+
llvm::cl::desc("Enable OSSA simple jump threading (staging)."),
70+
llvm::cl::init(true));
71+
72+
llvm::cl::opt<bool> EnableOSSADominatorBasedSimplify(
73+
"enable-ossa-dominator-based-simplify",
74+
llvm::cl::desc("Enable OSSA dominator based simplifications (staging)."),
75+
llvm::cl::init(true));
7476

7577
llvm::cl::opt<bool> IsInfiniteJumpThreadingBudget(
7678
"sil-infinite-jump-threading-budget",
@@ -536,7 +538,7 @@ bool SimplifyCFG::dominatorBasedSimplify(DominanceAnalysis *DA) {
536538
// Get the dominator tree.
537539
DT = DA->get(&Fn);
538540

539-
if (!EnableOSSASimplifyCFG && Fn.hasOwnership())
541+
if (!EnableOSSADominatorBasedSimplify && Fn.hasOwnership())
540542
return false;
541543

542544
// Split all critical edges such that we can move code onto edges. This is
@@ -560,7 +562,7 @@ bool SimplifyCFG::dominatorBasedSimplify(DominanceAnalysis *DA) {
560562
// and MUST NOT change the CFG without updating the dominator tree to
561563
// reflect such change.
562564
if (tryCheckedCastBrJumpThreading(&Fn, DT, deBlocks, BlocksForWorklist,
563-
EnableOSSARewriteTerminator)) {
565+
EnableOSSACheckedCastBrJumpThreading)) {
564566
for (auto BB: BlocksForWorklist)
565567
addToWorklist(BB);
566568

@@ -907,19 +909,13 @@ static bool hasInjectedEnumAtEndOfBlock(SILBasicBlock *block, SILValue enumAddr)
907909
/// tryJumpThreading - Check to see if it looks profitable to duplicate the
908910
/// destination of an unconditional jump into the bottom of this block.
909911
bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
910-
if (!EnableOSSASimplifyCFG && Fn.hasOwnership())
912+
if (!EnableOSSASimpleJumpThreading && Fn.hasOwnership())
911913
return false;
912914

913915
auto *DestBB = BI->getDestBB();
914916
auto *SrcBB = BI->getParent();
915917
TermInst *destTerminator = DestBB->getTerminator();
916-
if (!EnableOSSARewriteTerminator && Fn.hasOwnership()) {
917-
if (llvm::any_of(DestBB->getArguments(), [this](SILValue op) {
918-
return !op->getType().isTrivial(Fn);
919-
})) {
920-
return false;
921-
}
922-
}
918+
923919
// If the destination block ends with a return, we don't want to duplicate it.
924920
// We want to maintain the canonical form of a single return where possible.
925921
if (destTerminator->isFunctionExiting())

0 commit comments

Comments
 (0)