Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/BinaryFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class BinaryFunction {
/// Annotate each basic block entry with its current CFI state. This is
/// run right after the construction of CFG while basic blocks are in their
/// original order.
void annotateCFIState();
bool annotateCFIState();

/// Associate DW_CFA_GNU_args_size info with invoke instructions
/// (call instructions with non-empty landing pad).
Expand Down
21 changes: 17 additions & 4 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,13 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
recomputeLandingPads();

// Assign CFI information to each BB entry.
annotateCFIState();
bool SuccessfulAnnotation = annotateCFIState();
if (!SuccessfulAnnotation) {
BC.errs() << "BOLT-WARNING: failed to annotate CFI state for "
<< this->getPrintName() << "\n";
setIgnored();
return createNonFatalBOLTError("");
}

// Annotate invoke instructions with GNU_args_size data.
propagateGnuArgsSizeInfo(AllocatorId);
Expand All @@ -2443,7 +2449,11 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {

Layout.updateLayoutIndices();

normalizeCFIState();
if (SuccessfulAnnotation)
normalizeCFIState();
else
BC.errs() << "BOLT-WARNING: cannot normalize CFI State for "
<< this->getPrintName() << "\n";

// Clean-up memory taken by intermediate structures.
//
Expand Down Expand Up @@ -2618,7 +2628,7 @@ uint64_t BinaryFunction::getFunctionScore() const {
return FunctionScore;
}

void BinaryFunction::annotateCFIState() {
bool BinaryFunction::annotateCFIState() {
assert(CurrentState == State::Disassembled && "unexpected function state");
assert(!BasicBlocks.empty() && "basic block list should not be empty");

Expand Down Expand Up @@ -2654,7 +2664,9 @@ void BinaryFunction::annotateCFIState() {
EffectiveState = State;
break;
case MCCFIInstruction::OpRestoreState:
assert(!StateStack.empty() && "corrupt CFI stack");
if (StateStack.empty()) {
return false;
}
EffectiveState = StateStack.top();
StateStack.pop();
break;
Expand All @@ -2673,6 +2685,7 @@ void BinaryFunction::annotateCFIState() {
BC.errs() << "BOLT-WARNING: non-empty CFI stack at the end of " << *this
<< '\n';
}
return StateStack.empty();
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/ADRRelaxationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace bolt {
static bool PassFailed = false;

void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
if (PassFailed)
if (PassFailed || BF.isIgnored())
return;

BinaryContext &BC = BF.getBinaryContext();
Expand Down
8 changes: 7 additions & 1 deletion bolt/lib/Passes/Aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace bolt {
// Align function to the specified byte-boundary (typically, 64) offsetting
// the fuction by not more than the corresponding value
static void alignMaxBytes(BinaryFunction &Function) {
if (Function.isIgnored())
return;
Function.setAlignment(opts::AlignFunctions);
Function.setMaxAlignmentBytes(opts::AlignFunctionsMaxBytes);
Function.setMaxColdAlignmentBytes(opts::AlignFunctionsMaxBytes);
Expand All @@ -73,6 +75,9 @@ static void alignMaxBytes(BinaryFunction &Function) {
// -- the specified number of bytes
static void alignCompact(BinaryFunction &Function,
const MCCodeEmitter *Emitter) {

if (Function.isIgnored())
return;
const BinaryContext &BC = Function.getBinaryContext();
size_t HotSize = 0;
size_t ColdSize = 0;
Expand All @@ -97,7 +102,8 @@ static void alignCompact(BinaryFunction &Function,

void AlignerPass::alignBlocks(BinaryFunction &Function,
const MCCodeEmitter *Emitter) {
if (!Function.hasValidProfile() || !Function.isSimple())
if (Function.isIgnored() || !Function.hasValidProfile() ||
!Function.isSimple())
return;

const BinaryContext &BC = Function.getBinaryContext();
Expand Down
10 changes: 8 additions & 2 deletions bolt/lib/Passes/BinaryPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,10 +1810,14 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
}

Error InstructionLowering::runOnFunctions(BinaryContext &BC) {
for (auto &BFI : BC.getBinaryFunctions())
for (BinaryBasicBlock &BB : BFI.second)
for (auto &BFI : BC.getBinaryFunctions()) {
BinaryFunction &BF = BFI.second;
if (BF.isIgnored())
continue;
for (BinaryBasicBlock &BB : BF)
for (MCInst &Instruction : BB)
BC.MIB->lowerTailCall(Instruction);
}
return Error::success();
}

Expand Down Expand Up @@ -2029,6 +2033,8 @@ Error SpecializeMemcpy1::runOnFunctions(BinaryContext &BC) {
}

void RemoveNops::runOnFunction(BinaryFunction &BF) {
if (BF.isIgnored())
return;
const BinaryContext &BC = BF.getBinaryContext();
for (BinaryBasicBlock &BB : BF) {
for (int64_t I = BB.size() - 1; I >= 0; --I) {
Expand Down
2 changes: 2 additions & 0 deletions bolt/lib/Passes/FixRelaxationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace bolt {
// target of ADD is another symbol. When found change ADRP symbol reference to
// the ADDs one.
void FixRelaxations::runOnFunction(BinaryFunction &BF) {
if (BF.isIgnored())
return;
BinaryContext &BC = BF.getBinaryContext();
for (BinaryBasicBlock &BB : BF) {
for (auto II = BB.begin(); II != BB.end(); ++II) {
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/Instrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool Instrumentation::instrumentOneTarget(

void Instrumentation::instrumentFunction(BinaryFunction &Function,
MCPlusBuilder::AllocatorIdTy AllocId) {
if (Function.hasUnknownControlFlow())
if (Function.hasUnknownControlFlow() || Function.isIgnored())
return;

BinaryContext &BC = Function.getBinaryContext();
Expand Down
4 changes: 4 additions & 0 deletions bolt/lib/Passes/LongJmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ Error LongJmpPass::relax(BinaryFunction &Func, bool &Modified) {
const BinaryContext &BC = Func.getBinaryContext();

assert(BC.isAArch64() && "Unsupported arch");

if (Func.isIgnored())
return Error::success();

constexpr int InsnSize = 4; // AArch64
std::vector<std::pair<BinaryBasicBlock *, std::unique_ptr<BinaryBasicBlock>>>
Insertions;
Expand Down
2 changes: 2 additions & 0 deletions bolt/lib/Passes/MCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ void equalizeBBCounts(DataflowInfoManager &Info, BinaryFunction &BF) {
}

void EstimateEdgeCounts::runOnFunction(BinaryFunction &BF) {
if (BF.isIgnored())
return;
EdgeWeightMap PredEdgeWeights;
EdgeWeightMap SuccEdgeWeights;
if (!opts::IterativeGuess) {
Expand Down
2 changes: 2 additions & 0 deletions bolt/lib/Passes/ValidateInternalCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ Error ValidateInternalCalls::runOnFunctions(BinaryContext &BC) {
std::set<BinaryFunction *> NeedsValidation;
for (auto &BFI : BC.getBinaryFunctions()) {
BinaryFunction &Function = BFI.second;
if (Function.isIgnored())
continue;
for (BinaryBasicBlock &BB : Function) {
for (MCInst &Inst : BB) {
if (getInternalCallTarget(Function, Inst)) {
Expand Down
7 changes: 3 additions & 4 deletions bolt/lib/Passes/VeneerElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ Error VeneerElimination::runOnFunctions(BinaryContext &BC) {
std::unordered_map<const MCSymbol *, const MCSymbol *> VeneerDestinations;
uint64_t NumEliminatedVeneers = 0;
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
if (!isPossibleVeneer(BF))
continue;

if (BF.isIgnored())
if (BF.isIgnored() || !isPossibleVeneer(BF))
continue;

MCInst &FirstInstruction = *(BF.begin()->begin());
Expand Down Expand Up @@ -84,6 +81,8 @@ Error VeneerElimination::runOnFunctions(BinaryContext &BC) {

uint64_t VeneerCallers = 0;
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
if (BF.isIgnored())
continue;
for (BinaryBasicBlock &BB : BF) {
for (MCInst &Instr : BB) {
if (!BC.MIB->isCall(Instr) || BC.MIB->isIndirectCall(Instr))
Expand Down
3 changes: 3 additions & 0 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,9 @@ void RewriteInstance::postProcessFunctions() {
if (Function.empty())
continue;

if (Function.isIgnored())
continue;

Function.postProcessCFG();

if (opts::PrintAll || opts::PrintCFG)
Expand Down
Loading