Skip to content

Commit a5f3d1a

Browse files
authored
[BOLT][NFC] Return Error from BinaryFunctionPass::runOnFunctions (#81521)
As part of the effort to refactor old error handling code that would directly call exit(1), in this patch we change the interface to `BinaryFunctionPass` to return an Error on `runOnFunctions()`. This gives passes the ability to report a serious problem to the caller (RewriteInstance class), so the caller may decide how to best handle the exceptional situation. Co-authored-by: Rafael Auler <[email protected]> Test Plan: NFC
1 parent 283feb4 commit a5f3d1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+196
-143
lines changed

Diff for: bolt/include/bolt/Passes/ADRRelaxationPass.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ADRRelaxationPass : public BinaryFunctionPass {
3030
const char *getName() const override { return "adr-relaxation"; }
3131

3232
/// Pass entry point
33-
void runOnFunctions(BinaryContext &BC) override;
33+
Error runOnFunctions(BinaryContext &BC) override;
3434
void runOnFunction(BinaryFunction &BF);
3535
};
3636

Diff for: bolt/include/bolt/Passes/Aligner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AlignerPass : public BinaryFunctionPass {
3939
const char *getName() const override { return "aligner"; }
4040

4141
/// Pass entry point
42-
void runOnFunctions(BinaryContext &BC) override;
42+
Error runOnFunctions(BinaryContext &BC) override;
4343
};
4444

4545
} // namespace bolt

Diff for: bolt/include/bolt/Passes/AllocCombiner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AllocCombinerPass : public BinaryFunctionPass {
3333
}
3434

3535
/// Pass entry point
36-
void runOnFunctions(BinaryContext &BC) override;
36+
Error runOnFunctions(BinaryContext &BC) override;
3737
};
3838

3939
} // namespace bolt

Diff for: bolt/include/bolt/Passes/AsmDump.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AsmDumpPass : public BinaryFunctionPass {
2828
bool shouldPrint(const BinaryFunction &BF) const override { return false; }
2929

3030
/// Pass entry point
31-
void runOnFunctions(BinaryContext &BC) override;
31+
Error runOnFunctions(BinaryContext &BC) override;
3232
};
3333

3434
} // namespace bolt

Diff for: bolt/include/bolt/Passes/BinaryPasses.h

+23-22
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class BinaryFunctionPass {
5151
virtual bool shouldPrint(const BinaryFunction &BF) const;
5252

5353
/// Execute this pass on the given functions.
54-
virtual void runOnFunctions(BinaryContext &BC) = 0;
54+
virtual Error runOnFunctions(BinaryContext &BC) = 0;
5555
};
5656

