@@ -46,13 +46,13 @@ BreakFunctionNames("break-funcs",
4646 cl::Hidden,
4747 cl::cat(BoltCategory));
4848
49- cl::list<std::string>
49+ static cl::list<std::string>
5050 FunctionPadSpec (" pad-funcs" , cl::CommaSeparated,
5151 cl::desc (" list of functions to pad with amount of bytes" ),
5252 cl::value_desc(" func1:pad1,func2:pad2,func3:pad3,..." ),
5353 cl::Hidden, cl::cat(BoltCategory));
5454
55- cl::list<std::string> FunctionPadBeforeSpec (
55+ static cl::list<std::string> FunctionPadBeforeSpec (
5656 " pad-funcs-before" , cl::CommaSeparated,
5757 cl::desc (" list of functions to pad with amount of bytes" ),
5858 cl::value_desc(" func1:pad1,func2:pad2,func3:pad3,..." ), cl::Hidden,
@@ -74,10 +74,9 @@ X86AlignBranchBoundaryHotOnly("x86-align-branch-boundary-hot-only",
7474 cl::init(true ),
7575 cl::cat(BoltOptCategory));
7676
77- size_t padFunction (const cl::list<std::string> &Spec,
77+ size_t padFunction (std::map<std::string, size_t > &FunctionPadding,
78+ const cl::list<std::string> &Spec,
7879 const BinaryFunction &Function) {
79- static std::map<std::string, size_t > FunctionPadding;
80-
8180 if (FunctionPadding.empty () && !Spec.empty ()) {
8281 for (const std::string &Spec : Spec) {
8382 size_t N = Spec.find (' :' );
@@ -99,6 +98,15 @@ size_t padFunction(const cl::list<std::string> &Spec,
9998 return 0 ;
10099}
101100
101+ size_t padFunctionBefore (const BinaryFunction &Function) {
102+ static std::map<std::string, size_t > CacheFunctionPadding;
103+ return padFunction (CacheFunctionPadding, FunctionPadBeforeSpec, Function);
104+ }
105+ size_t padFunctionAfter (const BinaryFunction &Function) {
106+ static std::map<std::string, size_t > CacheFunctionPadding;
107+ return padFunction (CacheFunctionPadding, FunctionPadSpec, Function);
108+ }
109+
102110} // namespace opts
103111
104112namespace {
@@ -324,8 +332,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
324332 Streamer.emitCodeAlignment (Function.getAlign (), &*BC.STI );
325333 }
326334
327- if (size_t Padding =
328- opts::padFunction (opts::FunctionPadBeforeSpec, Function)) {
335+ if (size_t Padding = opts::padFunctionBefore (Function)) {
329336 // Handle padFuncsBefore after the above alignment logic but before
330337 // symbol addresses are decided.
331338 if (!BC.HasRelocations ) {
@@ -404,7 +411,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
404411 emitFunctionBody (Function, FF, /* EmitCodeOnly=*/ false );
405412
406413 // Emit padding if requested.
407- if (size_t Padding = opts::padFunction (opts::FunctionPadSpec, Function)) {
414+ if (size_t Padding = opts::padFunctionAfter ( Function)) {
408415 LLVM_DEBUG (dbgs () << " BOLT-DEBUG: padding function " << Function << " with "
409416 << Padding << " bytes\n " );
410417 Streamer.emitFill (Padding, MAI->getTextAlignFillValue ());
0 commit comments