Skip to content

Commit a119aaf

Browse files
authored
Merge pull request #68651 from nate-chandler/test/20230920/1
[Test] Added for LexicalDestroyHoisting.
2 parents fca24bd + 8de1083 commit a119aaf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#include "swift/SIL/SILBasicBlock.h"
2020
#include "swift/SIL/SILInstruction.h"
2121
#include "swift/SIL/SILValue.h"
22+
#include "swift/SIL/Test.h"
2223
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
2324
#include "swift/SILOptimizer/Analysis/Reachability.h"
2425
#include "swift/SILOptimizer/Analysis/VisitBarrierAccessScopes.h"
26+
#include "swift/SILOptimizer/PassManager/Transforms.h"
2527
#include "swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h"
2628
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
2729
#include "swift/SILOptimizer/Utils/InstructionDeleter.h"
@@ -405,3 +407,25 @@ bool swift::hoistDestroysOfOwnedLexicalValue(
405407
calleeAnalysis);
406408
return LexicalDestroyHoisting::run(context);
407409
}
410+
411+
namespace swift::test {
412+
// Arguments:
413+
// - bool: pruneDebug
414+
// - bool: maximizeLifetimes
415+
// - bool: "respectAccessScopes", whether to contract lifetimes to end within
416+
// access scopes which they previously enclosed but can't be hoisted
417+
// before
418+
// - SILValue: value to canonicalize
419+
// Dumps:
420+
// - function after value canonicalization
421+
static FunctionTest LexicalDestroyHoistingTest(
422+
"lexical_destroy_hoisting",
423+
[](auto &function, auto &arguments, auto &test) {
424+
auto *calleeAnalysis = test.template getAnalysis<BasicCalleeAnalysis>();
425+
InstructionDeleter deleter;
426+
auto value = arguments.takeValue();
427+
hoistDestroysOfOwnedLexicalValue(value, *value->getFunction(), deleter,
428+
calleeAnalysis);
429+
function.dump();
430+
});
431+
} // end namespace swift::test

0 commit comments

Comments
 (0)