5757
/// A pass to print program-wide dynostats.
@@ -70,7 +70,7 @@ class DynoStatsPrintPass : public BinaryFunctionPass {
7070

7171
bool shouldPrint(const BinaryFunction &BF) const override { return false; }
7272

73-
void runOnFunctions(BinaryContext &BC) override {
73+
Error runOnFunctions(BinaryContext &BC) override {
7474
const DynoStats NewDynoStats =
7575
getDynoStats(BC.getBinaryFunctions(), BC.isAArch64());
7676
const bool Changed = (NewDynoStats != PrevDynoStats);
@@ -82,6 +82,7 @@ class DynoStatsPrintPass : public BinaryFunctionPass {
8282
NewDynoStats.print(outs(), &PrevDynoStats, BC.InstPrinter.get());
8383
}
8484
outs() << '\n';
85+
return Error::success();
8586
}
8687
};
8788

@@ -100,7 +101,7 @@ class NormalizeCFG : public BinaryFunctionPass {
100101

101102
const char *getName() const override { return "normalize CFG"; }
102103

103-
void runOnFunctions(BinaryContext &) override;
104+
Error runOnFunctions(BinaryContext &) override;
104105
};
105106

106107
/// Detect and eliminate unreachable basic blocks. We could have those
@@ -119,7 +120,7 @@ class EliminateUnreachableBlocks : public BinaryFunctionPass {
119120
bool shouldPrint(const BinaryFunction &BF) const override {
120121
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
121122
}
122-
void runOnFunctions(BinaryContext &) override;
123+
Error runOnFunctions(BinaryContext &) override;
123124
};
124125

125126
// Reorder the basic blocks for each function based on hotness.
@@ -165,7 +166,7 @@ class ReorderBasicBlocks : public BinaryFunctionPass {
165166

166167
const char *getName() const override { return "reorder-blocks"; }
167168
bool shouldPrint(const BinaryFunction &BF) const override;
168-
void runOnFunctions(BinaryContext &BC) override;
169+
Error runOnFunctions(BinaryContext &BC) override;
169170
};
170171

171172
/// Sync local branches with CFG.
@@ -175,7 +176,7 @@ class FixupBranches : public BinaryFunctionPass {
175176
: BinaryFunctionPass(PrintPass) {}
176177

177178
const char *getName() const override { return "fix-branches"; }
178-
void runOnFunctions(BinaryContext &BC) override;
179+
Error runOnFunctions(BinaryContext &BC) override;
179180
};
180181

181182
/// Fix the CFI state and exception handling information after all other
@@ -186,7 +187,7 @@ class FinalizeFunctions : public BinaryFunctionPass {
186187
: BinaryFunctionPass(PrintPass) {}
187188

188189
const char *getName() const override { return "finalize-functions"; }
189-
void runOnFunctions(BinaryContext &BC) override;
190+
Error runOnFunctions(BinaryContext &BC) override;
190191
};
191192

192193
/// Perform any necessary adjustments for functions that do not fit into their
@@ -198,7 +199,7 @@ class CheckLargeFunctions : public BinaryFunctionPass {
198199

199200
const char *getName() const override { return "check-large-functions"; }
200201

201-
void runOnFunctions(BinaryContext &BC) override;
202+
Error runOnFunctions(BinaryContext &BC) override;
202203

203204
bool shouldOptimize(const BinaryFunction &BF) const override;
204205
};
@@ -210,7 +211,7 @@ class LowerAnnotations : public BinaryFunctionPass {
210211
: BinaryFunctionPass(PrintPass) {}
211212

212213
const char *getName() const override { return "lower-annotations"; }
213-
void runOnFunctions(BinaryContext &BC) override;
214+
Error runOnFunctions(BinaryContext &BC) override;
214215
};
215216

216217
/// Clean the state of the MC representation before sending it to emission
@@ -220,7 +221,7 @@ class CleanMCState : public BinaryFunctionPass {
220221
: BinaryFunctionPass(PrintPass) {}
221222

222223
const char *getName() const override { return "clean-mc-state"; }
223-
void runOnFunctions(BinaryContext &BC) override;
224+
Error runOnFunctions(BinaryContext &BC) override;
224225
};
225226

226227
/// An optimization to simplify conditional tail calls by removing
@@ -292,7 +293,7 @@ class SimplifyConditionalTailCalls : public BinaryFunctionPass {
292293
bool shouldPrint(const BinaryFunction &BF) const override {
293294
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
294295
}
295-
void runOnFunctions(BinaryContext &BC) override;
296+
Error runOnFunctions(BinaryContext &BC) override;
296297
};
297298

298299
/// Convert instructions to the form with the minimum operand width.
@@ -305,7 +306,7 @@ class ShortenInstructions : public BinaryFunctionPass {
305306

306307
const char *getName() const override { return "shorten-instructions"; }
307308

308-
void runOnFunctions(BinaryContext &BC) override;
309+
Error runOnFunctions(BinaryContext &BC) override;
309310
};
310311

311312
/// Perform simple peephole optimizations.
@@ -339,7 +340,7 @@ class Peepholes : public BinaryFunctionPass {
339340
: BinaryFunctionPass(PrintPass) {}
340341

341342
const char *getName() const override { return "peepholes"; }
342-
void runOnFunctions(BinaryContext &BC) override;
343+
Error runOnFunctions(BinaryContext &BC) override;
343344
};
344345

345346
/// An optimization to simplify loads from read-only sections.The pass converts
@@ -370,7 +371,7 @@ class SimplifyRODataLoads : public BinaryFunctionPass {
370371
bool shouldPrint(const BinaryFunction &BF) const override {
371372
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
372373
}
373-
void runOnFunctions(BinaryContext &BC) override;
374+
Error runOnFunctions(BinaryContext &BC) override;
374375
};
375376

376377
/// Assign output sections to all functions.
@@ -379,7 +380,7 @@ class AssignSections : public BinaryFunctionPass {
379380
explicit AssignSections() : BinaryFunctionPass(false) {}
380381

381382
const char *getName() const override { return "assign-sections"; }
382-
void runOnFunctions(BinaryContext &BC) override;
383+
Error runOnFunctions(BinaryContext &BC) override;
383384
};
384385

385386
/// Compute and report to the user the imbalance in flow equations for all
@@ -394,7 +395,7 @@ class PrintProfileStats : public BinaryFunctionPass {
394395

395396
const char *getName() const override { return "profile-stats"; }
396397
bool shouldPrint(const BinaryFunction &) const override { return false; }
397-
void runOnFunctions(BinaryContext &BC) override;
398+
Error runOnFunctions(BinaryContext &BC) override;
398399
};
399400

400401
/// Prints a list of the top 100 functions sorted by a set of
@@ -406,7 +407,7 @@ class PrintProgramStats : public BinaryFunctionPass {
406407

407408
const char *getName() const override { return "print-stats"; }
408409
bool shouldPrint(const BinaryFunction &) const override { return false; }
409-
void runOnFunctions(BinaryContext &BC) override;
410+
Error runOnFunctions(BinaryContext &BC) override;
410411
};
411412

412413
/// Pass for lowering any instructions that we have raised and that have
@@ -418,7 +419,7 @@ class InstructionLowering : public BinaryFunctionPass {
418419

419420
const char *getName() const override { return "inst-lowering"; }
420421

421-
void runOnFunctions(BinaryContext &BC) override;
422+
Error runOnFunctions(BinaryContext &BC) override;
422423
};
423424

424425
/// Pass for stripping 'repz' from 'repz retq' sequence of instructions.
@@ -429,7 +430,7 @@ class StripRepRet : public BinaryFunctionPass {
429430

430431
const char *getName() const override { return "strip-rep-ret"; }
431432

432-
void runOnFunctions(BinaryContext &BC) override;
433+
Error runOnFunctions(BinaryContext &BC) override;
433434
};
434435

435436
/// Pass for inlining calls to memcpy using 'rep movsb' on X86.
@@ -440,7 +441,7 @@ class InlineMemcpy : public BinaryFunctionPass {
440441

441442
const char *getName() const override { return "inline-memcpy"; }
442443

443-
void runOnFunctions(BinaryContext &BC) override;
444+
Error runOnFunctions(BinaryContext &BC) override;
444445
};
445446

446447
/// Pass for specializing memcpy for a size of 1 byte.
@@ -461,7 +462,7 @@ class SpecializeMemcpy1 : public BinaryFunctionPass {
461462

462463
const char *getName() const override { return "specialize-memcpy"; }
463464

464-
void runOnFunctions(BinaryContext &BC) override;
465+
Error runOnFunctions(BinaryContext &BC) override;
465466
};
466467

467468
/// Pass to remove nops in code
@@ -475,7 +476,7 @@ class RemoveNops : public BinaryFunctionPass {
475476
const char *getName() const override { return "remove-nops"; }
476477

477478
/// Pass entry point
478-
void runOnFunctions(BinaryContext &BC) override;
479+
Error runOnFunctions(BinaryContext &BC) override;
479480
};
480481

481482
enum FrameOptimizationType : char {

Diff for: bolt/include/bolt/Passes/CMOVConversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CMOVConversion : public BinaryFunctionPass {
7676

7777
const char *getName() const override { return "CMOV conversion"; }
7878

79-
void runOnFunctions(BinaryContext &BC) override;
79+
Error runOnFunctions(BinaryContext &BC) override;
8080
};
8181

8282
} // namespace bolt

Diff for: bolt/include/bolt/Passes/FixRISCVCallsPass.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FixRISCVCallsPass : public BinaryFunctionPass {
3333
const char *getName() const override { return "fix-riscv-calls"; }
3434

3535
/// Pass entry point
36-
void runOnFunctions(BinaryContext &BC) override;
36+
Error runOnFunctions(BinaryContext &BC) override;
3737
};
3838

3939
} // namespace bolt

