Add a variation on CopyPropagation to handle debug_value correctly.

MandatoryCopyPropagation must be a separate pass in order to preserve
all debug_value instructions. CopyPropagation cannot preserve
debug_value because, as a rule, debug information cannot affect -O
behavior.
This commit is contained in:
Andrew Trick
2021-01-04 17:59:19 -08:00
parent f22d0855df
commit 02784a2dc2
2 changed files with 17 additions and 3 deletions

View File

@@ -38,6 +38,12 @@ using namespace swift;
namespace {
class CopyPropagation : public SILFunctionTransform {
/// True if debug_value instructions should be pruned.
bool pruneDebug;
public:
CopyPropagation(bool pruneDebug): pruneDebug(pruneDebug) {}
/// The entry point to this function transformation.
void run() override;
};
@@ -64,7 +70,7 @@ void CopyPropagation::run() {
}
}
// Perform copy propgation for each copied value.
CanonicalizeOSSALifetime canonicalizer(/*pruneDebug*/ true);
CanonicalizeOSSALifetime canonicalizer(pruneDebug);
for (auto &def : copiedDefs) {
canonicalizer.canonicalizeValueLifetime(def);
if (SILValue outerCopy = canonicalizer.createdOuterCopy()) {
@@ -81,4 +87,10 @@ void CopyPropagation::run() {
}
}
SILTransform *swift::createCopyPropagation() { return new CopyPropagation(); }
SILTransform *swift::createCopyPropagation() {
return new CopyPropagation(/*pruneDebug*/ true);
}
SILTransform *swift::createMandatoryCopyPropagation() {
return new CopyPropagation(/*pruneDebug*/ false);
}