Skip to content

Commit 50d6c30

Browse files
committed
SILOptimizer: Add some LLVM_DEBUGs to GlobalOpt
1 parent 8195d5e commit 50d6c30

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,12 @@ static SILFunction *genGetterFromInit(SILOptFunctionBuilder &FunctionBuilder,
294294
auto V = Store->getSrc();
295295

296296
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');
298300
return nullptr;
301+
}
302+
299303
Insts.push_back(cast<SingleValueInstruction>(Store->getDest()));
300304
Insts.push_back(Store);
301305

@@ -637,6 +641,9 @@ replaceLoadsByKnownValue(BuiltinInst *CallToOnce, SILFunction *AddrF,
637641
SILFunction *InitF, SILGlobalVariable *SILG,
638642
SingleValueInstruction *InitVal,
639643
GlobalInitCalls &Calls) {
644+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: replacing loads with known value for "
645+
<< SILG->getName() << '\n');
646+
640647
assert(isAssignedOnlyOnceInInitializer(SILG) &&
641648
"The value of the initializer should be known at compile-time");
642649
assert(SILG->getDecl() &&
@@ -736,6 +743,9 @@ void SILGlobalOpt::optimizeInitializer(SILFunction *AddrF,
736743

737744
// Remove "once" call from the addressor.
738745
if (!isAssignedOnlyOnceInInitializer(SILG) || !SILG->getDecl()) {
746+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: building static initializer for "
747+
<< SILG->getName() << '\n');
748+
739749
removeToken(CallToOnce->getOperand(0));
740750
CallToOnce->eraseFromParent();
741751
StaticInitCloner::appendToInitializer(SILG, InitVal);
@@ -819,6 +829,8 @@ void SILGlobalOpt::collectGlobalAccess(GlobalAddrInst *GAI) {
819829
auto *F = GAI->getFunction();
820830

821831
if (!SILG->getLoweredType().isTrivial(*F)) {
832+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: type is not trivial: "
833+
<< SILG->getName() << '\n');
822834
GlobalVarSkipProcessing.insert(SILG);
823835
return;
824836
}
@@ -843,6 +855,9 @@ void SILGlobalOpt::collectGlobalAccess(GlobalAddrInst *GAI) {
843855
continue;
844856
}
845857

858+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: has non-store, non-load use: "
859+
<< SILG->getName() << '\n';
860+
Op->getUser()->dump());
846861
// This global is not initialized by a simple
847862
// constant value at this moment.
848863
GlobalVarSkipProcessing.insert(SILG);
@@ -858,16 +873,23 @@ void SILGlobalOpt::optimizeGlobalAccess(SILGlobalVariable *SILG,
858873
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: use static initializer for "
859874
<< SILG->getName() << '\n');
860875

861-
if (GlobalVarSkipProcessing.count(SILG))
876+
if (GlobalVarSkipProcessing.count(SILG)) {
877+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: already decided to skip: "
878+
<< SILG->getName() << '\n');
862879
return;
880+
}
863881

864-
if (//!isAssignedOnlyOnceInInitializer(SILG) ||
865-
!SILG->getDecl()) {
882+
if (!SILG->getDecl()) {
883+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: no AST declaration: "
884+
<< SILG->getName() << '\n');
866885
return;
867886
}
868887

869-
if (!GlobalLoadMap.count(SILG))
888+
if (!GlobalLoadMap.count(SILG)) {
889+
LLVM_DEBUG(llvm::dbgs() << "GlobalOpt: not in load map: "
890+
<< SILG->getName() << '\n');
870891
return;
892+
}
871893

872894
// Generate a getter only if there are any loads from this variable.
873895
SILFunction *GetterF = genGetterFromInit(FunctionBuilder, SI, SILG);

0 commit comments

Comments
 (0)