[BOLT] Fix no-assertions build.

(cherry picked from FBD5130285)
This commit is contained in:
Maksim Panchenko
2017-05-25 10:29:38 -07:00
parent 174e3a825b
commit 2428567f7d
7 changed files with 141 additions and 109 deletions

View File

@@ -301,8 +301,9 @@ void BinaryBasicBlock::addLandingPad(BinaryBasicBlock *LPBlock) {
void BinaryBasicBlock::clearLandingPads() {
for (auto *LPBlock : LandingPads) {
auto count = LPBlock->Throwers.erase(this);
assert(count == 1 && "Possible duplicate entry in LandingPads");
auto Count = LPBlock->Throwers.erase(this);
(void)Count;
assert(Count == 1 && "Possible duplicate entry in LandingPads");
}
LandingPads.clear();
}

View File

@@ -1074,6 +1074,7 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
const auto Result =
BC.MIA->replaceImmWithSymbol(Instruction, Relocation.Symbol,
Relocation.Addend, BC.Ctx.get(), Value);
(void)Result;
assert(Result && "cannot replace immediate with relocation");
// Make sure we replaced the correct immediate (instruction
@@ -1240,6 +1241,7 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
case IndirectBranchType::POSSIBLE_TAIL_CALL:
{
auto Result = MIA->convertJmpToTailCall(Instruction);
(void)Result;
assert(Result);
if (BranchDataOrErr) {
MIA->addAnnotation(Ctx.get(), Instruction, "IndirectBranchData",
@@ -2351,7 +2353,6 @@ void BinaryFunction::annotateCFIState() {
}
bool BinaryFunction::fixCFIState() {
auto Sep = "";
DEBUG(dbgs() << "Trying to fix CFI states for each BB after reordering.\n");
DEBUG(dbgs() << "This is the list of CFI states for each BB of " << *this
<< ": ");
@@ -2402,6 +2403,8 @@ bool BinaryFunction::fixCFIState() {
int32_t State = 0;
auto *FDEStartBB = BasicBlocksLayout[0];
bool SeenCold = false;
auto Sep = "";
(void)Sep;
for (auto *BB : BasicBlocksLayout) {
const auto CFIStateAtExit = BB->getCFIStateAtExit();
@@ -3093,8 +3096,8 @@ void BinaryFunction::mergeProfileDataInto(BinaryFunction &BF) const {
auto BIMergeI = BBMerge->branch_info_begin();
auto BII = BB->branch_info_begin();
for (const auto *BBSucc : BB->successors()) {
auto *BBMergeSucc = *BBMergeSI;
assert(getIndex(BBSucc) == BF.getIndex(BBMergeSucc));
(void)BBSucc;
assert(getIndex(BBSucc) == BF.getIndex(*BBMergeSI));
// At this point no branch count should be set to COUNT_NO_PROFILE.
assert(BII->Count != BinaryBasicBlock::COUNT_NO_PROFILE &&
@@ -3124,7 +3127,7 @@ void BinaryFunction::mergeProfileDataInto(BinaryFunction &BF) const {
assert(BBMergeI == BF.end());
}
__attribute__((noinline)) BinaryFunction::BasicBlockOrderType BinaryFunction::dfs() const {
BinaryFunction::BasicBlockOrderType BinaryFunction::dfs() const {
BasicBlockOrderType DFS;
unsigned Index = 0;
std::stack<BinaryBasicBlock *> Stack;

View File

@@ -676,6 +676,7 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
auto Result = MIA->createUncondBranch(Branch,
CondSucc->getLabel(),
BC.Ctx.get());
(void)Result;
assert(Result);
PredBB->addInstruction(Branch);
}
@@ -1324,78 +1325,86 @@ void ReorderFunctions::reorder(std::vector<Cluster> &&Clusters,
}
}
if (opts::ReorderFunctions != BinaryFunction::RT_NONE &&
(opts::Verbosity > 0 ||
(DebugFlag && isCurrentDebugType("hfsort")))) {
uint64_t TotalSize = 0;
uint64_t CurPage = 0;
uint64_t Hotfuncs = 0;
double TotalDistance = 0;
double TotalCalls = 0;
double TotalCalls64B = 0;
double TotalCalls4KB = 0;
double TotalCalls2MB = 0;
dbgs() << "============== page 0 ==============\n";
for (auto& Cluster : Clusters) {
dbgs() <<
format("-------- density = %.3lf (%u / %u) --------\n",
(double) Cluster.Samples / Cluster.Size,
Cluster.Samples, Cluster.Size);
if (opts::ReorderFunctions == BinaryFunction::RT_NONE)
return;
for (auto FuncId : Cluster.Targets) {
if (Cg.Targets[FuncId].Samples > 0) {
Hotfuncs++;
if (opts::Verbosity == 0) {
#ifndef NDEBUG
if (!DebugFlag || !isCurrentDebugType("hfsort"))
return;
#else
return;
#endif
}
dbgs() << "BOLT-INFO: hot func " << *Funcs[FuncId]
<< " (" << Cg.Targets[FuncId].Size << ")\n";
TotalSize = 0;
uint64_t CurPage = 0;
uint64_t Hotfuncs = 0;
double TotalDistance = 0;
double TotalCalls = 0;
double TotalCalls64B = 0;
double TotalCalls4KB = 0;
double TotalCalls2MB = 0;
dbgs() << "============== page 0 ==============\n";
for (auto& Cluster : Clusters) {
dbgs() <<
format("-------- density = %.3lf (%u / %u) --------\n",
(double) Cluster.Samples / Cluster.Size,
Cluster.Samples, Cluster.Size);
uint64_t Dist = 0;
uint64_t Calls = 0;
for (auto Dst : Cg.Targets[FuncId].Succs) {
auto& A = *Cg.Arcs.find(Arc(FuncId, Dst));
auto D =
std::abs(FuncAddr[A.Dst] - (FuncAddr[FuncId] + A.AvgCallOffset));
auto W = A.Weight;
Calls += W;
if (D < 64) TotalCalls64B += W;
if (D < 4096) TotalCalls4KB += W;
if (D < (2 << 20)) TotalCalls2MB += W;
Dist += A.Weight * D;
dbgs() << format("arc: %u [@%lu+%.1lf] -> %u [@%lu]: "
"weight = %.0lf, callDist = %f\n",
A.Src, FuncAddr[A.Src], A.AvgCallOffset,
A.Dst, FuncAddr[A.Dst], A.Weight, D);
}
TotalCalls += Calls;
TotalDistance += Dist;
dbgs() << format("start = %6u : avgCallDist = %lu : %s\n",
TotalSize,
Calls ? Dist / Calls : 0,
Funcs[FuncId]->getPrintName().c_str());
TotalSize += Cg.Targets[FuncId].Size;
auto NewPage = TotalSize / PageSize;
if (NewPage != CurPage) {
CurPage = NewPage;
dbgs() << format("============== page %u ==============\n", CurPage);
}
for (auto FuncId : Cluster.Targets) {
if (Cg.Targets[FuncId].Samples > 0) {
Hotfuncs++;
dbgs() << "BOLT-INFO: hot func " << *Funcs[FuncId]
<< " (" << Cg.Targets[FuncId].Size << ")\n";
uint64_t Dist = 0;
uint64_t Calls = 0;
for (auto Dst : Cg.Targets[FuncId].Succs) {
auto& A = *Cg.Arcs.find(Arc(FuncId, Dst));
auto D =
std::abs(FuncAddr[A.Dst] - (FuncAddr[FuncId] + A.AvgCallOffset));
auto W = A.Weight;
Calls += W;
if (D < 64) TotalCalls64B += W;
if (D < 4096) TotalCalls4KB += W;
if (D < (2 << 20)) TotalCalls2MB += W;
Dist += A.Weight * D;
dbgs() << format("arc: %u [@%lu+%.1lf] -> %u [@%lu]: "
"weight = %.0lf, callDist = %f\n",
A.Src, FuncAddr[A.Src], A.AvgCallOffset,
A.Dst, FuncAddr[A.Dst], A.Weight, D);
}
TotalCalls += Calls;
TotalDistance += Dist;
dbgs() << format("start = %6u : avgCallDist = %lu : %s\n",
TotalSize,
Calls ? Dist / Calls : 0,
Funcs[FuncId]->getPrintName().c_str());
TotalSize += Cg.Targets[FuncId].Size;
auto NewPage = TotalSize / PageSize;
if (NewPage != CurPage) {
CurPage = NewPage;
dbgs() << format("============== page %u ==============\n", CurPage);
}
}
}
dbgs() << format(" Number of hot functions: %u\n"
" Number of clusters: %lu\n",
Hotfuncs, Clusters.size())
<< format(" Final average call distance = %.1lf (%.0lf / %.0lf)\n",
TotalCalls ? TotalDistance / TotalCalls : 0,
TotalDistance, TotalCalls)
<< format(" Total Calls = %.0lf\n", TotalCalls);
if (TotalCalls) {
dbgs() << format(" Total Calls within 64B = %.0lf (%.2lf%%)\n",
TotalCalls64B, 100 * TotalCalls64B / TotalCalls)
<< format(" Total Calls within 4KB = %.0lf (%.2lf%%)\n",
TotalCalls4KB, 100 * TotalCalls4KB / TotalCalls)
<< format(" Total Calls within 2MB = %.0lf (%.2lf%%)\n",
TotalCalls2MB, 100 * TotalCalls2MB / TotalCalls);
}
}
dbgs() << format(" Number of hot functions: %u\n"
" Number of clusters: %lu\n",
Hotfuncs, Clusters.size())
<< format(" Final average call distance = %.1lf (%.0lf / %.0lf)\n",
TotalCalls ? TotalDistance / TotalCalls : 0,
TotalDistance, TotalCalls)
<< format(" Total Calls = %.0lf\n", TotalCalls);
if (TotalCalls) {
dbgs() << format(" Total Calls within 64B = %.0lf (%.2lf%%)\n",
TotalCalls64B, 100 * TotalCalls64B / TotalCalls)
<< format(" Total Calls within 4KB = %.0lf (%.2lf%%)\n",
TotalCalls4KB, 100 * TotalCalls4KB / TotalCalls)
<< format(" Total Calls within 2MB = %.0lf (%.2lf%%)\n",
TotalCalls2MB, 100 * TotalCalls2MB / TotalCalls);
}
}

View File

@@ -419,8 +419,14 @@ void FrameAnalysis::buildClobberMap(const BinaryContext &BC) {
RegsKilledMap[Func] = std::move(RegsKilled);
}
if (opts::Verbosity == 0 && (!DebugFlag || !isCurrentDebugType("fa")))
if (opts::Verbosity == 0) {
#ifndef NDEBUG
if (!DebugFlag || !isCurrentDebugType("fa"))
return;
#else
return;
#endif
}
// This loop is for computing statistics only
for (auto *Func : TopologicalCGOrder) {
@@ -433,17 +439,16 @@ void FrameAnalysis::buildClobberMap(const BinaryContext &BC) {
CountFunctionsAllClobber += Count;
++NumFunctionsAllClobber;
}
if (!DebugFlag || !isCurrentDebugType("fa"))
continue;
// DEBUG only
dbgs() << "Killed regs set for func: " << Func->getPrintName() << "\n";
const BitVector &RegsKilled = Iter->second;
int RegIdx = RegsKilled.find_first();
while (RegIdx != -1) {
dbgs() << "\tREG" << RegIdx;
RegIdx = RegsKilled.find_next(RegIdx);
};
dbgs() << "\n";
DEBUG_WITH_TYPE("fa",
dbgs() << "Killed regs set for func: " << Func->getPrintName() << "\n";
const BitVector &RegsKilled = Iter->second;
int RegIdx = RegsKilled.find_first();
while (RegIdx != -1) {
dbgs() << "\tREG" << RegIdx;
RegIdx = RegsKilled.find_next(RegIdx);
};
dbgs() << "\n";
);
}
}

View File

@@ -168,8 +168,14 @@ void FrameOptimizerPass::buildClobberMap(const BinaryContext &BC) {
RegsKilledMap[Func] = std::move(RegsKilled);
}
if (opts::Verbosity == 0 && (!DebugFlag || !isCurrentDebugType("fop")))
if (opts::Verbosity == 0) {
#ifndef NDEBUG
if (!DebugFlag || !isCurrentDebugType("fop"))
return;
#else
return;
#endif
}
// This loop is for computing statistics only
for (auto *Func : TopologicalCGOrder) {
@@ -182,17 +188,16 @@ void FrameOptimizerPass::buildClobberMap(const BinaryContext &BC) {
CountFunctionsAllClobber += Count;
++NumFunctionsAllClobber;
}
if (!DebugFlag || !isCurrentDebugType("fop"))
continue;
// DEBUG only
dbgs() << "Killed regs set for func: " << Func->getPrintName() << "\n";
const BitVector &RegsKilled = Iter->second;
int RegIdx = RegsKilled.find_first();
while (RegIdx != -1) {
dbgs() << "\tREG" << RegIdx;
RegIdx = RegsKilled.find_next(RegIdx);
};
dbgs() << "\n";
DEBUG_WITH_TYPE("fop",
dbgs() << "Killed regs set for func: " << Func->getPrintName() << "\n";
const BitVector &RegsKilled = Iter->second;
int RegIdx = RegsKilled.find_first();
while (RegIdx != -1) {
dbgs() << "\tREG" << RegIdx;
RegIdx = RegsKilled.find_next(RegIdx);
};
dbgs() << "\n";
);
}
}
@@ -665,18 +670,17 @@ bool FrameOptimizerPass::restoreFrameIndex(const BinaryContext &BC,
CfaOffset + StackOffset, Size, IsSimple});
}
if (!DebugFlag || !isCurrentDebugType("fop"))
continue;
// DEBUG only
dbgs() << "Frame index annotation added to:\n";
BC.printInstruction(dbgs(), Inst, 0, &BF, true);
dbgs() << " FrameIndexEntry <IsLoad:" << IsLoad << " StackOffset:";
if (FrameIndexMap[&Inst].StackOffset < 0)
dbgs() << "-" << Twine::utohexstr(-FrameIndexMap[&Inst].StackOffset);
else
dbgs() << "+" << Twine::utohexstr(FrameIndexMap[&Inst].StackOffset);
dbgs() << " IsStoreFromReg:" << FrameIndexMap[&Inst].IsStoreFromReg
<< " RegOrImm:" << FrameIndexMap[&Inst].RegOrImm << ">\n";
DEBUG_WITH_TYPE("fop",
dbgs() << "Frame index annotation added to:\n";
BC.printInstruction(dbgs(), Inst, 0, &BF, true);
dbgs() << " FrameIndexEntry <IsLoad:" << IsLoad << " StackOffset:";
if (FrameIndexMap[&Inst].StackOffset < 0)
dbgs() << "-" << Twine::utohexstr(-FrameIndexMap[&Inst].StackOffset);
else
dbgs() << "+" << Twine::utohexstr(FrameIndexMap[&Inst].StackOffset);
dbgs() << " IsStoreFromReg:" << FrameIndexMap[&Inst].IsStoreFromReg
<< " RegOrImm:" << FrameIndexMap[&Inst].RegOrImm << ">\n";
);
}
}
}
@@ -816,8 +820,14 @@ void FrameOptimizerPass::runOnFunctions(BinaryContext &BC,
outs() << "BOLT-INFO: FOP optimized " << NumRedundantLoads
<< " redundant load(s).\n";
if (opts::Verbosity == 0 && (!DebugFlag || !isCurrentDebugType("fop")))
if (opts::Verbosity == 0) {
#ifndef NDEBUG
if (!DebugFlag || !isCurrentDebugType("fop"))
return;
#else
return;
#endif
}
outs() << "BOLT-INFO: FOP changed " << NumLoadsChangedToReg
<< " load(s) to use a register instead of a stack access, and "

View File

@@ -249,6 +249,7 @@ InlineSmallFunctions::inlineCall(
const bool Result = BC.MIA->analyzeBranch(Instruction, OldTargetLabel,
OldFTLabel, CondBranch,
UncondBranch);
(void)Result;
assert(Result &&
"analyzeBranch failed on instruction guaranteed to be a branch");
assert(OldTargetLabel);

View File

@@ -2552,7 +2552,9 @@ void RewriteInstance::patchELFPHDRTable() {
OS.seek(PHDRTableOffset);
bool ModdedGnuStack = false;
(void)ModdedGnuStack;
bool AddedSegment = false;
(void)AddedSegment;
// Copy existing program headers with modifications.
for (auto &Phdr : Obj->program_headers()) {
@@ -3244,6 +3246,7 @@ void RewriteInstance::rewriteFile() {
// Make sure output stream has enough reserved space, otherwise
// pwrite() will fail.
auto Offset = OS.seek(getFileOffsetForAddress(NextAvailableAddress));
(void)Offset;
assert(Offset == getFileOffsetForAddress(NextAvailableAddress) &&
"error resizing output file");