Skip to content

Commit 51dfc63

Browse files
committed
SimplifyCFG: fix indentation so subsequent diffs are clean.
1 parent bfe219f commit 51dfc63

File tree

1 file changed

+133
-131
lines changed

1 file changed

+133
-131
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 133 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -60,146 +60,148 @@ STATISTIC(NumSROAArguments, "Number of aggregate argument levels split by "
6060
static unsigned MaxIterationsOfDominatorBasedSimplify = 10;
6161

6262
namespace {
63-
class SimplifyCFG {
64-
SILOptFunctionBuilder FuncBuilder;
65-
SILFunction &Fn;
66-
SILPassManager *PM;
67-
68-
// WorklistList is the actual list that we iterate over (for determinism).
69-
// Slots may be null, which should be ignored.
70-
SmallVector<SILBasicBlock*, 32> WorklistList;
71-
// WorklistMap keeps track of which slot a BB is in, allowing efficient
72-
// containment query, and allows efficient removal.
73-
llvm::SmallDenseMap<SILBasicBlock*, unsigned, 32> WorklistMap;
74-
// Keep track of loop headers - we don't want to jump-thread through them.
75-
SmallPtrSet<SILBasicBlock *, 32> LoopHeaders;
76-
// The cost (~ number of copied instructions) of jump threading per basic
77-
// block. Used to prevent infinite jump threading loops.
78-
llvm::SmallDenseMap<SILBasicBlock *, int, 8> JumpThreadingCost;
79-
80-
// Dominance and post-dominance info for the current function
81-
DominanceInfo *DT = nullptr;
82-
83-
ConstantFolder ConstFolder;
84-
85-
// True if the function has a large amount of blocks. In this case we turn off some expensive
86-
// optimizations.
87-
bool isVeryLargeFunction = false;
88-
89-
void constFoldingCallback(SILInstruction *I) {
90-
// If a terminal instruction gets constant folded (like cond_br), it
91-
// enables further simplify-CFG optimizations.
92-
if (isa<TermInst>(I))
93-
addToWorklist(I->getParent());
94-
}
95-
96-
bool ShouldVerify;
97-
bool EnableJumpThread;
98-
public:
99-
SimplifyCFG(SILFunction &Fn, SILTransform &T, bool Verify,
100-
bool EnableJumpThread)
101-
: FuncBuilder(T), Fn(Fn), PM(T.getPassManager()),
102-
ConstFolder(FuncBuilder, PM->getOptions().AssertConfig,
103-
/* EnableDiagnostics */false,
104-
[&](SILInstruction *I) { constFoldingCallback(I); }),
105-
ShouldVerify(Verify), EnableJumpThread(EnableJumpThread) {}
106-
107-
bool run();
108-
109-
bool simplifyBlockArgs() {
110-
auto *DA = PM->getAnalysis<DominanceAnalysis>();
63+
class SimplifyCFG {
64+
SILOptFunctionBuilder FuncBuilder;
65+
SILFunction &Fn;
66+
SILPassManager *PM;
67+
68+
// WorklistList is the actual list that we iterate over (for determinism).
69+
// Slots may be null, which should be ignored.
70+
SmallVector<SILBasicBlock *, 32> WorklistList;
71+
// WorklistMap keeps track of which slot a BB is in, allowing efficient
72+
// containment query, and allows efficient removal.
73+
llvm::SmallDenseMap<SILBasicBlock *, unsigned, 32> WorklistMap;
74+
// Keep track of loop headers - we don't want to jump-thread through them.
75+
SmallPtrSet<SILBasicBlock *, 32> LoopHeaders;
76+
// The cost (~ number of copied instructions) of jump threading per basic
77+
// block. Used to prevent infinite jump threading loops.
78+
llvm::SmallDenseMap<SILBasicBlock *, int, 8> JumpThreadingCost;
79+
80+
// Dominance and post-dominance info for the current function
81+
DominanceInfo *DT = nullptr;
82+
83+
ConstantFolder ConstFolder;
84+
85+
// True if the function has a large amount of blocks. In this case we turn off
86+
// some expensive optimizations.
87+
bool isVeryLargeFunction = false;
88+
89+
void constFoldingCallback(SILInstruction *I) {
90+
// If a terminal instruction gets constant folded (like cond_br), it
91+
// enables further simplify-CFG optimizations.
92+
if (isa<TermInst>(I))
93+
addToWorklist(I->getParent());
94+
}
95+
96+
bool ShouldVerify;
97+
bool EnableJumpThread;
11198

112-
DT = DA->get(&Fn);
113-
bool Changed = false;
114-
for (SILBasicBlock &BB : Fn) {
115-
Changed |= simplifyArgs(&BB);
116-
}
117-
DT = nullptr;
118-
return Changed;
119-
}
99+
public:
100+
SimplifyCFG(SILFunction &Fn, SILTransform &T, bool Verify,
101+
bool EnableJumpThread)
102+
: FuncBuilder(T), Fn(Fn), PM(T.getPassManager()),
103+
ConstFolder(FuncBuilder, PM->getOptions().AssertConfig,
104+
/* EnableDiagnostics */ false,
105+
[&](SILInstruction *I) { constFoldingCallback(I); }),
106+
ShouldVerify(Verify), EnableJumpThread(EnableJumpThread) {}
120107

121-
private:
122-
void clearWorklist() {
123-
WorklistMap.clear();
124-
WorklistList.clear();
125-
}
108+
bool run();
126109

127-
/// popWorklist - Return the next basic block to look at, or null if the
128-
/// worklist is empty. This handles skipping over null entries in the
129-
/// worklist.
130-
SILBasicBlock *popWorklist() {
131-
while (!WorklistList.empty())
132-
if (auto *BB = WorklistList.pop_back_val()) {
133-
WorklistMap.erase(BB);
134-
return BB;
135-
}
110+
bool simplifyBlockArgs() {
111+
auto *DA = PM->getAnalysis<DominanceAnalysis>();
136112

137-
return nullptr;
113+
DT = DA->get(&Fn);
114+
bool Changed = false;
115+
for (SILBasicBlock &BB : Fn) {
116+
Changed |= simplifyArgs(&BB);
138117
}
118+
DT = nullptr;
119+
return Changed;
120+
}
139121

140-
/// addToWorklist - Add the specified block to the work list if it isn't
141-
/// already present.
142-
void addToWorklist(SILBasicBlock *BB) {
143-
unsigned &Entry = WorklistMap[BB];
144-
if (Entry != 0) return;
145-
WorklistList.push_back(BB);
146-
Entry = WorklistList.size();
147-
}
122+
private:
123+
void clearWorklist() {
124+
WorklistMap.clear();
125+
WorklistList.clear();
126+
}
127+
128+
/// popWorklist - Return the next basic block to look at, or null if the
129+
/// worklist is empty. This handles skipping over null entries in the
130+
/// worklist.
131+
SILBasicBlock *popWorklist() {
132+
while (!WorklistList.empty())
133+
if (auto *BB = WorklistList.pop_back_val()) {
134+
WorklistMap.erase(BB);
135+
return BB;
136+
}
148137

149-
/// removeFromWorklist - Remove the specified block from the worklist if
150-
/// present.
151-
void removeFromWorklist(SILBasicBlock *BB) {
152-
assert(BB && "Cannot add null pointer to the worklist");
153-
auto It = WorklistMap.find(BB);
154-
if (It == WorklistMap.end()) return;
138+
return nullptr;
139+
}
155140

156-
// If the BB is in the worklist, null out its entry.
157-
if (It->second) {
158-
assert(WorklistList[It->second-1] == BB && "Consistency error");
159-
WorklistList[It->second-1] = nullptr;
160-
}
141+
/// addToWorklist - Add the specified block to the work list if it isn't
142+
/// already present.
143+
void addToWorklist(SILBasicBlock *BB) {
144+
unsigned &Entry = WorklistMap[BB];
145+
if (Entry != 0)
146+
return;
147+
WorklistList.push_back(BB);
148+
Entry = WorklistList.size();
149+
}
161150

162-
// Remove it from the map as well.
163-
WorklistMap.erase(It);
164-
165-
if (LoopHeaders.count(BB))
166-
LoopHeaders.erase(BB);
167-
}
168-
169-
bool simplifyBlocks();
170-
bool canonicalizeSwitchEnums();
171-
bool simplifyThreadedTerminators();
172-
bool dominatorBasedSimplifications(SILFunction &Fn,
173-
DominanceInfo *DT);
174-
bool dominatorBasedSimplify(DominanceAnalysis *DA);
175-
176-
/// Remove the basic block if it has no predecessors. Returns true
177-
/// If the block was removed.
178-
bool removeIfDead(SILBasicBlock *BB);
179-
180-
bool tryJumpThreading(BranchInst *BI);
181-
bool tailDuplicateObjCMethodCallSuccessorBlocks();
182-
bool simplifyAfterDroppingPredecessor(SILBasicBlock *BB);
183-
bool addToWorklistAfterSplittingEdges(SILBasicBlock *BB);
184-
185-
bool simplifyBranchOperands(OperandValueArrayRef Operands);
186-
bool simplifyBranchBlock(BranchInst *BI);
187-
bool simplifyCondBrBlock(CondBranchInst *BI);
188-
bool simplifyCheckedCastBranchBlock(CheckedCastBranchInst *CCBI);
189-
bool simplifyCheckedCastValueBranchBlock(CheckedCastValueBranchInst *CCBI);
190-
bool simplifyCheckedCastAddrBranchBlock(CheckedCastAddrBranchInst *CCABI);
191-
bool simplifyTryApplyBlock(TryApplyInst *TAI);
192-
bool simplifySwitchValueBlock(SwitchValueInst *SVI);
193-
bool simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB);
194-
bool simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI);
195-
bool simplifySwitchEnumBlock(SwitchEnumInst *SEI);
196-
bool simplifyUnreachableBlock(UnreachableInst *UI);
197-
bool simplifyProgramTerminationBlock(SILBasicBlock *BB);
198-
bool simplifyArgument(SILBasicBlock *BB, unsigned i);
199-
bool simplifyArgs(SILBasicBlock *BB);
200-
void findLoopHeaders();
201-
bool simplifySwitchEnumOnObjcClassOptional(SwitchEnumInst *SEI);
202-
};
151+
/// removeFromWorklist - Remove the specified block from the worklist if
152+
/// present.
153+
void removeFromWorklist(SILBasicBlock *BB) {
154+
assert(BB && "Cannot add null pointer to the worklist");
155+
auto It = WorklistMap.find(BB);
156+
if (It == WorklistMap.end())
157+
return;
158+
159+
// If the BB is in the worklist, null out its entry.
160+
if (It->second) {
161+
assert(WorklistList[It->second - 1] == BB && "Consistency error");
162+
WorklistList[It->second - 1] = nullptr;
163+
}
164+
165+
// Remove it from the map as well.
166+
WorklistMap.erase(It);
167+
168+
if (LoopHeaders.count(BB))
169+
LoopHeaders.erase(BB);
170+
}
171+
172+
bool simplifyBlocks();
173+
bool canonicalizeSwitchEnums();
174+
bool simplifyThreadedTerminators();
175+
bool dominatorBasedSimplifications(SILFunction &Fn, DominanceInfo *DT);
176+
bool dominatorBasedSimplify(DominanceAnalysis *DA);
177+
178+
/// Remove the basic block if it has no predecessors. Returns true
179+
/// If the block was removed.
180+
bool removeIfDead(SILBasicBlock *BB);
181+
182+
bool tryJumpThreading(BranchInst *BI);
183+
bool tailDuplicateObjCMethodCallSuccessorBlocks();
184+
bool simplifyAfterDroppingPredecessor(SILBasicBlock *BB);
185+
bool addToWorklistAfterSplittingEdges(SILBasicBlock *BB);
186+
187+
bool simplifyBranchOperands(OperandValueArrayRef Operands);
188+
bool simplifyBranchBlock(BranchInst *BI);
189+
bool simplifyCondBrBlock(CondBranchInst *BI);
190+
bool simplifyCheckedCastBranchBlock(CheckedCastBranchInst *CCBI);
191+
bool simplifyCheckedCastValueBranchBlock(CheckedCastValueBranchInst *CCBI);
192+
bool simplifyCheckedCastAddrBranchBlock(CheckedCastAddrBranchInst *CCABI);
193+
bool simplifyTryApplyBlock(TryApplyInst *TAI);
194+
bool simplifySwitchValueBlock(SwitchValueInst *SVI);
195+
bool simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB);
196+
bool simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI);
197+
bool simplifySwitchEnumBlock(SwitchEnumInst *SEI);
198+
bool simplifyUnreachableBlock(UnreachableInst *UI);
199+
bool simplifyProgramTerminationBlock(SILBasicBlock *BB);
200+
bool simplifyArgument(SILBasicBlock *BB, unsigned i);
201+
bool simplifyArgs(SILBasicBlock *BB);
202+
void findLoopHeaders();
203+
bool simplifySwitchEnumOnObjcClassOptional(SwitchEnumInst *SEI);
204+
};
203205

204206
} // end anonymous namespace
205207

0 commit comments

Comments
 (0)