forked from OSchip/llvm-project
run finalize functions in parallel
Summary: (cherry picked from FBD16188733)
This commit is contained in:
parent
98539b0966
commit
f4ab6e6924
|
@ -2560,7 +2560,7 @@ bool BinaryFunction::finalizeCFIState() {
|
|||
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
|
||||
<< ": ");
|
||||
|
||||
|
||||
int32_t State = 0;
|
||||
bool SeenCold = false;
|
||||
auto Sep = "";
|
||||
|
|
|
@ -1088,6 +1088,7 @@ public:
|
|||
MCSymbol *getFunctionEndLabel() const {
|
||||
assert(BC.Ctx && "cannot be called with empty context");
|
||||
if (!FunctionEndLabel) {
|
||||
std::unique_lock<std::shared_timed_mutex> Lock(BC.CtxMutex);
|
||||
FunctionEndLabel = BC.Ctx->createTempSymbol("func_end", true);
|
||||
}
|
||||
return FunctionEndLabel;
|
||||
|
@ -1096,6 +1097,7 @@ public:
|
|||
/// Return MC symbol associated with the end of the cold part of the function.
|
||||
MCSymbol *getFunctionColdEndLabel() const {
|
||||
if (!FunctionColdEndLabel) {
|
||||
std::unique_lock<std::shared_timed_mutex> Lock(BC.CtxMutex);
|
||||
FunctionColdEndLabel = BC.Ctx->createTempSymbol("func_cold_end", true);
|
||||
}
|
||||
return FunctionColdEndLabel;
|
||||
|
|
|
@ -364,7 +364,7 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
|
|||
void BinaryFunction::updateEHRanges() {
|
||||
if (getSize() == 0)
|
||||
return;
|
||||
|
||||
|
||||
assert(CurrentState == State::CFG_Finalized && "unexpected state");
|
||||
|
||||
// Build call sites table.
|
||||
|
@ -430,9 +430,14 @@ void BinaryFunction::updateEHRanges() {
|
|||
continue;
|
||||
|
||||
// Same symbol is used for the beginning and the end of the range.
|
||||
const MCSymbol *EHSymbol = BC.Ctx->createTempSymbol("EH", true);
|
||||
const MCSymbol *EHSymbol;
|
||||
MCInst EHLabel;
|
||||
BC.MIB->createEHLabel(EHLabel, EHSymbol, BC.Ctx.get());
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex> Lock(BC.CtxMutex);
|
||||
EHSymbol = BC.Ctx->createTempSymbol("EH", true);
|
||||
BC.MIB->createEHLabel(EHLabel, EHSymbol, BC.Ctx.get());
|
||||
}
|
||||
|
||||
II = std::next(BB->insertPseudoInstr(II, EHLabel));
|
||||
|
||||
// At this point we could be in one of the following states:
|
||||
|
|
|
@ -588,30 +588,30 @@ void FixupBranches::runOnFunctions(BinaryContext &BC) {
|
|||
}
|
||||
|
||||
void FinalizeFunctions::runOnFunctions(BinaryContext &BC) {
|
||||
for (auto &It : BC.getBinaryFunctions()) {
|
||||
auto &Function = It.second;
|
||||
const auto ShouldOptimize = shouldOptimize(Function);
|
||||
|
||||
// Always fix functions in relocation mode.
|
||||
if (!BC.HasRelocations && !ShouldOptimize)
|
||||
continue;
|
||||
|
||||
// Fix the CFI state.
|
||||
if (ShouldOptimize && !Function.finalizeCFIState()) {
|
||||
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
|
||||
if (shouldOptimize(BF) && !BF.finalizeCFIState()) {
|
||||
if (BC.HasRelocations) {
|
||||
errs() << "BOLT-ERROR: unable to fix CFI state for function "
|
||||
<< Function << ". Exiting.\n";
|
||||
errs() << "BOLT-ERROR: unable to fix CFI state for function " << BF
|
||||
<< ". Exiting.\n";
|
||||
exit(1);
|
||||
}
|
||||
Function.setSimple(false);
|
||||
continue;
|
||||
BF.setSimple(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Function.setFinalized();
|
||||
BF.setFinalized();
|
||||
|
||||
// Update exception handling information.
|
||||
Function.updateEHRanges();
|
||||
}
|
||||
BF.updateEHRanges();
|
||||
};
|
||||
|
||||
ParallelUtilities::PredicateTy SkipPredicate = [&](const BinaryFunction &BF) {
|
||||
return !BC.HasRelocations && !shouldOptimize(BF);
|
||||
};
|
||||
|
||||
ParallelUtilities::runOnEachFunction(
|
||||
BC, ParallelUtilities::SchedulingPolicy::SP_CONSTANT, WorkFun,
|
||||
SkipPredicate, "FinalizeFunctions");
|
||||
}
|
||||
|
||||
void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
|
||||
|
|
Loading…
Reference in New Issue