1 //===-- ARMBasicBlockInfo.h - Basic Block Information -----------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Utility functions and data structure for computing block size. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H 15 #define LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H 16 17 #include "ARM.h" 18 #include "ARMMachineFunctionInfo.h" 19 using namespace llvm; 20 21 namespace llvm { 22 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. 26 /// 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); 32 return 0; 33 } 34 35 /// BasicBlockInfo - Information about the offset and size of a single 36 /// basic block. 37 struct BasicBlockInfo { 38 /// Offset - Distance from the beginning of the function to the beginning 39 /// of this basic block. 40 /// 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. 44 /// 45 /// Because worst case padding is used, the computed offset of an aligned 46 /// block may not actually be aligned. 47 unsigned Offset; 48 49 /// Size - Size of the basic block in bytes. If the block contains 50 /// inline assembly, this is a worst case estimate. 51 /// 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. 54 unsigned Size; 55 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. 58 uint8_t KnownBits; 59 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. 63 uint8_t Unalign; 64 65 /// PostAlign - When non-zero, the block terminator contains a .align 66 /// directive, so the end of the block is aligned to 1 << PostAlign 67 /// bytes. 68 uint8_t PostAlign; 69 70 BasicBlockInfo() : Offset(0), Size(0), KnownBits(0), Unalign(0), 71 PostAlign(0) {} 72 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); 82 return Bits; 83 } 84 85 /// Compute the offset immediately following this block. If LogAlign is 86 /// specified, return the offset the successor block will get if it has 87 /// this alignment. 88 unsigned postOffset(unsigned LogAlign = 0) const { 89 unsigned PO = Offset + Size; 90 unsigned LA = std::max(unsigned(PostAlign), LogAlign); 91 if (!LA) 92 return PO; 93 // Add alignment padding from the terminator. 94 return PO + UnknownPadding(LA, internalKnownBits()); 95 } 96 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 100 /// of know bits. 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()); 105 } 106 }; 107 108 } // end namespace llvm 109 110 #endif 111