1 //===- bolt/Passes/ReorderFunctions.h - Reorder functions -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef BOLT_PASSES_REORDER_FUNCTIONS_H
10 #define BOLT_PASSES_REORDER_FUNCTIONS_H
11 
12 #include "bolt/Passes/BinaryFunctionCallGraph.h"
13 #include "bolt/Passes/BinaryPasses.h"
14 
15 namespace llvm {
16 namespace bolt {
17 class Cluster;
18 
19 /// Modify function order for streaming based on hotness.
20 class ReorderFunctions : public BinaryFunctionPass {
21   BinaryFunctionCallGraph Cg;
22 
23   void reorder(std::vector<Cluster> &&Clusters,
24                std::map<uint64_t, BinaryFunction> &BFs);
25 
26 public:
27   enum ReorderType : char {
28     RT_NONE = 0,
29     RT_EXEC_COUNT,
30     RT_HFSORT,
31     RT_HFSORT_PLUS,
32     RT_PETTIS_HANSEN,
33     RT_RANDOM,
34     RT_USER
35   };
36 
ReorderFunctions(const cl::opt<bool> & PrintPass)37   explicit ReorderFunctions(const cl::opt<bool> &PrintPass)
38       : BinaryFunctionPass(PrintPass) {}
39 
getName()40   const char *getName() const override { return "reorder-functions"; }
41   void runOnFunctions(BinaryContext &BC) override;
42 };
43 
44 } // namespace bolt
45 } // namespace llvm
46 
47 #endif // BOLT_PASSES_REORDER_FUNCTIONS_H
48