|
14 | 14 | #include "swift/Demangling/Demangle.h"
|
15 | 15 | #include "swift/SIL/CFG.h"
|
16 | 16 | #include "swift/SIL/DebugUtils.h"
|
| 17 | +#include "swift/SIL/SILGlobalVariable.h" |
17 | 18 | #include "swift/SIL/SILInstruction.h"
|
18 | 19 | #include "swift/SILOptimizer/Analysis/ColdBlockInfo.h"
|
19 | 20 | #include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
|
@@ -113,8 +114,6 @@ class SILGlobalOpt {
|
113 | 114 | /// This is the main entrypoint for collecting global accesses.
|
114 | 115 | void collectGlobalAccess(GlobalAddrInst *GAI);
|
115 | 116 |
|
116 |
| - SILGlobalVariable *getVariableOfGlobalInit(SILFunction *AddrF); |
117 |
| - |
118 | 117 | /// Returns true if we think that \p CurBB is inside a loop.
|
119 | 118 | bool isInLoop(SILBasicBlock *CurBB);
|
120 | 119 |
|
@@ -349,21 +348,6 @@ void SILGlobalOpt::collectGlobalStore(StoreInst *SI, SILGlobalVariable *SILG) {
|
349 | 348 | GlobalVarStore[SILG] = SI;
|
350 | 349 | }
|
351 | 350 |
|
352 |
| -/// Return the callee of a once call. |
353 |
| -static SILFunction *getCalleeOfOnceCall(BuiltinInst *BI) { |
354 |
| - assert(BI->getNumOperands() == 2 && "once call should have 2 operands."); |
355 |
| - |
356 |
| - auto Callee = BI->getOperand(1); |
357 |
| - assert(Callee->getType().castTo<SILFunctionType>()->getRepresentation() |
358 |
| - == SILFunctionTypeRepresentation::CFunctionPointer && |
359 |
| - "Expected C function representation!"); |
360 |
| - |
361 |
| - if (auto *FR = dyn_cast<FunctionRefInst>(Callee)) |
362 |
| - return FR->getReferencedFunction(); |
363 |
| - |
364 |
| - return nullptr; |
365 |
| -} |
366 |
| - |
367 | 351 | // Update UnhandledOnceCallee and InitializerCount by going through all "once"
|
368 | 352 | // calls.
|
369 | 353 | void SILGlobalOpt::collectOnceCall(BuiltinInst *BI) {
|
@@ -596,34 +580,6 @@ static SILFunction *genGetterFromInit(SILFunction *InitF, VarDecl *varDecl) {
|
596 | 580 | return GetterF;
|
597 | 581 | }
|
598 | 582 |
|
599 |
| -/// Find the globalinit_func by analyzing the body of the addressor. |
600 |
| -static SILFunction *findInitializer(SILModule *Module, SILFunction *AddrF, |
601 |
| - BuiltinInst *&CallToOnce) { |
602 |
| - // We only handle a single SILBasicBlock for now. |
603 |
| - if (AddrF->size() != 1) |
604 |
| - return nullptr; |
605 |
| - |
606 |
| - CallToOnce = nullptr; |
607 |
| - SILBasicBlock *BB = &AddrF->front(); |
608 |
| - for (auto &I : *BB) { |
609 |
| - // Find the builtin "once" call. |
610 |
| - if (auto *BI = dyn_cast<BuiltinInst>(&I)) { |
611 |
| - const BuiltinInfo &Builtin = Module->getBuiltinInfo(BI->getName()); |
612 |
| - if (Builtin.ID != BuiltinValueKind::Once) |
613 |
| - continue; |
614 |
| - |
615 |
| - // Bail if we have multiple "once" calls in the addressor. |
616 |
| - if (CallToOnce) |
617 |
| - return nullptr; |
618 |
| - |
619 |
| - CallToOnce = BI; |
620 |
| - } |
621 |
| - } |
622 |
| - if (!CallToOnce) |
623 |
| - return nullptr; |
624 |
| - return getCalleeOfOnceCall(CallToOnce); |
625 |
| -} |
626 |
| - |
627 | 583 | /// Checks if a given global variable is assigned only once.
|
628 | 584 | static bool isAssignedOnlyOnceInInitializer(SILGlobalVariable *SILG) {
|
629 | 585 | if (SILG->isLet())
|
@@ -669,49 +625,6 @@ static SILValue convertLoadSequence(SILValue oldSequence,
|
669 | 625 | return nullptr;
|
670 | 626 | }
|
671 | 627 |
|
672 |
| -static SILGlobalVariable *getVariableOfStaticInitializer(SILFunction *InitFunc, |
673 |
| - SingleValueInstruction *&InitVal) { |
674 |
| - InitVal = nullptr; |
675 |
| - SILGlobalVariable *GVar = nullptr; |
676 |
| - // We only handle a single SILBasicBlock for now. |
677 |
| - if (InitFunc->size() != 1) |
678 |
| - return nullptr; |
679 |
| - |
680 |
| - SILBasicBlock *BB = &InitFunc->front(); |
681 |
| - GlobalAddrInst *SGA = nullptr; |
682 |
| - bool HasStore = false; |
683 |
| - for (auto &I : *BB) { |
684 |
| - // Make sure we have a single GlobalAddrInst and a single StoreInst. |
685 |
| - // And the StoreInst writes to the GlobalAddrInst. |
686 |
| - if (isa<AllocGlobalInst>(&I) || isa<ReturnInst>(&I) |
687 |
| - || isa<DebugValueInst>(&I)) { |
688 |
| - continue; |
689 |
| - } else if (auto *sga = dyn_cast<GlobalAddrInst>(&I)) { |
690 |
| - if (SGA) |
691 |
| - return nullptr; |
692 |
| - SGA = sga; |
693 |
| - GVar = SGA->getReferencedGlobal(); |
694 |
| - } else if (auto *SI = dyn_cast<StoreInst>(&I)) { |
695 |
| - if (HasStore || SI->getDest() != SGA) |
696 |
| - return nullptr; |
697 |
| - HasStore = true; |
698 |
| - SILValue value = SI->getSrc(); |
699 |
| - |
700 |
| - // We only handle StructInst and TupleInst being stored to a |
701 |
| - // global variable for now. |
702 |
| - if (!isa<StructInst>(value) && !isa<TupleInst>(value)) |
703 |
| - return nullptr; |
704 |
| - InitVal = cast<SingleValueInstruction>(value); |
705 |
| - } else if (!SILGlobalVariable::isValidStaticInitializerInst(&I, |
706 |
| - I.getModule())) { |
707 |
| - return nullptr; |
708 |
| - } |
709 |
| - } |
710 |
| - if (!InitVal) |
711 |
| - return nullptr; |
712 |
| - return GVar; |
713 |
| -} |
714 |
| - |
715 | 628 | /// Replace loads from a global variable by the known value.
|
716 | 629 | void SILGlobalOpt::
|
717 | 630 | replaceLoadsByKnownValue(BuiltinInst *CallToOnce, SILFunction *AddrF,
|
@@ -822,29 +735,6 @@ void SILGlobalOpt::optimizeInitializer(SILFunction *AddrF,
|
822 | 735 | HasChanged = true;
|
823 | 736 | }
|
824 | 737 |
|
825 |
| -SILGlobalVariable *SILGlobalOpt::getVariableOfGlobalInit(SILFunction *AddrF) { |
826 |
| - if (!AddrF->isGlobalInit()) |
827 |
| - return nullptr; |
828 |
| - |
829 |
| - // If the addressor contains a single "once" call, it calls globalinit_func, |
830 |
| - // and the globalinit_func is called by "once" from a single location, |
831 |
| - // continue; otherwise bail. |
832 |
| - BuiltinInst *CallToOnce; |
833 |
| - auto *InitF = findInitializer(Module, AddrF, CallToOnce); |
834 |
| - |
835 |
| - if (!InitF || !InitF->getName().startswith("globalinit_") |
836 |
| - || InitializerCount[InitF] > 1) |
837 |
| - return nullptr; |
838 |
| - |
839 |
| - // If the globalinit_func is trivial, continue; otherwise bail. |
840 |
| - SingleValueInstruction *dummyInitVal; |
841 |
| - auto *SILG = getVariableOfStaticInitializer(InitF, dummyInitVal); |
842 |
| - if (!SILG || !SILG->isDefinition()) |
843 |
| - return nullptr; |
844 |
| - |
845 |
| - return SILG; |
846 |
| -} |
847 |
| - |
848 | 738 | static bool canBeChangedExternally(SILGlobalVariable *SILG) {
|
849 | 739 | // Don't assume anything about globals which are imported from other modules.
|
850 | 740 | if (isAvailableExternally(SILG->getLinkage()))
|
|
0 commit comments