[llvm] 4f2ccdd - [Attributor][NFC] Improve debug messages
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 16:18:10 PDT 2022
Author: Johannes Doerfert
Date: 2022-07-19T18:17:40-05:00
New Revision: 4f2ccdd0b16823052ff34a07afff89c525c45cd8
URL: https://github.com/llvm/llvm-project/commit/4f2ccdd0b16823052ff34a07afff89c525c45cd8
DIFF: https://github.com/llvm/llvm-project/commit/4f2ccdd0b16823052ff34a07afff89c525c45cd8.diff
LOG: [Attributor][NFC] Improve debug messages
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index d97438ba9926..4cdfaf8009b0 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -343,6 +343,7 @@ static bool getPotentialCopiesOfMemoryValue(
const auto *TLI =
A.getInfoCache().getTargetLibraryInfoForFunction(*I.getFunction());
+ LLVM_DEBUG(dbgs() << "Visit " << Objects.size() << " objects:\n");
for (Value *Obj : Objects) {
LLVM_DEBUG(dbgs() << "Visit underlying object " << *Obj << "\n");
if (isa<UndefValue>(Obj))
@@ -390,8 +391,10 @@ static bool getPotentialCopiesOfMemoryValue(
if (IsLoad) {
Value *InitialValue = AA::getInitialValueForObj(*Obj, *I.getType(), TLI);
- if (!InitialValue)
+ if (!InitialValue) {
+ LLVM_DEBUG(dbgs() << "Failed to get initial value: " << *Obj << "\n");
return false;
+ }
CheckForNullOnlyAndUndef(InitialValue);
NewCopies.push_back(InitialValue);
NewCopyOrigins.push_back(nullptr);
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index c93b2ef88a94..492c9e2e36f1 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1173,6 +1173,27 @@ struct AAPointerInfoImpl
/// Statistic tracking for all AAPointerInfo implementations.
/// See AbstractAttribute::trackStatistics().
void trackPointerInfoStatistics(const IRPosition &IRP) const {}
+
+ /// Dump the state into \p O.
+ void dumpState(raw_ostream &O) {
+ for (auto &It : AccessBins) {
+ O << "[" << It.first.getOffset() << "-"
+ << It.first.getOffset() + It.first.getSize()
+ << "] : " << It.getSecond()->size() << "\n";
+ for (auto &Acc : *It.getSecond()) {
+ O << " - " << Acc.getKind() << " - " << *Acc.getLocalInst() << "\n";
+ if (Acc.getLocalInst() != Acc.getRemoteInst())
+ O << " --> " << *Acc.getRemoteInst()
+ << "\n";
+ if (!Acc.isWrittenValueYetUndetermined()) {
+ if (Acc.getWrittenValue())
+ O << " - c: " << *Acc.getWrittenValue() << "\n";
+ else
+ O << " - c: <unknown>\n";
+ }
+ }
+ }
+ }
};
struct AAPointerInfoFloating : public AAPointerInfoImpl {
@@ -1372,36 +1393,30 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
return false;
};
auto EquivalentUseCB = [&](const Use &OldU, const Use &NewU) {
- if (OffsetInfoMap.count(NewU))
+ if (OffsetInfoMap.count(NewU)) {
+ LLVM_DEBUG({
+ if (!(OffsetInfoMap[NewU] == OffsetInfoMap[OldU])) {
+ dbgs() << "[AAPointerInfo] Equivalent use callback failed: "
+ << OffsetInfoMap[NewU].Offset << " vs "
+ << OffsetInfoMap[OldU].Offset << "\n";
+ }
+ });
return OffsetInfoMap[NewU] == OffsetInfoMap[OldU];
+ }
OffsetInfoMap[NewU] = OffsetInfoMap[OldU];
return true;
};
if (!A.checkForAllUses(UsePred, *this, AssociatedValue,
/* CheckBBLivenessOnly */ true, DepClassTy::OPTIONAL,
- /* IgnoreDroppableUses */ true, EquivalentUseCB))
+ /* IgnoreDroppableUses */ true, EquivalentUseCB)) {
+ LLVM_DEBUG(
+ dbgs() << "[AAPointerInfo] Check for all uses failed, abort!\n");
return indicatePessimisticFixpoint();
+ }
LLVM_DEBUG({
dbgs() << "Accesses by bin after update:\n";
- for (auto &It : AccessBins) {
- dbgs() << "[" << It.first.getOffset() << "-"
- << It.first.getOffset() + It.first.getSize()
- << "] : " << It.getSecond()->size() << "\n";
- for (auto &Acc : *It.getSecond()) {
- dbgs() << " - " << Acc.getKind() << " - " << *Acc.getLocalInst()
- << "\n";
- if (Acc.getLocalInst() != Acc.getRemoteInst())
- dbgs() << " --> "
- << *Acc.getRemoteInst() << "\n";
- if (!Acc.isWrittenValueYetUndetermined()) {
- if (Acc.getWrittenValue())
- dbgs() << " - c: " << *Acc.getWrittenValue() << "\n";
- else
- dbgs() << " - c: <unknown>\n";
- }
- }
- }
+ dumpState(dbgs());
});
return Changed;
@@ -1474,6 +1489,12 @@ struct AAPointerInfoCallSiteArgument final : AAPointerInfoFloating {
<< *MI << "\n");
return indicatePessimisticFixpoint();
}
+
+ LLVM_DEBUG({
+ dbgs() << "Accesses by bin after update:\n";
+ dumpState(dbgs());
+ });
+
return Changed;
}
@@ -9478,8 +9499,11 @@ struct AAFunctionReachabilityFunction : public AAFunctionReachability {
for (auto *AAEdges : AAEdgesList) {
if (AAEdges->hasUnknownCallee()) {
- if (!CanReachUnknownCallee)
+ if (!CanReachUnknownCallee) {
+ LLVM_DEBUG(dbgs()
+ << "[QueryResolver] Edges include unknown callee!\n");
Change = ChangeStatus::CHANGED;
+ }
CanReachUnknownCallee = true;
return Change;
}
@@ -9643,8 +9667,11 @@ struct AAFunctionReachabilityFunction : public AAFunctionReachability {
// This is a hack for us to be able to cache queries.
auto *NonConstThis = const_cast<AAFunctionReachabilityFunction *>(this);
QueryResolver &InstQSet = NonConstThis->InstQueries[&Inst];
- if (!AllKnown)
+ if (!AllKnown) {
+ LLVM_DEBUG(dbgs() << "[AAReachability] Not all reachable edges known, "
+ "may reach unknown callee!\n");
InstQSet.CanReachUnknownCallee = true;
+ }
return InstQSet.isReachable(A, *NonConstThis, CallEdges, Fn);
}
@@ -9677,8 +9704,11 @@ struct AAFunctionReachabilityFunction : public AAFunctionReachability {
bool AllKnown =
getReachableCallEdges(A, *Reachability, *InstPair.first, CallEdges);
// Update will return change if we this effects any queries.
- if (!AllKnown)
+ if (!AllKnown) {
+ LLVM_DEBUG(dbgs() << "[AAReachability] Not all reachable edges "
+ "known, may reach unknown callee!\n");
InstPair.second.CanReachUnknownCallee = true;
+ }
Change |= InstPair.second.update(A, *this, CallEdges);
}
}
@@ -9691,8 +9721,11 @@ struct AAFunctionReachabilityFunction : public AAFunctionReachability {
WholeFunction.Reachable.size() + WholeFunction.Unreachable.size();
return "FunctionReachability [" +
- std::to_string(WholeFunction.Reachable.size()) + "," +
- std::to_string(QueryCount) + "]";
+ (canReachUnknownCallee()
+ ? "unknown"
+ : (std::to_string(WholeFunction.Reachable.size()) + "," +
+ std::to_string(QueryCount))) +
+ "]";
}
void trackStatistics() const override {}
@@ -10058,8 +10091,12 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
if (!AA::getPotentiallyLoadedValues(A, LI, PotentialCopies,
PotentialValueOrigins, *this,
UsedAssumedInformation,
- /* OnlyExact */ true))
+ /* OnlyExact */ true)) {
+ LLVM_DEBUG(dbgs() << "[AAPotentialValues] Failed to get potentially "
+ "loaded values for load instruction "
+ << LI << "\n");
return false;
+ }
// Do not simplify loads that are only used in llvm.assume if we cannot also
// remove all stores that may feed into the load. The reason is that the
@@ -10077,8 +10114,12 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
return A.isAssumedDead(*I, this, /* LivenessAA */ nullptr,
UsedAssumedInformation,
/* CheckBBLivenessOnly */ false);
- }))
+ })) {
+ LLVM_DEBUG(dbgs() << "[AAPotentialValues] Load is onl used by assumes "
+ "and we cannot delete all the stores: "
+ << LI << "\n");
return false;
+ }
}
// Values have to be dynamically unique or we loose the fact that a
@@ -10091,8 +10132,12 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
AllLocal &= AA::isValidInScope(*PC, getAnchorScope());
return AA::isDynamicallyUnique(A, *this, *PC);
});
- if (!DynamicallyUnique)
+ if (!DynamicallyUnique) {
+ LLVM_DEBUG(dbgs() << "[AAPotentialValues] Not all potentially loaded "
+ "values are dynamically unique: "
+ << LI << "\n");
return false;
+ }
for (auto *PotentialCopy : PotentialCopies) {
if (AllLocal) {
More information about the llvm-commits
mailing list