Skip to content

Commit 6bbd45d

Browse files
[NFC][BOLT] Refactor ForcePatch option (llvm#127812)
Move force-patch flag to CommandLineOpts and add details on PatchEntries.
1 parent fa4bf3a commit 6bbd45d

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern llvm::cl::opt<unsigned> BucketsPerLine;
3737
extern llvm::cl::opt<bool> DiffOnly;
3838
extern llvm::cl::opt<bool> EnableBAT;
3939
extern llvm::cl::opt<bool> EqualizeBBCounts;
40+
extern llvm::cl::opt<bool> ForcePatch;
4041
extern llvm::cl::opt<bool> RemoveSymtab;
4142
extern llvm::cl::opt<unsigned> ExecutionCountThreshold;
4243
extern llvm::cl::opt<unsigned> HeatmapBlock;

bolt/lib/Passes/PatchEntries.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the PatchEntries class that is used for patching
10-
// the original function entry points.
9+
// This file implements the PatchEntries class that is used for patching the
10+
// original function entry points. This ensures that only the new/optimized code
11+
// executes and that the old code is never used. This is necessary due to
12+
// current BOLT limitations of not being able to duplicate all function's
13+
// associated metadata (e.g., .eh_frame, exception ranges, debug info,
14+
// jump-tables).
15+
//
16+
// NOTE: A successful run of 'scanExternalRefs' can relax this requirement as
17+
// it also ensures that old code is never executed.
1118
//
1219
//===----------------------------------------------------------------------===//
1320

1421
#include "bolt/Passes/PatchEntries.h"
22+
#include "bolt/Utils/CommandLineOpts.h"
1523
#include "bolt/Utils/NameResolver.h"
1624
#include "llvm/ADT/STLExtras.h"
1725
#include "llvm/Support/CommandLine.h"
1826

1927
namespace opts {
20-
2128
extern llvm::cl::OptionCategory BoltCategory;
22-
2329
extern llvm::cl::opt<unsigned> Verbosity;
24-
25-
llvm::cl::opt<bool>
26-
ForcePatch("force-patch",
27-
llvm::cl::desc("force patching of original entry points"),
28-
llvm::cl::Hidden, llvm::cl::cat(BoltCategory));
29-
}
30+
} // namespace opts
3031

3132
namespace llvm {
3233
namespace bolt {

bolt/lib/Rewrite/MachORewriteInstance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "bolt/Rewrite/JITLinkLinker.h"
2121
#include "bolt/Rewrite/RewriteInstance.h"
2222
#include "bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h"
23+
#include "bolt/Utils/CommandLineOpts.h"
2324
#include "bolt/Utils/Utils.h"
2425
#include "llvm/MC/MCObjectStreamer.h"
2526
#include "llvm/Support/Errc.h"
@@ -32,9 +33,8 @@ namespace opts {
3233

3334
using namespace llvm;
3435
extern cl::opt<unsigned> AlignText;
35-
//FIXME! Upstream change
36-
//extern cl::opt<bool> CheckOverlappingElements;
37-
extern cl::opt<bool> ForcePatch;
36+
// FIXME! Upstream change
37+
// extern cl::opt<bool> CheckOverlappingElements;
3838
extern cl::opt<bool> Instrument;
3939
extern cl::opt<bool> InstrumentCalls;
4040
extern cl::opt<bolt::JumpTableSupportLevel> JumpTables;

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ cl::opt<bool> EqualizeBBCounts(
8080
"in non-LBR and shrink wrapping)"),
8181
cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
8282

83+
llvm::cl::opt<bool> ForcePatch(
84+
"force-patch",
85+
llvm::cl::desc("force patching of original entry points to ensure "
86+
"execution follows only the new/optimized code."),
87+
llvm::cl::Hidden, llvm::cl::cat(BoltCategory));
88+
8389
cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
8490
cl::cat(BoltCategory));
8591

0 commit comments

Comments
 (0)