|
29 | 29 | #include "swift/SIL/BasicBlockUtils.h"
|
30 | 30 | #include "swift/SIL/DebugUtils.h"
|
31 | 31 | #include "swift/SIL/InstructionUtils.h"
|
| 32 | +#include "swift/SIL/OwnershipUtils.h" |
32 | 33 | #include "swift/SIL/Projection.h"
|
33 | 34 | #include "swift/SIL/SILArgument.h"
|
34 | 35 | #include "swift/SIL/SILDeclRef.h"
|
@@ -858,6 +859,19 @@ bool DeadObjectElimination::processAllocRef(AllocRefInstBase *ARI) {
|
858 | 859 | }
|
859 | 860 |
|
860 | 861 | if (ARI->getFunction()->hasOwnership()) {
|
| 862 | + // In ossa, we are going to delete the dead element store and insert a |
| 863 | + // destroy_value of the store's source. This is shortening the store's |
| 864 | + // source lifetime. Check if there was a pointer escape of the store's |
| 865 | + // source, if so bail out. |
| 866 | + for (auto *user : UsersToRemove) { |
| 867 | + auto *store = dyn_cast<StoreInst>(user); |
| 868 | + if (!store || |
| 869 | + store->getOwnershipQualifier() == StoreOwnershipQualifier::Trivial) |
| 870 | + continue; |
| 871 | + if (findPointerEscape(store->getSrc())) { |
| 872 | + return false; |
| 873 | + } |
| 874 | + } |
861 | 875 | for (auto *user : UsersToRemove) {
|
862 | 876 | auto *store = dyn_cast<StoreInst>(user);
|
863 | 877 | if (!store ||
|
@@ -893,6 +907,19 @@ bool DeadObjectElimination::processAllocStack(AllocStackInst *ASI) {
|
893 | 907 | }
|
894 | 908 |
|
895 | 909 | if (ASI->getFunction()->hasOwnership()) {
|
| 910 | + for (auto *user : UsersToRemove) { |
| 911 | + auto *store = dyn_cast<StoreInst>(user); |
| 912 | + if (!store || |
| 913 | + store->getOwnershipQualifier() == StoreOwnershipQualifier::Trivial) |
| 914 | + continue; |
| 915 | + // In ossa, we are going to delete the dead store and insert a |
| 916 | + // destroy_value of the store's source. This is shortening the store's |
| 917 | + // source lifetime. Check if there was a pointer escape of the store's |
| 918 | + // source, if so bail out. |
| 919 | + if (findPointerEscape(store->getSrc())) { |
| 920 | + return false; |
| 921 | + } |
| 922 | + } |
896 | 923 | for (auto *user : UsersToRemove) {
|
897 | 924 | auto *store = dyn_cast<StoreInst>(user);
|
898 | 925 | if (!store ||
|
@@ -929,6 +956,17 @@ bool DeadObjectElimination::processKeyPath(KeyPathInst *KPI) {
|
929 | 956 | }
|
930 | 957 |
|
931 | 958 | if (KPI->getFunction()->hasOwnership()) {
|
| 959 | + for (const Operand &Op : KPI->getPatternOperands()) { |
| 960 | + if (Op.get()->getType().isTrivial(*KPI->getFunction())) |
| 961 | + continue; |
| 962 | + // In ossa, we are going to delete the dead keypath which was consuming |
| 963 | + // the pattern operand and insert a destroy_value of the pattern operand |
| 964 | + // value. This is shortening the pattern operand value's lifetime. Check |
| 965 | + // if there was a pointer escape, if so bail out. |
| 966 | + if (findPointerEscape(Op.get())) { |
| 967 | + return false; |
| 968 | + } |
| 969 | + } |
932 | 970 | for (const Operand &Op : KPI->getPatternOperands()) {
|
933 | 971 | if (Op.get()->getType().isTrivial(*KPI->getFunction()))
|
934 | 972 | continue;
|
|
0 commit comments