forked from OSchip/llvm-project
[BOLT] Fix hot_end symbol update with user function order
Summary: If no profile data is provided, but only a user-provided order file for functions, fix the placement of the __hot_end symbol. (cherry picked from FBD22713265)
This commit is contained in:
parent
6b89a9cb44
commit
ed02946281
|
@ -13,6 +13,7 @@
|
||||||
#include "BinaryPasses.h"
|
#include "BinaryPasses.h"
|
||||||
#include "ParallelUtilities.h"
|
#include "ParallelUtilities.h"
|
||||||
#include "Passes/ReorderAlgorithm.h"
|
#include "Passes/ReorderAlgorithm.h"
|
||||||
|
#include "Passes/ReorderFunctions.h"
|
||||||
#include "llvm/Support/Options.h"
|
#include "llvm/Support/Options.h"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
@ -60,6 +61,7 @@ extern cl::opt<bolt::MacroFusionType> AlignMacroOpFusion;
|
||||||
extern cl::opt<unsigned> Verbosity;
|
extern cl::opt<unsigned> Verbosity;
|
||||||
extern cl::opt<bool> EnableBAT;
|
extern cl::opt<bool> EnableBAT;
|
||||||
extern cl::opt<bool> UpdateDebugSections;
|
extern cl::opt<bool> UpdateDebugSections;
|
||||||
|
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
|
||||||
extern bool isHotTextMover(const bolt::BinaryFunction &Function);
|
extern bool isHotTextMover(const bolt::BinaryFunction &Function);
|
||||||
|
|
||||||
enum DynoStatsSortOrder : char {
|
enum DynoStatsSortOrder : char {
|
||||||
|
@ -1138,7 +1140,9 @@ void AssignSections::runOnFunctions(BinaryContext &BC) {
|
||||||
if (!BC.HasRelocations)
|
if (!BC.HasRelocations)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto UseColdSection = BC.NumProfiledFuncs > 0;
|
const auto UseColdSection =
|
||||||
|
BC.NumProfiledFuncs > 0 ||
|
||||||
|
opts::ReorderFunctions == ReorderFunctions::RT_USER;
|
||||||
for (auto &BFI : BC.getBinaryFunctions()) {
|
for (auto &BFI : BC.getBinaryFunctions()) {
|
||||||
auto &Function = BFI.second;
|
auto &Function = BFI.second;
|
||||||
if (opts::isHotTextMover(Function)) {
|
if (opts::isHotTextMover(Function)) {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
main
|
||||||
|
fib
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* Checks that BOLT correctly processes a user-provided function list file,
|
||||||
|
* reorder functions according to this list, update hot_start and hot_end
|
||||||
|
* symbols and insert a function to perform hot text mapping during program
|
||||||
|
* startup.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int foo(int x) {
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fib(int x) {
|
||||||
|
if (x < 2)
|
||||||
|
return x;
|
||||||
|
return fib(x - 1) + fib(x - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bar(int x) {
|
||||||
|
return x - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
printf("fib(%d) = %d\n", argc, fib(argc));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
REQUIRES: system-linux
|
||||||
|
|
||||||
|
RUN: %host_cc %s -o %t.exe -Wl,-q
|
||||||
|
|
||||||
|
RUN: llvm-bolt %t.exe -relocs=1 -lite -reorder-functions=user \
|
||||||
|
RUN: -function-order=%p/Inputs/user_func_order.txt -o %t
|
||||||
|
RUN: nm -ns %t | FileCheck %s -check-prefix=CHECK-NM
|
||||||
|
RUN: %t 1 2 3 | FileCheck %s -check-prefix=CHECK-OUTPUT
|
||||||
|
|
||||||
|
CHECK-NM: W __hot_start
|
||||||
|
CHECK-NM: T main
|
||||||
|
CHECK-NM-NEXT: T fib
|
||||||
|
CHECK-NM-NEXT: W __hot_end
|
||||||
|
|
||||||
|
CHECK-OUTPUT: fib(4) = 3
|
||||||
|
*/
|
Loading…
Reference in New Issue