1 //===- bolt/Passes/Aligner.h - Pass for optimal code alignment --*- 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 // This file contains the declaration of the Aligner class, which provides 10 // alignment for code, e.g. basic block and functions, with the goal to achieve 11 // the optimal performance. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef BOLT_PASSES_ALIGNER_H 16 #define BOLT_PASSES_ALIGNER_H 17 18 #include "bolt/Passes/BinaryPasses.h" 19 20 namespace llvm { 21 namespace bolt { 22 23 class AlignerPass : public BinaryFunctionPass { 24 private: 25 /// Stats for usage of max bytes for basic block alignment. 26 std::vector<uint32_t> AlignHistogram; 27 std::shared_timed_mutex AlignHistogramMtx; 28 29 /// Stats: execution count of blocks that were aligned. 30 std::atomic<uint64_t> AlignedBlocksCount{0}; 31 32 /// Assign alignment to basic blocks based on profile. 33 void alignBlocks(BinaryFunction &Function, const MCCodeEmitter *Emitter); 34 35 public: AlignerPass()36 explicit AlignerPass() : BinaryFunctionPass(false) {} 37 getName()38 const char *getName() const override { return "aligner"; } 39 40 /// Pass entry point 41 void runOnFunctions(BinaryContext &BC) override; 42 }; 43 44 } // namespace bolt 45 } // namespace llvm 46 47 #endif 48