[llvm] b803aee - [FuncSpec][NFC] Improve debug messages.
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 1 03:55:25 PST 2022
Author: Alexandros Lamprineas
Date: 2022-03-01T11:55:08Z
New Revision: b803aee67b2e085693e42ced9ba51f9c96e24186
URL: https://github.com/llvm/llvm-project/commit/b803aee67b2e085693e42ced9ba51f9c96e24186
DIFF: https://github.com/llvm/llvm-project/commit/b803aee67b2e085693e42ced9ba51f9c96e24186.diff
LOG: [FuncSpec][NFC] Improve debug messages.
Adds diagnostic messages when debugging the pass.
Differential Revision: https://reviews.llvm.org/D119875
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/lib/Transforms/Utils/SCCPSolver.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 7eff04313bdef..e7ba3a8dd578f 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -302,6 +302,9 @@ class FunctionSpecializer {
continue;
}
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Specialization cost for "
+ << F->getName() << " is " << Cost << "\n");
+
auto ConstArgs = calculateGains(F, Cost);
if (ConstArgs.empty()) {
LLVM_DEBUG(dbgs() << "FnSpecialization: no possible constants found\n");
@@ -390,8 +393,6 @@ class FunctionSpecializer {
// argument can take on. If specialization is not profitable, we continue
// on to the next argument.
for (Argument &FormalArg : F->args()) {
- LLVM_DEBUG(dbgs() << "FnSpecialization: Analysing arg: "
- << FormalArg.getName() << "\n");
// Determine if this argument is interesting. If we know the argument can
// take on any constant values, they are collected in Constants. If the
// argument can only ever equal a constant value in Constants, the
@@ -401,7 +402,9 @@ class FunctionSpecializer {
bool IsPartial = true;
SmallVector<Constant *> ActualArgs;
if (!isArgumentInteresting(&FormalArg, ActualArgs, IsPartial)) {
- LLVM_DEBUG(dbgs() << "FnSpecialization: Argument is not interesting\n");
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Argument "
+ << FormalArg.getNameOrAsOperand()
+ << " is not interesting\n");
continue;
}
@@ -427,10 +430,10 @@ class FunctionSpecializer {
// Truncate the worklist to 'MaxClonesThreshold' candidates if
// necessary.
if (Worklist.size() > MaxClonesThreshold) {
- LLVM_DEBUG(dbgs() << "FnSpecialization: number of candidates exceed "
- << "the maximum number of clones threshold.\n"
- << "Truncating worklist to " << MaxClonesThreshold
- << " candidates.\n");
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Number of candidates exceed "
+ << "the maximum number of clones threshold.\n"
+ << "FnSpecialization: Truncating worklist to "
+ << MaxClonesThreshold << " candidates.\n");
Worklist.erase(Worklist.begin() + MaxClonesThreshold,
Worklist.end());
}
@@ -439,14 +442,16 @@ class FunctionSpecializer {
for (auto &ActualArg : Worklist)
ActualArg.Partial = true;
- LLVM_DEBUG(dbgs() << "Sorted list of candidates by gain:\n";
- for (auto &C
- : Worklist) {
- dbgs() << "- Function = " << C.Fn->getName() << ", ";
- dbgs() << "FormalArg = " << C.Formal->getName() << ", ";
- dbgs() << "ActualArg = " << C.Actual->getName() << ", ";
- dbgs() << "Gain = " << C.Gain << "\n";
- });
+ LLVM_DEBUG(
+ dbgs() << "FnSpecialization: Specializations for function "
+ << F->getName() << "\n";
+ for (auto &C : Worklist) {
+ dbgs() << "FnSpecialization: FormalArg = "
+ << C.Formal->getNameOrAsOperand() << ", ActualArg = "
+ << C.Actual->getNameOrAsOperand() << ", Gain = "
+ << C.Gain << "\n";
+ }
+ );
// FIXME: Only one argument per function.
break;
@@ -556,13 +561,13 @@ class FunctionSpecializer {
DominatorTree DT(*F);
LoopInfo LI(DT);
auto &TTI = (GetTTI)(*F);
- LLVM_DEBUG(dbgs() << "FnSpecialization: Analysing bonus for: " << *A
- << "\n");
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Analysing bonus for constant: "
+ << C->getNameOrAsOperand() << "\n");
InstructionCost TotalCost = 0;
for (auto *U : A->users()) {
TotalCost += getUserBonus(U, TTI, LI);
- LLVM_DEBUG(dbgs() << "FnSpecialization: User cost ";
+ LLVM_DEBUG(dbgs() << "FnSpecialization: User cost ";
TotalCost.print(dbgs()); dbgs() << " for: " << *U << "\n");
}
@@ -620,6 +625,9 @@ class FunctionSpecializer {
Bonus += Params.DefaultThreshold;
else if (IC.isVariable() && IC.getCostDelta() > 0)
Bonus += IC.getCostDelta();
+
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Inlining bonus " << Bonus
+ << " for user " << *U << "\n");
}
return TotalCost + Bonus;
@@ -649,8 +657,9 @@ class FunctionSpecializer {
// If the argument isn't overdefined, there's nothing to do. It should
// already be constant.
if (!Solver.getLatticeValueFor(A).isOverdefined()) {
- LLVM_DEBUG(dbgs() << "FnSpecialization: nothing to do, arg is already "
- << "constant?\n");
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Nothing to do, argument "
+ << A->getNameOrAsOperand()
+ << " is already constant?\n");
return false;
}
@@ -668,7 +677,8 @@ class FunctionSpecializer {
// TODO 2: this currently does not support constants, i.e. integer ranges.
//
IsPartial = !getPossibleConstants(A, Constants);
- LLVM_DEBUG(dbgs() << "FnSpecialization: interesting arg: " << *A << "\n");
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Found interesting argument "
+ << A->getNameOrAsOperand() << "\n");
return true;
}
@@ -753,7 +763,15 @@ class FunctionSpecializer {
continue;
CallSitesToRewrite.push_back(&CS);
}
+
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Replacing call sites of "
+ << F->getName() << " with "
+ << Clone->getName() << "\n");
+
for (auto *CS : CallSitesToRewrite) {
+ LLVM_DEBUG(dbgs() << "FnSpecialization: "
+ << CS->getFunction()->getName() << " ->"
+ << *CS << "\n");
if ((CS->getFunction() == Clone && CS->getArgOperand(ArgNo) == &Arg) ||
CS->getArgOperand(ArgNo) == C) {
CS->setCalledFunction(Clone);
@@ -779,7 +797,7 @@ class FunctionSpecializer {
for (Argument &Arg : F->args())
if (!Arg.use_empty() && tryToReplaceWithConstant(&Arg))
LLVM_DEBUG(dbgs() << "FnSpecialization: Replaced constant argument: "
- << Arg.getName() << "\n");
+ << Arg.getNameOrAsOperand() << "\n");
}
}
};
@@ -890,6 +908,7 @@ bool llvm::runFunctionSpecialization(
unsigned I = 0;
while (FuncSpecializationMaxIters != I++ &&
FS.specializeFunctions(FuncDecls, WorkList)) {
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Finished iteration " << I << "\n");
// Run the solver for the specialized functions.
RunSCCPSolver(WorkList);
@@ -901,6 +920,9 @@ bool llvm::runFunctionSpecialization(
Changed = true;
}
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Number of specializations = "
+ << NumFuncSpecialized <<"\n");
+
// Clean up the IR by removing dead instructions and ssa_copy intrinsics.
FS.removeDeadInstructions();
removeSSACopy(M);
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 12cc6715ecab0..0413c70b56b1b 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -538,7 +538,11 @@ void SCCPInstVisitor::markArgInFuncSpecialization(Function *F, Argument *A,
// over from the old function.
for (Argument *OldArg = F->arg_begin(), *NewArg = A->getParent()->arg_begin(),
*End = F->arg_end();
- OldArg != End; ++OldArg, ++NewArg)
+ OldArg != End; ++OldArg, ++NewArg) {
+
+ LLVM_DEBUG(dbgs() << "SCCP: Marking argument "
+ << NewArg->getNameOrAsOperand() << "\n");
+
if (NewArg != A && ValueState.count(OldArg)) {
// Note: This previously looked like this:
// ValueState[NewArg] = ValueState[OldArg];
@@ -549,6 +553,7 @@ void SCCPInstVisitor::markArgInFuncSpecialization(Function *F, Argument *A,
NewValue = ValueState[OldArg];
pushToWorkList(NewValue, NewArg);
}
+ }
}
void SCCPInstVisitor::visitInstruction(Instruction &I) {
More information about the llvm-commits
mailing list