diff --git a/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp b/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp index fcb6c12e66fa0..7a9f6ec1849b7 100644 --- a/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp +++ b/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp @@ -19,9 +19,11 @@ #include "swift/SIL/SILBasicBlock.h" #include "swift/SIL/SILInstruction.h" #include "swift/SIL/SILValue.h" +#include "swift/SIL/Test.h" #include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h" #include "swift/SILOptimizer/Analysis/Reachability.h" #include "swift/SILOptimizer/Analysis/VisitBarrierAccessScopes.h" +#include "swift/SILOptimizer/PassManager/Transforms.h" #include "swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h" #include "swift/SILOptimizer/Utils/InstOptUtils.h" #include "swift/SILOptimizer/Utils/InstructionDeleter.h" @@ -405,3 +407,25 @@ bool swift::hoistDestroysOfOwnedLexicalValue( calleeAnalysis); return LexicalDestroyHoisting::run(context); } + +namespace swift::test { +// Arguments: +// - bool: pruneDebug +// - bool: maximizeLifetimes +// - bool: "respectAccessScopes", whether to contract lifetimes to end within +// access scopes which they previously enclosed but can't be hoisted +// before +// - SILValue: value to canonicalize +// Dumps: +// - function after value canonicalization +static FunctionTest LexicalDestroyHoistingTest( + "lexical_destroy_hoisting", + [](auto &function, auto &arguments, auto &test) { + auto *calleeAnalysis = test.template getAnalysis(); + InstructionDeleter deleter; + auto value = arguments.takeValue(); + hoistDestroysOfOwnedLexicalValue(value, *value->getFunction(), deleter, + calleeAnalysis); + function.dump(); + }); +} // end namespace swift::test