Diff for: bolt/include/bolt/Passes/FixRelaxationPass.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FixRelaxations : public BinaryFunctionPass {
3131
const char *getName() const override { return "fix-relaxations"; }
3232

3333
/// Pass entry point
34-
void runOnFunctions(BinaryContext &BC) override;
34+
Error runOnFunctions(BinaryContext &BC) override;
3535
};
3636

3737
} // namespace bolt

Diff for: bolt/include/bolt/Passes/FrameOptimizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class FrameOptimizerPass : public BinaryFunctionPass {
108108
const char *getName() const override { return "frame-optimizer"; }
109109

110110
/// Pass entry point
111-
void runOnFunctions(BinaryContext &BC) override;
111+
Error runOnFunctions(BinaryContext &BC) override;
112112

113113
bool shouldPrint(const BinaryFunction &BF) const override {
114114
return BinaryFunctionPass::shouldPrint(BF) && FuncsChanged.count(&BF) > 0;

Diff for: bolt/include/bolt/Passes/Hugify.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HugePage : public BinaryFunctionPass {
1818
public:
1919
HugePage(const cl::opt<bool> &PrintPass) : BinaryFunctionPass(PrintPass) {}
2020

21-
void runOnFunctions(BinaryContext &BC) override;
21+
Error runOnFunctions(BinaryContext &BC) override;
2222

2323
const char *getName() const override { return "HugePage"; }
2424
};

Diff for: bolt/include/bolt/Passes/IdenticalCodeFolding.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IdenticalCodeFolding : public BinaryFunctionPass {
3535
: BinaryFunctionPass(PrintPass) {}
3636

3737
const char *getName() const override { return "identical-code-folding"; }
38-
void runOnFunctions(BinaryContext &BC) override;
38+
Error runOnFunctions(BinaryContext &BC) override;
3939
};
4040

4141
} // namespace bolt

Diff for: bolt/include/bolt/Passes/IndirectCallPromotion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class IndirectCallPromotion : public BinaryFunctionPass {
221221
return BF.isSimple() && !BF.isIgnored() && BF.hasProfile() &&
222222
!BF.hasUnknownControlFlow();
223223
}
224-
void runOnFunctions(BinaryContext &BC) override;
224+
Error runOnFunctions(BinaryContext &BC) override;
225225
};
226226

