Skip to content

Commit 69693ed

Browse files
committed
[pmo] Eliminate incomplete support for promoting enums.
This was never implemented correctly way back in 2013-2014. It was originally added I believe so we could DI checks, but the promotion part was never added. Given that DI is now completely split from PMO, we can just turn this off and if necessary add it back on master "properly". rdar://41161408 (cherry picked from commit b9f69cb)
1 parent 73535cc commit 69693ed

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ class ElementUseCollector {
231231
/// element we attribute an access to.
232232
bool InStructSubElement = false;
233233

234-
/// When walking the use list, if we index into an enum slice, keep track
235-
/// of this.
236-
bool InEnumSubElement = false;
237-
238234
public:
239235
ElementUseCollector(const PMOMemoryObjectInfo &TheMemory,
240236
SmallVectorImpl<PMOMemoryUse> &Uses,
@@ -294,7 +290,7 @@ void ElementUseCollector::addElementUses(unsigned BaseEltNo, SILType UseTy,
294290
// If we're in a subelement of a struct or enum, just mark the struct, not
295291
// things that come after it in a parent tuple.
296292
unsigned NumElements = 1;
297-
if (TheMemory.NumElements != 1 && !InStructSubElement && !InEnumSubElement)
293+
if (TheMemory.NumElements != 1 && !InStructSubElement)
298294
NumElements = getElementCountRec(Module, UseTy);
299295

300296
Uses.push_back(PMOMemoryUse(User, Kind, BaseEltNo, NumElements));
@@ -309,7 +305,7 @@ bool ElementUseCollector::collectTupleElementUses(TupleElementAddrInst *TEAI,
309305
// If we're walking into a tuple within a struct or enum, don't adjust the
310306
// BaseElt. The uses hanging off the tuple_element_addr are going to be
311307
// counted as uses of the struct or enum itself.
312-
if (InStructSubElement || InEnumSubElement)
308+
if (InStructSubElement)
313309
return collectUses(TEAI, BaseEltNo);
314310

315311
// tuple_element_addr P, 42 indexes into the current tuple element.
@@ -554,26 +550,6 @@ bool ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
554550
llvm_unreachable("bad parameter convention");
555551
}
556552

557-
// init_enum_data_addr is treated like a tuple_element_addr or other
558-
// instruction that is looking into the memory object (i.e., the memory
559-
// object needs to be explicitly initialized by a copy_addr or some other
560-
// use of the projected address).
561-
if (auto I = dyn_cast<InitEnumDataAddrInst>(User)) {
562-
// If we are in a struct already, bail. With proper analysis, we should be
563-
// able to do this optimization.
564-
if (InStructSubElement) {
565-
return false;
566-
}
567-
568-
// Keep track of the fact that we're inside of an enum. This informs our
569-
// recursion that tuple stores are not scalarized outside, and that stores
570-
// should not be treated as partial stores.
571-
llvm::SaveAndRestore<bool> X(InEnumSubElement, true);
572-
if (!collectUses(I, BaseEltNo))
573-
return false;
574-
continue;
575-
}
576-
577553
// init_existential_addr is modeled as an initialization store.
578554
if (isa<InitExistentialAddrInst>(User)) {
579555
// init_existential_addr should not apply to struct subelements.
@@ -585,17 +561,6 @@ bool ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
585561
continue;
586562
}
587563

588-
// inject_enum_addr is modeled as an initialization store.
589-
if (isa<InjectEnumAddrInst>(User)) {
590-
// inject_enum_addr the subelement of a struct unless in a ctor.
591-
if (InStructSubElement) {
592-
return false;
593-
}
594-
Uses.push_back(
595-
PMOMemoryUse(User, PMOUseKind::Initialization, BaseEltNo, 1));
596-
continue;
597-
}
598-
599564
// open_existential_addr is a use of the protocol value,
600565
// so it is modeled as a load.
601566
if (isa<OpenExistentialAddrInst>(User)) {

test/SILOptimizer/predictable_memopt.sil

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,4 +880,24 @@ bb0(%arg : $K):
880880
%4 = load %0 : $*SWithOpt
881881
dealloc_stack %0 : $*SWithOpt
882882
return %4 : $SWithOpt
883-
}
883+
}
884+
885+
// We do not support this now, so make sure we do not do anything.
886+
//
887+
// CHECK-LABEL: sil @promote_init_enum_data_addr : $@convention(thin)
888+
// CHECK: alloc_stack
889+
// CHECK: load
890+
// CHECK: [[RESULT:%.*]] = load
891+
// CHECK: return [[RESULT]]
892+
// CHECK: } // end sil function 'promote_init_enum_data_addr'
893+
sil @promote_init_enum_data_addr : $@convention(thin) (@in Int) -> Int {
894+
bb0(%0 : $*Int):
895+
%1 = alloc_stack $Optional<Int>
896+
%2 = load %0 : $*Int
897+
%3 = init_enum_data_addr %1 : $*Optional<Int>, #Optional.some!enumelt.1
898+
store %2 to %3 : $*Int
899+
inject_enum_addr %1 : $*Optional<Int>, #Optional.some!enumelt.1
900+
%4 = load %3 : $*Int
901+
dealloc_stack %1 : $*Optional<Int>
902+
return %4 : $Int
903+
}

0 commit comments

Comments
 (0)