1 //===-- ARMBasicBlockInfo.h - Basic Block Information -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Utility functions and data structure for computing block size.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
14 #define LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
16 #include "llvm/Support/MathExtras.h"
22 /// UnknownPadding - Return the worst case padding that could result from
23 /// unknown offset bits. This does not include alignment padding caused by
24 /// known offset bits.
26 /// @param LogAlign log2(alignment)
27 /// @param KnownBits Number of known low offset bits.
28 inline unsigned UnknownPadding(unsigned LogAlign
, unsigned KnownBits
) {
29 if (KnownBits
< LogAlign
)
30 return (1u << LogAlign
) - (1u << KnownBits
);
34 /// BasicBlockInfo - Information about the offset and size of a single
36 struct BasicBlockInfo
{
37 /// Offset - Distance from the beginning of the function to the beginning
38 /// of this basic block.
40 /// Offsets are computed assuming worst case padding before an aligned
41 /// block. This means that subtracting basic block offsets always gives a
42 /// conservative estimate of the real distance which may be smaller.
44 /// Because worst case padding is used, the computed offset of an aligned
45 /// block may not actually be aligned.
48 /// Size - Size of the basic block in bytes. If the block contains
49 /// inline assembly, this is a worst case estimate.
51 /// The size does not include any alignment padding whether from the
52 /// beginning of the block, or from an aligned jump table at the end.
55 /// KnownBits - The number of low bits in Offset that are known to be
56 /// exact. The remaining bits of Offset are an upper bound.
57 uint8_t KnownBits
= 0;
59 /// Unalign - When non-zero, the block contains instructions (inline asm)
60 /// of unknown size. The real size may be smaller than Size bytes by a
61 /// multiple of 1 << Unalign.
64 /// PostAlign - When non-zero, the block terminator contains a .align
65 /// directive, so the end of the block is aligned to 1 << PostAlign
67 uint8_t PostAlign
= 0;
69 BasicBlockInfo() = default;
71 /// Compute the number of known offset bits internally to this block.
72 /// This number should be used to predict worst case padding when
73 /// splitting the block.
74 unsigned internalKnownBits() const {
75 unsigned Bits
= Unalign
? Unalign
: KnownBits
;
76 // If the block size isn't a multiple of the known bits, assume the
77 // worst case padding.
78 if (Size
& ((1u << Bits
) - 1))
79 Bits
= countTrailingZeros(Size
);
83 /// Compute the offset immediately following this block. If LogAlign is
84 /// specified, return the offset the successor block will get if it has
86 unsigned postOffset(unsigned LogAlign
= 0) const {
87 unsigned PO
= Offset
+ Size
;
88 unsigned LA
= std::max(unsigned(PostAlign
), LogAlign
);
91 // Add alignment padding from the terminator.
92 return PO
+ UnknownPadding(LA
, internalKnownBits());
95 /// Compute the number of known low bits of postOffset. If this block
96 /// contains inline asm, the number of known bits drops to the
97 /// instruction alignment. An aligned terminator may increase the number
99 /// If LogAlign is given, also consider the alignment of the next block.
100 unsigned postKnownBits(unsigned LogAlign
= 0) const {
101 return std::max(std::max(unsigned(PostAlign
), LogAlign
),
102 internalKnownBits());
106 } // end namespace llvm
108 #endif // LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H