@@ -294,8 +294,12 @@ static SILFunction *genGetterFromInit(SILOptFunctionBuilder &FunctionBuilder,
294
294
auto V = Store->getSrc ();
295
295
296
296
SmallVector<SILInstruction *, 8 > Insts;
297
- if (!analyzeStaticInitializer (V, Insts))
297
+ if (!analyzeStaticInitializer (V, Insts)) {
298
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: can't analyze static initializer for "
299
+ << SILG->getName () << ' \n ' );
298
300
return nullptr ;
301
+ }
302
+
299
303
Insts.push_back (cast<SingleValueInstruction>(Store->getDest ()));
300
304
Insts.push_back (Store);
301
305
@@ -637,6 +641,9 @@ replaceLoadsByKnownValue(BuiltinInst *CallToOnce, SILFunction *AddrF,
637
641
SILFunction *InitF, SILGlobalVariable *SILG,
638
642
SingleValueInstruction *InitVal,
639
643
GlobalInitCalls &Calls) {
644
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: replacing loads with known value for "
645
+ << SILG->getName () << ' \n ' );
646
+
640
647
assert (isAssignedOnlyOnceInInitializer (SILG) &&
641
648
" The value of the initializer should be known at compile-time" );
642
649
assert (SILG->getDecl () &&
@@ -736,6 +743,9 @@ void SILGlobalOpt::optimizeInitializer(SILFunction *AddrF,
736
743
737
744
// Remove "once" call from the addressor.
738
745
if (!isAssignedOnlyOnceInInitializer (SILG) || !SILG->getDecl ()) {
746
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: building static initializer for "
747
+ << SILG->getName () << ' \n ' );
748
+
739
749
removeToken (CallToOnce->getOperand (0 ));
740
750
CallToOnce->eraseFromParent ();
741
751
StaticInitCloner::appendToInitializer (SILG, InitVal);
@@ -819,6 +829,8 @@ void SILGlobalOpt::collectGlobalAccess(GlobalAddrInst *GAI) {
819
829
auto *F = GAI->getFunction ();
820
830
821
831
if (!SILG->getLoweredType ().isTrivial (*F)) {
832
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: type is not trivial: "
833
+ << SILG->getName () << ' \n ' );
822
834
GlobalVarSkipProcessing.insert (SILG);
823
835
return ;
824
836
}
@@ -843,6 +855,9 @@ void SILGlobalOpt::collectGlobalAccess(GlobalAddrInst *GAI) {
843
855
continue ;
844
856
}
845
857
858
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: has non-store, non-load use: "
859
+ << SILG->getName () << ' \n ' ;
860
+ Op->getUser ()->dump ());
846
861
// This global is not initialized by a simple
847
862
// constant value at this moment.
848
863
GlobalVarSkipProcessing.insert (SILG);
@@ -858,16 +873,23 @@ void SILGlobalOpt::optimizeGlobalAccess(SILGlobalVariable *SILG,
858
873
LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: use static initializer for "
859
874
<< SILG->getName () << ' \n ' );
860
875
861
- if (GlobalVarSkipProcessing.count (SILG))
876
+ if (GlobalVarSkipProcessing.count (SILG)) {
877
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: already decided to skip: "
878
+ << SILG->getName () << ' \n ' );
862
879
return ;
880
+ }
863
881
864
- if (// !isAssignedOnlyOnceInInitializer(SILG) ||
865
- !SILG->getDecl ()) {
882
+ if (!SILG->getDecl ()) {
883
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: no AST declaration: "
884
+ << SILG->getName () << ' \n ' );
866
885
return ;
867
886
}
868
887
869
- if (!GlobalLoadMap.count (SILG))
888
+ if (!GlobalLoadMap.count (SILG)) {
889
+ LLVM_DEBUG (llvm::dbgs () << " GlobalOpt: not in load map: "
890
+ << SILG->getName () << ' \n ' );
870
891
return ;
892
+ }
871
893
872
894
// Generate a getter only if there are any loads from this variable.
873
895
SILFunction *GetterF = genGetterFromInit (FunctionBuilder, SI, SILG);
0 commit comments