Skip to content

Commit 6b8d5d9

Browse files
committed
[BOLT][Linux] Optionally only handle C functions
BOLT can not handle some functions defined in assembly code reliably, since they may have extra semantics/enforcements BOLT can never know. For example, irq_entries_start defined in arch/x86/include/asm/idtentry.h is actually an “array” but BOLT views it as an ordinary function. If BOLT applies basic block reordering, instrumentation, etc to it, run time errors would happen. We could explicitly specify those functions to skip, but to find all of them we usually need to test & debug many times. That is a lot of work and we may still miss some. In my own experience, when adapting BOLT for Linux to a new architecture or Linux version, we may spend lots of time on fixing runtime errors related to functions defined in assembly code. Only handling C functions makes BOLT for Linux more reliable, and may save lots of development efforts. It can be used as follows: * put "-mllvm -bolt-function-list-file=filename" in KCFLAGS when buildling Linux * specify "-funcs-file-no-regex=filename" when invoking llvm-bolt
1 parent 01cc1d1 commit 6b8d5d9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "llvm/Support/Compiler.h"
8686
#include "llvm/Support/Debug.h"
8787
#include "llvm/Support/ErrorHandling.h"
88+
#include "llvm/Support/FileSystem.h"
8889
#include "llvm/Support/raw_ostream.h"
8990
#include "llvm/Target/TargetMachine.h"
9091
#include "llvm/Target/TargetOptions.h"
@@ -274,6 +275,10 @@ static cl::opt<bool>
274275
DisableDeletePHIs("disable-cgp-delete-phis", cl::Hidden, cl::init(false),
275276
cl::desc("Disable elimination of dead PHI nodes."));
276277

278+
cl::opt<std::string>
279+
BoltFunctionListFile("bolt-function-list-file", cl::Hidden,
280+
cl::desc("Specify BOLT function list file"));
281+
277282
namespace {
278283

279284
enum ExtType {
@@ -506,6 +511,14 @@ class CodeGenPrepareLegacyPass : public FunctionPass {
506511
char CodeGenPrepareLegacyPass::ID = 0;
507512

508513
bool CodeGenPrepareLegacyPass::runOnFunction(Function &F) {
514+
if (!BoltFunctionListFile.empty()) {
515+
std::error_code EC;
516+
raw_fd_ostream OS(BoltFunctionListFile, EC, sys::fs::OpenFlags::OF_Append);
517+
if (EC)
518+
report_fatal_error(Twine(BoltFunctionListFile) + ": " + EC.message());
519+
OS << F.getName() << "\n";
520+
}
521+
509522
if (skipFunction(F))
510523
return false;
511524
auto TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();

0 commit comments

Comments
 (0)