1 //===-- ARMBasicBlockInfo.h - Basic Block Information -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Utility functions and data structure for computing block size.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
15 #define LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
18 #include "ARMMachineFunctionInfo.h"
23 /// UnknownPadding - Return the worst case padding that could result from
24 /// unknown offset bits. This does not include alignment padding caused by
25 /// known offset bits.
27 /// @param LogAlign log2(alignment)
28 /// @param KnownBits Number of known low offset bits.
29 inline unsigned UnknownPadding(unsigned LogAlign, unsigned KnownBits) {
30 if (KnownBits < LogAlign)
31 return (1u << LogAlign) - (1u << KnownBits);
35 /// BasicBlockInfo - Information about the offset and size of a single
37 struct BasicBlockInfo {
38 /// Offset - Distance from the beginning of the function to the beginning
39 /// of this basic block.
41 /// Offsets are computed assuming worst case padding before an aligned
42 /// block. This means that subtracting basic block offsets always gives a
43 /// conservative estimate of the real distance which may be smaller.
45 /// Because worst case padding is used, the computed offset of an aligned
46 /// block may not actually be aligned.
49 /// Size - Size of the basic block in bytes. If the block contains
50 /// inline assembly, this is a worst case estimate.
52 /// The size does not include any alignment padding whether from the
53 /// beginning of the block, or from an aligned jump table at the end.
56 /// KnownBits - The number of low bits in Offset that are known to be
57 /// exact. The remaining bits of Offset are an upper bound.
60 /// Unalign - When non-zero, the block contains instructions (inline asm)
61 /// of unknown size. The real size may be smaller than Size bytes by a
62 /// multiple of 1 << Unalign.
65 /// PostAlign - When non-zero, the block terminator contains a .align
66 /// directive, so the end of the block is aligned to 1 << PostAlign
70 BasicBlockInfo() : Offset(0), Size(0), KnownBits(0), Unalign(0),
73 /// Compute the number of known offset bits internally to this block.
74 /// This number should be used to predict worst case padding when
75 /// splitting the block.
76 unsigned internalKnownBits() const {
77 unsigned Bits = Unalign ? Unalign : KnownBits;
78 // If the block size isn't a multiple of the known bits, assume the
79 // worst case padding.
80 if (Size & ((1u << Bits) - 1))
81 Bits = countTrailingZeros(Size);
85 /// Compute the offset immediately following this block. If LogAlign is
86 /// specified, return the offset the successor block will get if it has
88 unsigned postOffset(unsigned LogAlign = 0) const {
89 unsigned PO = Offset + Size;
90 unsigned LA = std::max(unsigned(PostAlign), LogAlign);
93 // Add alignment padding from the terminator.
94 return PO + UnknownPadding(LA, internalKnownBits());
97 /// Compute the number of known low bits of postOffset. If this block
98 /// contains inline asm, the number of known bits drops to the
99 /// instruction alignment. An aligned terminator may increase the number
101 /// If LogAlign is given, also consider the alignment of the next block.
102 unsigned postKnownBits(unsigned LogAlign = 0) const {
103 return std::max(std::max(unsigned(PostAlign), LogAlign),
104 internalKnownBits());
108 } // end namespace llvm