1 //===- bolt/Passes/ReorderSection.h - Reorder section data ------*- 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_DATA_H 10 #define BOLT_PASSES_REORDER_DATA_H 11 12 #include "bolt/Passes/BinaryPasses.h" 13 #include <unordered_map> 14 15 namespace llvm { 16 namespace bolt { 17 18 class ReorderData : public BinaryFunctionPass { 19 public: 20 using DataOrder = std::vector<std::pair<BinaryData *, uint64_t>>; 21 22 private: 23 DataOrder baseOrder(BinaryContext &BC, const BinarySection &Section) const; 24 25 std::unordered_map<BinaryData *, uint64_t> BinaryDataCounts; 26 27 void assignMemData(BinaryContext &BC); 28 29 /// Sort symbols by memory profiling data execution count. The output 30 /// is a vector of [address,count] pairs. 31 std::pair<DataOrder, unsigned> 32 sortedByCount(BinaryContext &BC, const BinarySection &Section) const; 33 34 std::pair<DataOrder, unsigned> 35 sortedByFunc(BinaryContext &BC, const BinarySection &Section, 36 std::map<uint64_t, BinaryFunction> &BFs) const; 37 38 void printOrder(const BinarySection &Section, DataOrder::const_iterator Begin, 39 DataOrder::const_iterator End) const; 40 41 /// Set the ordering of the section with \p SectionName. \p NewOrder is a 42 /// vector of [old address, size] pairs. The new symbol order is implicit 43 /// in the order of the vector. 44 void setSectionOrder(BinaryContext &BC, BinarySection &OutputSection, 45 DataOrder::iterator Begin, DataOrder::iterator End); 46 47 bool markUnmoveableSymbols(BinaryContext &BC, BinarySection &Section) const; 48 49 public: ReorderData()50 explicit ReorderData() : BinaryFunctionPass(false) {} 51 getName()52 const char *getName() const override { return "reorder-data"; } 53 54 void runOnFunctions(BinaryContext &BC) override; 55 }; 56 57 } // namespace bolt 58 } // namespace llvm 59 60 #endif 61