LLVM  14.0.0git
ARMBasicBlockInfo.h
Go to the documentation of this file.
1 //===-- ARMBasicBlockInfo.h - Basic Block Information -----------*- 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 // Utility functions and data structure for computing block size.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
14 #define LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
15 
16 #include "ARMBaseInstrInfo.h"
17 #include "ARMMachineFunctionInfo.h"
19 #include <algorithm>
20 #include <cstdint>
21 
22 namespace llvm {
23 
24 struct BasicBlockInfo;
26 
27 /// UnknownPadding - Return the worst case padding that could result from
28 /// unknown offset bits. This does not include alignment padding caused by
29 /// known offset bits.
30 ///
31 /// @param Alignment alignment
32 /// @param KnownBits Number of known low offset bits.
33 inline unsigned UnknownPadding(Align Alignment, unsigned KnownBits) {
34  if (KnownBits < Log2(Alignment))
35  return Alignment.value() - (1ull << KnownBits);
36  return 0;
37 }
38 
39 /// BasicBlockInfo - Information about the offset and size of a single
40 /// basic block.
42  /// Offset - Distance from the beginning of the function to the beginning
43  /// of this basic block.
44  ///
45  /// Offsets are computed assuming worst case padding before an aligned
46  /// block. This means that subtracting basic block offsets always gives a
47  /// conservative estimate of the real distance which may be smaller.
48  ///
49  /// Because worst case padding is used, the computed offset of an aligned
50  /// block may not actually be aligned.
51  unsigned Offset = 0;
52 
53  /// Size - Size of the basic block in bytes. If the block contains
54  /// inline assembly, this is a worst case estimate.
55  ///
56  /// The size does not include any alignment padding whether from the
57  /// beginning of the block, or from an aligned jump table at the end.
58  unsigned Size = 0;
59 
60  /// KnownBits - The number of low bits in Offset that are known to be
61  /// exact. The remaining bits of Offset are an upper bound.
62  uint8_t KnownBits = 0;
63 
64  /// Unalign - When non-zero, the block contains instructions (inline asm)
65  /// of unknown size. The real size may be smaller than Size bytes by a
66  /// multiple of 1 << Unalign.
67  uint8_t Unalign = 0;
68 
69  /// PostAlign - When > 1, the block terminator contains a .align
70  /// directive, so the end of the block is aligned to PostAlign bytes.
72 
73  BasicBlockInfo() = default;
74 
75  /// Compute the number of known offset bits internally to this block.
76  /// This number should be used to predict worst case padding when
77  /// splitting the block.
78  unsigned internalKnownBits() const {
79  unsigned Bits = Unalign ? Unalign : KnownBits;
80  // If the block size isn't a multiple of the known bits, assume the
81  // worst case padding.
82  if (Size & ((1u << Bits) - 1))
84  return Bits;
85  }
86 
87  /// Compute the offset immediately following this block. If Align is
88  /// specified, return the offset the successor block will get if it has
89  /// this alignment.
90  unsigned postOffset(Align Alignment = Align(1)) const {
91  unsigned PO = Offset + Size;
92  const Align PA = std::max(PostAlign, Alignment);
93  if (PA == Align(1))
94  return PO;
95  // Add alignment padding from the terminator.
96  return PO + UnknownPadding(PA, internalKnownBits());
97  }
98 
99  /// Compute the number of known low bits of postOffset. If this block
100  /// contains inline asm, the number of known bits drops to the
101  /// instruction alignment. An aligned terminator may increase the number
102  /// of know bits.
103  /// If LogAlign is given, also consider the alignment of the next block.
104  unsigned postKnownBits(Align Align = llvm::Align(1)) const {
106  }
107 };
108 
110 
111 private:
112  MachineFunction &MF;
113  bool isThumb = false;
114  const ARMBaseInstrInfo *TII = nullptr;
116 
117 public:
119  TII =
120  static_cast<const ARMBaseInstrInfo*>(MF.getSubtarget().getInstrInfo());
121  isThumb = MF.getInfo<ARMFunctionInfo>()->isThumbFunction();
122  }
123 
125  BBInfo.resize(MF.getNumBlockIDs());
126  for (MachineBasicBlock &MBB : MF)
128  }
129 
131 
132  unsigned getOffsetOf(MachineInstr *MI) const;
133 
134  unsigned getOffsetOf(MachineBasicBlock *MBB) const {
135  return BBInfo[MBB->getNumber()].Offset;
136  }
137 
139 
141  BBInfo[MBB->getNumber()].Size += Size;
142  }
143 
145  unsigned MaxDisp) const;
146 
147  void insert(unsigned BBNum, BasicBlockInfo BBI) {
148  BBInfo.insert(BBInfo.begin() + BBNum, BBI);
149  }
150 
151  void clear() { BBInfo.clear(); }
152 
153  BBInfoVector &getBBInfo() { return BBInfo; }
154 
155 };
156 
157 } // end namespace llvm
158 
159 #endif // LLVM_LIB_TARGET_ARM_ARMBASICBLOCKINFO_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::ARMFunctionInfo
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
Definition: ARMMachineFunctionInfo.h:27
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
MathExtras.h
llvm::ARMBasicBlockUtils::insert
void insert(unsigned BBNum, BasicBlockInfo BBI)
Definition: ARMBasicBlockInfo.h:147
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
llvm::BasicBlockInfo::postKnownBits
unsigned postKnownBits(Align Align=llvm::Align(1)) const
Compute the number of known low bits of postOffset.
Definition: ARMBasicBlockInfo.h:104
llvm::BasicBlockInfo::Offset
unsigned Offset
Offset - Distance from the beginning of the function to the beginning of this basic block.
Definition: ARMBasicBlockInfo.h:51
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
ARMMachineFunctionInfo.h
llvm::MachineFunction::getNumBlockIDs
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Definition: MachineFunction.h:749
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::ARMBasicBlockUtils::clear
void clear()
Definition: ARMBasicBlockInfo.h:151
llvm::ARMBasicBlockUtils::isBBInRange
bool isBBInRange(MachineInstr *MI, MachineBasicBlock *DestBB, unsigned MaxDisp) const
isBBInRange - Returns true if the distance between specific MI and specific BB can fit in MI's displa...
Definition: ARMBasicBlockInfo.cpp:93
llvm::BasicBlockInfo::postOffset
unsigned postOffset(Align Alignment=Align(1)) const
Compute the offset immediately following this block.
Definition: ARMBasicBlockInfo.h:90
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:720
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:207
llvm::BasicBlockInfo
BasicBlockInfo - Information about the offset and size of a single basic block.
Definition: ARMBasicBlockInfo.h:41
llvm::ARMBasicBlockUtils::computeBlockSize
void computeBlockSize(MachineBasicBlock *MBB)
Definition: ARMBasicBlockInfo.cpp:47
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:606
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
isThumbFunction
static bool isThumbFunction(Function *F, Triple::ArchType ModuleArch)
Definition: LowerTypeTests.cpp:1344
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:622
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::BasicBlockInfo::PostAlign
Align PostAlign
PostAlign - When > 1, the block terminator contains a .align directive, so the end of the block is al...
Definition: ARMBasicBlockInfo.h:71
llvm::BasicBlockInfo::internalKnownBits
unsigned internalKnownBits() const
Compute the number of known offset bits internally to this block.
Definition: ARMBasicBlockInfo.h:78
llvm::ARMBaseInstrInfo
Definition: ARMBaseInstrInfo.h:37
ARMBaseInstrInfo.h
llvm::BasicBlockInfo::Unalign
uint8_t Unalign
Unalign - When non-zero, the block contains instructions (inline asm) of unknown size.
Definition: ARMBasicBlockInfo.h:67
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::ARMBasicBlockUtils::getOffsetOf
unsigned getOffsetOf(MachineBasicBlock *MBB) const
Definition: ARMBasicBlockInfo.h:134
llvm::BasicBlockInfo::Size
unsigned Size
Size - Size of the basic block in bytes.
Definition: ARMBasicBlockInfo.h:58
llvm::countTrailingZeros
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: MathExtras.h:156
llvm::ARMBasicBlockUtils::adjustBBOffsetsAfter
void adjustBBOffsetsAfter(MachineBasicBlock *MBB)
Definition: ARMBasicBlockInfo.cpp:117
llvm::UnknownPadding
unsigned UnknownPadding(Align Alignment, unsigned KnownBits)
UnknownPadding - Return the worst case padding that could result from unknown offset bits.
Definition: ARMBasicBlockInfo.h:33
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::KnownBits
Definition: KnownBits.h:23
llvm::ARMBasicBlockUtils::adjustBBSize
void adjustBBSize(MachineBasicBlock *MBB, int Size)
Definition: ARMBasicBlockInfo.h:140
llvm::ARMBasicBlockUtils::ARMBasicBlockUtils
ARMBasicBlockUtils(MachineFunction &MF)
Definition: ARMBasicBlockInfo.h:118
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::ARMBasicBlockUtils::getBBInfo
BBInfoVector & getBBInfo()
Definition: ARMBasicBlockInfo.h:153
llvm::BasicBlockInfo::KnownBits
uint8_t KnownBits
KnownBits - The number of low bits in Offset that are known to be exact.
Definition: ARMBasicBlockInfo.h:62
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::ARMBasicBlockUtils::getOffsetOf
unsigned getOffsetOf(MachineInstr *MI) const
getOffsetOf - Return the current offset of the specified machine instruction from the start of the fu...
Definition: ARMBasicBlockInfo.cpp:75
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::BasicBlockInfo::BasicBlockInfo
BasicBlockInfo()=default
llvm::ARMBasicBlockUtils::computeAllBlockSizes
void computeAllBlockSizes()
Definition: ARMBasicBlockInfo.h:124
llvm::ARMBasicBlockUtils
Definition: ARMBasicBlockInfo.h:109
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:773