}
}
+static void EmitAndPrintRemark(OptimizationRemarkEmitter *ORE,
+ DiagnosticInfoOptimizationBase &Rem) {
+ LLVM_DEBUG(dbgs() << Rem.getMsg() << "\n");
+ ORE->emit(Rem);
+}
+
void SelectOptimize::findProfitableSIGroupsInnerLoops(
const Loop *L, SelectGroups &SIGroups, SelectGroups &ProfSIGroups) {
NumSelectOptAnalyzed += SIGroups.size();
OR << "Profitable to convert to branch (loop analysis). BranchCost="
<< BranchCost.toString() << ", SelectCost=" << SelectCost.toString()
<< ". ";
- ORE->emit(OR);
+ EmitAndPrintRemark(ORE, OR);
++NumSelectConvertedLoop;
ProfSIGroups.push_back(ASI);
} else {
ORmiss << "Select is more profitable (loop analysis). BranchCost="
<< BranchCost.toString()
<< ", SelectCost=" << SelectCost.toString() << ". ";
- ORE->emit(ORmiss);
+ EmitAndPrintRemark(ORE, ORmiss);
}
}
}
bool SelectOptimize::isConvertToBranchProfitableBase(
const SmallVector<SelectInst *, 2> &ASI) {
SelectInst *SI = ASI.front();
+ LLVM_DEBUG(dbgs() << "Analyzing select group containing " << *SI << "\n");
OptimizationRemark OR(DEBUG_TYPE, "SelectOpti", SI);
OptimizationRemarkMissed ORmiss(DEBUG_TYPE, "SelectOpti", SI);
if (PSI->isColdBlock(SI->getParent(), BFI.get())) {
++NumSelectColdBB;
ORmiss << "Not converted to branch because of cold basic block. ";
- ORE->emit(ORmiss);
+ EmitAndPrintRemark(ORE, ORmiss);
return false;
}
if (SI->getMetadata(LLVMContext::MD_unpredictable)) {
++NumSelectUnPred;
ORmiss << "Not converted to branch because of unpredictable branch. ";
- ORE->emit(ORmiss);
+ EmitAndPrintRemark(ORE, ORmiss);
return false;
}
if (isSelectHighlyPredictable(SI) && TLI->isPredictableSelectExpensive()) {
++NumSelectConvertedHighPred;
OR << "Converted to branch because of highly predictable branch. ";
- ORE->emit(OR);
+ EmitAndPrintRemark(ORE, OR);
return true;
}
if (hasExpensiveColdOperand(ASI)) {
++NumSelectConvertedExpColdOperand;
OR << "Converted to branch because of expensive cold operand.";
- ORE->emit(OR);
+ EmitAndPrintRemark(ORE, OR);
return true;
}
ORmiss << "Not profitable to convert to branch (base heuristic).";
- ORE->emit(ORmiss);
+ EmitAndPrintRemark(ORE, ORmiss);
return false;
}
OptimizationRemarkMissed ORmiss(DEBUG_TYPE, "SelectOpti", ASI.front());
ORmiss << "Profile data available but missing branch-weights metadata for "
"select instruction. ";
- ORE->emit(ORmiss);
+ EmitAndPrintRemark(ORE, ORmiss);
}
if (!ColdOperand)
return false;
LoopCost[1].NonPredCost >= LoopCost[1].PredCost) {
ORmissL << "No select conversion in the loop due to no reduction of loop's "
"critical path. ";
- ORE->emit(ORmissL);
+ EmitAndPrintRemark(ORE, ORmissL);
return false;
}
"loop's critical path. Gain="
<< Gain[1].toString()
<< ", RelativeGain=" << RelativeGain.toString() << "%. ";
- ORE->emit(ORmissL);
+ EmitAndPrintRemark(ORE, ORmissL);
return false;
}
ORmissL << "No select conversion in the loop due to small gradient gain. "
"GradientGain="
<< GradientGain.toString() << "%. ";
- ORE->emit(ORmissL);
+ EmitAndPrintRemark(ORE, ORmissL);
return false;
}
}
else if (Gain[1] < Gain[0]) {
ORmissL
<< "No select conversion in the loop due to negative gradient gain. ";
- ORE->emit(ORmissL);
+ EmitAndPrintRemark(ORE, ORmissL);
return false;
}
bool SelectOptimize::computeLoopCosts(
const Loop *L, const SelectGroups &SIGroups,
DenseMap<const Instruction *, CostInfo> &InstCostMap, CostInfo *LoopCost) {
+ LLVM_DEBUG(dbgs() << "Calculating Latency / IPredCost / INonPredCost of loop "
+ << L->getHeader()->getName() << "\n");
const auto &SIset = getSIset(SIGroups);
// Compute instruction and loop-critical-path costs across two iterations for
// both predicated and non-predicated version.
ORmissL << "Invalid instruction cost preventing analysis and "
"optimization of the inner-most loop containing this "
"instruction. ";
- ORE->emit(ORmissL);
+ EmitAndPrintRemark(ORE, ORmissL);
return false;
}
IPredCost += Scaled64::get(ILatency.value());
INonPredCost = PredictedPathCost + MispredictCost;
}
+ LLVM_DEBUG(dbgs() << " " << ILatency << "/" << IPredCost << "/"
+ << INonPredCost << " for " << I << "\n");
InstCostMap[&I] = {IPredCost, INonPredCost};
MaxCost.PredCost = std::max(MaxCost.PredCost, IPredCost);
MaxCost.NonPredCost = std::max(MaxCost.NonPredCost, INonPredCost);
}
}
+ LLVM_DEBUG(dbgs() << "Iteration " << Iter + 1
+ << " MaxCost = " << MaxCost.PredCost << " "
+ << MaxCost.NonPredCost << "\n");
}
return true;
}