xref: /llvm-project/bolt/include/bolt/Passes/Aligner.h (revision a5f3d1a803020167bd9d494a8a3921e7dcc1550a)
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 #include "llvm/Support/RWMutex.h"
20 
21 namespace llvm {
22 namespace bolt {
23 
24 class AlignerPass : public BinaryFunctionPass {
25 private:
26   /// Stats for usage of max bytes for basic block alignment.
27   std::vector<uint32_t> AlignHistogram;
28   llvm::sys::RWMutex AlignHistogramMtx;
29 
30   /// Stats: execution count of blocks that were aligned.
31   std::atomic<uint64_t> AlignedBlocksCount{0};
32 
33   /// Assign alignment to basic blocks based on profile.
34   void alignBlocks(BinaryFunction &Function, const MCCodeEmitter *Emitter);
35 
36 public:
AlignerPass()37   explicit AlignerPass() : BinaryFunctionPass(false) {}
38 
getName()39   const char *getName() const override { return "aligner"; }
40 
41   /// Pass entry point
42   Error runOnFunctions(BinaryContext &BC) override;
43 };
44 
45 } // namespace bolt
46 } // namespace llvm
47 
48 #endif
49