227227
} // namespace bolt

Diff for: bolt/include/bolt/Passes/Inliner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Inliner : public BinaryFunctionPass {
8686
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
8787
}
8888

89-
void runOnFunctions(BinaryContext &BC) override;
89+
Error runOnFunctions(BinaryContext &BC) override;
9090
};
9191

9292
} // namespace bolt

Diff for: bolt/include/bolt/Passes/Instrumentation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Instrumentation : public BinaryFunctionPass {
3131
Summary(std::make_unique<InstrumentationSummary>()) {}
3232

3333
/// Modifies all functions by inserting instrumentation code (first step)
34-
void runOnFunctions(BinaryContext &BC) override;
34+
Error runOnFunctions(BinaryContext &BC) override;
3535

3636
const char *getName() const override { return "instrumentation"; }
3737

Diff for: bolt/include/bolt/Passes/JTFootprintReduction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class JTFootprintReduction : public BinaryFunctionPass {
6868
bool shouldPrint(const BinaryFunction &BF) const override {
6969
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
7070
}
71-
void runOnFunctions(BinaryContext &BC) override;
71+
Error runOnFunctions(BinaryContext &BC) override;
7272
};
7373

7474
} // namespace bolt

Diff for: bolt/include/bolt/Passes/LongJmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class LongJmpPass : public BinaryFunctionPass {
148148

149149
const char *getName() const override { return "long-jmp"; }
150150

151-
void runOnFunctions(BinaryContext &BC) override;
151+
Error runOnFunctions(BinaryContext &BC) override;
152152
};
153153
} // namespace bolt
154154
} // namespace llvm

Diff for: bolt/include/bolt/Passes/LoopInversionPass.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LoopInversionPass : public BinaryFunctionPass {
4949
const char *getName() const override { return "loop-inversion-opt"; }
5050

5151
/// Pass entry point
52-
void runOnFunctions(BinaryContext &BC) override;
52+
Error runOnFunctions(BinaryContext &BC) override;
5353
bool runOnFunction(BinaryFunction &Function);
5454
};
5555

Diff for: bolt/include/bolt/Passes/PLTCall.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PLTCall : public BinaryFunctionPass {
3030
bool shouldPrint(const BinaryFunction &BF) const override {
3131
return BinaryFunctionPass::shouldPrint(BF);
3232
}
33-
void runOnFunctions(BinaryContext &BC) override;
33+
Error runOnFunctions(BinaryContext &BC) override;
3434
};
3535

3636
} // namespace bolt

Diff for: bolt/include/bolt/Passes/PatchEntries.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PatchEntries : public BinaryFunctionPass {
3434
explicit PatchEntries() : BinaryFunctionPass(false) {}
3535

3636
const char *getName() const override { return "patch-entries"; }
37-
void runOnFunctions(BinaryContext &BC) override;
37+
Error runOnFunctions(BinaryContext &BC) override;
3838
};
3939

4040
} // namespace bolt

Diff for: bolt/include/bolt/Passes/RegReAssign.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class RegReAssign : public BinaryFunctionPass {
5555
return BinaryFunctionPass::shouldPrint(BF) && FuncsChanged.count(&BF) > 0;
5656
}
5757

58-
void runOnFunctions(BinaryContext &BC) override;
58+
Error runOnFunctions(BinaryContext &BC) override;
5959
};
6060
} // namespace bolt
6161
} // namespace llvm

Diff for: bolt/include/bolt/Passes/ReorderData.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ReorderData : public BinaryFunctionPass {
5151

5252
const char *getName() const override { return "reorder-data"; }
5353

54-
void runOnFunctions(BinaryContext &BC) override;
54+
Error runOnFunctions(BinaryContext &BC) override;
5555
};
5656

5757
} // namespace bolt

Diff for: bolt/include/bolt/Passes/ReorderFunctions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ReorderFunctions : public BinaryFunctionPass {
4242
: BinaryFunctionPass(PrintPass) {}
4343

4444
const char *getName() const override { return "reorder-functions"; }
45-
void runOnFunctions(BinaryContext &BC) override;
45+
Error runOnFunctions(BinaryContext &BC) override;
4646

4747
static std::vector<std::string> readFunctionOrderFile();
4848
};

0 commit comments

Comments
 (0)