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/Core/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(BinaryContext &BC, std::vector<Cluster> &&Clusters, 24 std::map<uint64_t, BinaryFunction> &BFs); 25 26 void printStats(BinaryContext &BC, const std::vector<Cluster> &Clusters, 27 const std::vector<uint64_t> &FuncAddr); 28 29 public: 30 enum ReorderType : char { 31 RT_NONE = 0, 32 RT_EXEC_COUNT, 33 RT_HFSORT, 34 RT_HFSORT_PLUS, 35 RT_CDSORT, 36 RT_PETTIS_HANSEN, 37 RT_RANDOM, 38 RT_USER 39 }; 40 ReorderFunctions(const cl::opt<bool> & PrintPass)41 explicit ReorderFunctions(const cl::opt<bool> &PrintPass) 42 : BinaryFunctionPass(PrintPass) {} 43 getName()44 const char *getName() const override { return "reorder-functions"; } 45 Error runOnFunctions(BinaryContext &BC) override; 46 47 static Error readFunctionOrderFile(std::vector<std::string> &FunctionNames); 48 }; 49 50 } // namespace bolt 51 } // namespace llvm 52 53 #endif // BOLT_PASSES_REORDER_FUNCTIONS_H 54