Skip to content

Commit 81fa786

Browse files
committed
Comments, typos, and cleanup from review.
1 parent bd28b0e commit 81fa786

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
138138
&& "cloned instruction dropped debug scope");
139139
}
140140

141-
/// Visitor callback that maps an original value to an existing value. Called
142-
/// whenever the visitor that clones an instruction skips doPostProcess().
141+
/// Visitor callback that maps an original value to an existing value. If the
142+
/// original instruction can be folded away in the cloned code, then the
143+
/// instruction visitor should call this instead of cloning the instruction
144+
/// and calling doPostProcess(). foldValue() and doPostProcess() are the only
145+
/// two ways for a visitor to remap an original value that may be used within
146+
/// the cloned region.
143147
void foldValue(SILValue origValue, SILValue mappedValue) {
144-
ValueMap.insert({origValue, mappedValue});
148+
auto iterAndInserted = ValueMap.insert({origValue, mappedValue});
149+
(void)iterAndInserted;
150+
assert(iterAndInserted.second && "Original value already mapped.");
145151
}
146152

147153
/// Mark a block containing an unreachable instruction for use in the `fixUp`
@@ -316,7 +322,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
316322
// terminator.
317323
void visitInstructionsInBlock(SILBasicBlock *BB);
318324

319-
// Visit a block's terminator. This is called with each block in DFS predorder
325+
// Visit a block's terminator. This is called with each block in DFS preorder
320326
// after visiting and mapping all basic blocks and after visiting all
321327
// non-terminator instructions in the block.
322328
void visitTerminator(SILBasicBlock *BB) {
@@ -623,18 +629,14 @@ void SILCloner<ImplClass>::visitBlocksDepthFirst(
623629
continue;
624630

625631
// Map the successor to a new BB.
626-
auto *MappedBB = newF.createBasicBlock();
632+
auto *MappedBB = insertBeforeBB
633+
? newF.createBasicBlockBefore(insertBeforeBB)
634+
: newF.createBasicBlock();
635+
627636
BBMap.insert(std::make_pair(Succ.getBB(), MappedBB));
628637

629638
clonePhiArgs(Succ);
630639

631-
// Also, move the new mapped BB to the right position in the caller
632-
if (insertBeforeBB) {
633-
newF.getBlocks().splice(SILFunction::iterator(insertBeforeBB),
634-
newF.getBlocks(),
635-
SILFunction::iterator(MappedBB));
636-
}
637-
638640
dfsWorklist.push_back(Succ);
639641
}
640642
// Reverse the worklist to pop the successors in forward order.

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class EdgeThreadingCloner : public BaseThreadingCloner {
377377
DestPHIArg->getType(), DestPHIArg->getOwnershipKind());
378378
// Since we don't call any CFG cloning entry point, we can call
379379
// `foldValue` immediately as if cloning has already started. This simply
380-
// avoids handling AvailVals during `remap` or defining a custome
380+
// avoids handling AvailVals during `remap` or defining a custom
381381
// visitSILPhiArgument().
382382
foldValue(DestPHIArg, BlockArg);
383383
AvailVals.push_back(std::make_pair(DestPHIArg, BlockArg));
@@ -427,7 +427,7 @@ class BasicBlockCloner : public BaseThreadingCloner {
427427
for (unsigned i = 0, e = FromBB->args_size(); i != e; ++i) {
428428
// Since we don't call any CFG cloning entry point, we can call
429429
// `foldValue` immediately as if cloning has already started. This
430-
// simply avoids handling AvailVals during `remap` or defining a custome
430+
// simply avoids handling AvailVals during `remap` or defining a custom
431431
// visitSILPhiArgument().
432432
foldValue(FromBB->getArgument(i), DestBB->getArgument(i));
433433
AvailVals.push_back(

include/swift/SILOptimizer/Utils/SILInliner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class SILInliner {
8383
///
8484
/// *NOTE*: This attempts to perform inlining unconditionally and thus asserts
8585
/// if inlining will fail. All users /must/ check that a function is allowed
86-
/// to be inlined using SILInliner::canInlineApplyAite before calling this
86+
/// to be inlined using SILInliner::canInlineApplySite before calling this
8787
/// function.
8888
SILBasicBlock::iterator inlineFunction(SILFunction *calleeFunction,
8989
FullApplySite apply,

0 commit comments

Comments
 (0)