Skip to content

Commit 1b14b5b

Browse files
committed
[sil] Move swift::replaceAllUsesAndErase from Analysis/SimplifyInstruction -> Utils/InstOptUtils
This is a low level API already being used in multiple places besides InstSimplify (e.x.: Utils/OwnershipOptUtils), so it makes sense to move it into InstOptUtil.
1 parent ec50d03 commit 1b14b5b

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

include/swift/SILOptimizer/Analysis/SimplifyInstruction.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ replaceAllSimplifiedUsesAndErase(SILInstruction *I, SILValue result,
5252
InstModCallbacks &callbacks,
5353
DeadEndBlocks *deadEndBlocks = nullptr);
5454

55-
/// This is a low level routine that makes all uses of \p svi uses of \p
56-
/// newValue (ignoring end scope markers) and then deletes \p svi and all end
57-
/// scope markers. Then returns the next inst to process.
58-
SILBasicBlock::iterator replaceAllUsesAndErase(SingleValueInstruction *svi,
59-
SILValue newValue,
60-
InstModCallbacks &callbacks);
61-
62-
/// Simplify invocations of builtin operations that may overflow.
55+
// Simplify invocations of builtin operations that may overflow.
6356
/// All such operations return a tuple (result, overflow_flag).
6457
/// This function try to simplify such operations, but returns only a
6558
/// simplified first element of a tuple. The overflow flag is not returned

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,13 @@ FullApplySite cloneFullApplySiteReplacingCallee(FullApplySite applySite,
666666
SILValue newCallee,
667667
SILBuilderContext &builderCtx);
668668

669+
/// This is a low level routine that makes all uses of \p svi uses of \p
670+
/// newValue (ignoring end scope markers) and then deletes \p svi and all end
671+
/// scope markers. Then returns the next inst to process.
672+
SILBasicBlock::iterator replaceAllUsesAndErase(SingleValueInstruction *svi,
673+
SILValue newValue,
674+
InstModCallbacks &callbacks);
675+
669676
} // end namespace swift
670677

671678
#endif

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -735,31 +735,6 @@ case BuiltinValueKind::id:
735735
// Top Level Entrypoints
736736
//===----------------------------------------------------------------------===//
737737

738-
SILBasicBlock::iterator
739-
swift::replaceAllUsesAndErase(SingleValueInstruction *svi, SILValue newValue,
740-
InstModCallbacks &callbacks) {
741-
assert(svi != newValue && "Cannot RAUW a value with itself");
742-
SILBasicBlock::iterator nextii = std::next(svi->getIterator());
743-
744-
// Only SingleValueInstructions are currently simplified.
745-
while (!svi->use_empty()) {
746-
Operand *use = *svi->use_begin();
747-
SILInstruction *user = use->getUser();
748-
// Erase the end of scope marker.
749-
if (isEndOfScopeMarker(user)) {
750-
if (&*nextii == user)
751-
++nextii;
752-
callbacks.deleteInst(user);
753-
continue;
754-
}
755-
callbacks.setUseValue(use, newValue);
756-
}
757-
758-
callbacks.deleteInst(svi);
759-
760-
return nextii;
761-
}
762-
763738
/// Replace an instruction with a simplified result, including any debug uses,
764739
/// and erase the instruction. If the instruction initiates a scope, do not
765740
/// replace the end of its scope; it will be deleted along with its parent.

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,3 +1884,28 @@ swift::cloneFullApplySiteReplacingCallee(FullApplySite applySite,
18841884
}
18851885
llvm_unreachable("Unhandled case?!");
18861886
}
1887+
1888+
SILBasicBlock::iterator
1889+
swift::replaceAllUsesAndErase(SingleValueInstruction *svi, SILValue newValue,
1890+
InstModCallbacks &callbacks) {
1891+
assert(svi != newValue && "Cannot RAUW a value with itself");
1892+
SILBasicBlock::iterator nextii = std::next(svi->getIterator());
1893+
1894+
// Only SingleValueInstructions are currently simplified.
1895+
while (!svi->use_empty()) {
1896+
Operand *use = *svi->use_begin();
1897+
SILInstruction *user = use->getUser();
1898+
// Erase the end of scope marker.
1899+
if (isEndOfScopeMarker(user)) {
1900+
if (&*nextii == user)
1901+
++nextii;
1902+
callbacks.deleteInst(user);
1903+
continue;
1904+
}
1905+
callbacks.setUseValue(use, newValue);
1906+
}
1907+
1908+
callbacks.deleteInst(svi);
1909+
1910+
return nextii;
1911+
}

0 commit comments

Comments
 (0)