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(BinaryContext &BC, const BinarySection &Section, 39 DataOrder::const_iterator Begin, 40 DataOrder::const_iterator End) const; 41 42 /// Set the ordering of the section with \p SectionName. \p NewOrder is a 43 /// vector of [old address, size] pairs. The new symbol order is implicit 44 /// in the order of the vector. 45 void setSectionOrder(BinaryContext &BC, BinarySection &OutputSection, 46 DataOrder::iterator Begin, DataOrder::iterator End); 47 48 bool markUnmoveableSymbols(BinaryContext &BC, BinarySection &Section) const; 49 50 public: ReorderData()51 explicit ReorderData() : BinaryFunctionPass(false) {} 52 getName()53 const char *getName() const override { return "reorder-data"; } 54 55 Error runOnFunctions(BinaryContext &BC) override; 56 }; 57 58 } // namespace bolt 59 } // namespace llvm 60 61 #endif 62