@@ -983,6 +983,18 @@ bool AvailableValueDataflowContext::hasEscapedAt(SILInstruction *I) {
983
983
// Allocation Optimization
984
984
// ===----------------------------------------------------------------------===//
985
985
986
+ static SILType getMemoryType (AllocationInst *memory) {
987
+ // Compute the type of the memory object.
988
+ if (auto *abi = dyn_cast<AllocBoxInst>(memory)) {
989
+ assert (abi->getBoxType ()->getLayout ()->getFields ().size () == 1 &&
990
+ " optimizing multi-field boxes not implemented" );
991
+ return abi->getBoxType ()->getFieldType (abi->getModule (), 0 );
992
+ }
993
+
994
+ assert (isa<AllocStackInst>(memory));
995
+ return cast<AllocStackInst>(memory)->getElementType ();
996
+ }
997
+
986
998
namespace {
987
999
988
1000
// / This performs load promotion and deletes synthesized allocations if all
@@ -1008,8 +1020,13 @@ class AllocOptimize {
1008
1020
AvailableValueDataflowContext DataflowContext;
1009
1021
1010
1022
public:
1011
- AllocOptimize (AllocationInst *TheMemory, SmallVectorImpl<PMOMemoryUse> &Uses,
1012
- SmallVectorImpl<SILInstruction *> &Releases);
1023
+ AllocOptimize (AllocationInst *memory, SmallVectorImpl<PMOMemoryUse> &uses,
1024
+ SmallVectorImpl<SILInstruction *> &releases)
1025
+ : Module(memory->getModule ()), TheMemory(memory),
1026
+ MemoryType(getMemoryType(memory)),
1027
+ NumMemorySubElements(getNumSubElements(MemoryType, Module)), Uses(uses),
1028
+ Releases(releases),
1029
+ DataflowContext(TheMemory, NumMemorySubElements, uses) {}
1013
1030
1014
1031
bool optimizeMemoryAccesses ();
1015
1032
bool tryToRemoveDeadAllocation ();
@@ -1024,26 +1041,6 @@ class AllocOptimize {
1024
1041
1025
1042
} // end anonymous namespace
1026
1043
1027
- static SILType getMemoryType (AllocationInst *TheMemory) {
1028
- // Compute the type of the memory object.
1029
- if (auto *ABI = dyn_cast<AllocBoxInst>(TheMemory)) {
1030
- assert (ABI->getBoxType ()->getLayout ()->getFields ().size () == 1 &&
1031
- " optimizing multi-field boxes not implemented" );
1032
- return ABI->getBoxType ()->getFieldType (ABI->getModule (), 0 );
1033
- } else {
1034
- assert (isa<AllocStackInst>(TheMemory));
1035
- return cast<AllocStackInst>(TheMemory)->getElementType ();
1036
- }
1037
- }
1038
-
1039
- AllocOptimize::AllocOptimize (AllocationInst *InputMemory,
1040
- SmallVectorImpl<PMOMemoryUse> &InputUses,
1041
- SmallVectorImpl<SILInstruction *> &InputReleases)
1042
- : Module(InputMemory->getModule ()), TheMemory(InputMemory),
1043
- MemoryType(getMemoryType(TheMemory)),
1044
- NumMemorySubElements(getNumSubElements(MemoryType, Module)),
1045
- Uses(InputUses), Releases(InputReleases),
1046
- DataflowContext(TheMemory, NumMemorySubElements, Uses) {}
1047
1044
1048
1045
// / If we are able to optimize \p Inst, return the source address that
1049
1046
// / instruction is loading from. If we can not optimize \p Inst, then just
0 commit comments