LLVM  12.0.0git
BasicBlockSections.cpp
Go to the documentation of this file.
1 //===-- BasicBlockSections.cpp ---=========--------------------------------===//
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 // BasicBlockSections implementation.
10 //
11 // The purpose of this pass is to assign sections to basic blocks when
12 // -fbasic-block-sections= option is used. Further, with profile information
13 // only the subset of basic blocks with profiles are placed in separate sections
14 // and the rest are grouped in a cold section. The exception handling blocks are
15 // treated specially to ensure they are all in one seciton.
16 //
17 // Basic Block Sections
18 // ====================
19 //
20 // With option, -fbasic-block-sections=list, every function may be split into
21 // clusters of basic blocks. Every cluster will be emitted into a separate
22 // section with its basic blocks sequenced in the given order. To get the
23 // optimized performance, the clusters must form an optimal BB layout for the
24 // function. Every cluster's section is labeled with a symbol to allow the
25 // linker to reorder the sections in any arbitrary sequence. A global order of
26 // these sections would encapsulate the function layout.
27 //
28 // There are a couple of challenges to be addressed:
29 //
30 // 1. The last basic block of every cluster should not have any implicit
31 // fallthrough to its next basic block, as it can be reordered by the linker.
32 // The compiler should make these fallthroughs explicit by adding
33 // unconditional jumps..
34 //
35 // 2. All inter-cluster branch targets would now need to be resolved by the
36 // linker as they cannot be calculated during compile time. This is done
37 // using static relocations. Further, the compiler tries to use short branch
38 // instructions on some ISAs for small branch offsets. This is not possible
39 // for inter-cluster branches as the offset is not determined at compile
40 // time, and therefore, long branch instructions have to be used for those.
41 //
42 // 3. Debug Information (DebugInfo) and Call Frame Information (CFI) emission
43 // needs special handling with basic block sections. DebugInfo needs to be
44 // emitted with more relocations as basic block sections can break a
45 // function into potentially several disjoint pieces, and CFI needs to be
46 // emitted per cluster. This also bloats the object file and binary sizes.
47 //
48 // Basic Block Labels
49 // ==================
50 //
51 // With -fbasic-block-sections=labels, we emit the offsets of BB addresses of
52 // every function into the .llvm_bb_addr_map section. Along with the function
53 // symbols, this allows for mapping of virtual addresses in PMU profiles back to
54 // the corresponding basic blocks. This logic is implemented in AsmPrinter. This
55 // pass only assigns the BBSectionType of every function to ``labels``.
56 //
57 //===----------------------------------------------------------------------===//
58 
59 #include "llvm/ADT/Optional.h"
60 #include "llvm/ADT/SmallSet.h"
61 #include "llvm/ADT/SmallVector.h"
62 #include "llvm/ADT/StringMap.h"
63 #include "llvm/ADT/StringRef.h"
68 #include "llvm/CodeGen/Passes.h"
70 #include "llvm/InitializePasses.h"
71 #include "llvm/Support/Error.h"
75 
76 using llvm::SmallSet;
77 using llvm::SmallVector;
78 using llvm::StringMap;
79 using llvm::StringRef;
80 using namespace llvm;
81 
82 // Placing the cold clusters in a separate section mitigates against poor
83 // profiles and allows optimizations such as hugepage mapping to be applied at a
84 // section granularity. Defaults to ".text.split." which is recognized by lld
85 // via the `-z keep-text-section-prefix` flag.
87  "bbsections-cold-text-prefix",
88  cl::desc("The text prefix to use for cold basic block clusters"),
89  cl::init(".text.split."), cl::Hidden);
90 
91 namespace {
92 
93 // This struct represents the cluster information for a machine basic block.
94 struct BBClusterInfo {
95  // MachineBasicBlock ID.
96  unsigned MBBNumber;
97  // Cluster ID this basic block belongs to.
98  unsigned ClusterID;
99  // Position of basic block within the cluster.
100  unsigned PositionInCluster;
101 };
102 
103 using ProgramBBClusterInfoMapTy = StringMap<SmallVector<BBClusterInfo, 4>>;
104 
105 class BasicBlockSections : public MachineFunctionPass {
106 public:
107  static char ID;
108 
109  // This contains the basic-block-sections profile.
110  const MemoryBuffer *MBuf = nullptr;
111 
112  // This encapsulates the BB cluster information for the whole program.
113  //
114  // For every function name, it contains the cluster information for (all or
115  // some of) its basic blocks. The cluster information for every basic block
116  // includes its cluster ID along with the position of the basic block in that
117  // cluster.
118  ProgramBBClusterInfoMapTy ProgramBBClusterInfo;
119 
120  // Some functions have alias names. We use this map to find the main alias
121  // name for which we have mapping in ProgramBBClusterInfo.
122  StringMap<StringRef> FuncAliasMap;
123 
124  BasicBlockSections(const MemoryBuffer *Buf)
125  : MachineFunctionPass(ID), MBuf(Buf) {
127  };
128 
129  BasicBlockSections() : MachineFunctionPass(ID) {
131  }
132 
133  StringRef getPassName() const override {
134  return "Basic Block Sections Analysis";
135  }
136 
137  void getAnalysisUsage(AnalysisUsage &AU) const override;
138 
139  /// Read profiles of basic blocks if available here.
140  bool doInitialization(Module &M) override;
141 
142  /// Identify basic blocks that need separate sections and prepare to emit them
143  /// accordingly.
144  bool runOnMachineFunction(MachineFunction &MF) override;
145 };
146 
147 } // end anonymous namespace
148 
149 char BasicBlockSections::ID = 0;
150 INITIALIZE_PASS(BasicBlockSections, "bbsections-prepare",
151  "Prepares for basic block sections, by splitting functions "
152  "into clusters of basic blocks.",
153  false, false)
154 
155 // This function updates and optimizes the branching instructions of every basic
156 // block in a given function to account for changes in the layout.
157 static void updateBranches(
158  MachineFunction &MF,
160  const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
162  for (auto &MBB : MF) {
163  auto NextMBBI = std::next(MBB.getIterator());
164  auto *FTMBB = PreLayoutFallThroughs[MBB.getNumber()];
165  // If this block had a fallthrough before we need an explicit unconditional
166  // branch to that block if either
167  // 1- the block ends a section, which means its next block may be
168  // reorderd by the linker, or
169  // 2- the fallthrough block is not adjacent to the block in the new
170  // order.
171  if (FTMBB && (MBB.isEndSection() || &*NextMBBI != FTMBB))
172  TII->insertUnconditionalBranch(MBB, FTMBB, MBB.findBranchDebugLoc());
173 
174  // We do not optimize branches for machine basic blocks ending sections, as
175  // their adjacent block might be reordered by the linker.
176  if (MBB.isEndSection())
177  continue;
178 
179  // It might be possible to optimize branches by flipping the branch
180  // condition.
181  Cond.clear();
182  MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
183  if (TII->analyzeBranch(MBB, TBB, FBB, Cond))
184  continue;
185  MBB.updateTerminator(FTMBB);
186  }
187 }
188 
189 // This function provides the BBCluster information associated with a function.
190 // Returns true if a valid association exists and false otherwise.
192  const MachineFunction &MF, const StringMap<StringRef> FuncAliasMap,
193  const ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
195  // Get the main alias name for the function.
196  auto FuncName = MF.getName();
197  auto R = FuncAliasMap.find(FuncName);
198  StringRef AliasName = R == FuncAliasMap.end() ? FuncName : R->second;
199 
200  // Find the assoicated cluster information.
201  auto P = ProgramBBClusterInfo.find(AliasName);
202  if (P == ProgramBBClusterInfo.end())
203  return false;
204 
205  if (P->second.empty()) {
206  // This indicates that sections are desired for all basic blocks of this
207  // function. We clear the BBClusterInfo vector to denote this.
208  V.clear();
209  return true;
210  }
211 
212  V.resize(MF.getNumBlockIDs());
213  for (auto bbClusterInfo : P->second) {
214  // Bail out if the cluster information contains invalid MBB numbers.
215  if (bbClusterInfo.MBBNumber >= MF.getNumBlockIDs())
216  return false;
217  V[bbClusterInfo.MBBNumber] = bbClusterInfo;
218  }
219  return true;
220 }
221 
222 // This function sorts basic blocks according to the cluster's information.
223 // All explicitly specified clusters of basic blocks will be ordered
224 // accordingly. All non-specified BBs go into a separate "Cold" section.
225 // Additionally, if exception handling landing pads end up in more than one
226 // clusters, they are moved into a single "Exception" section. Eventually,
227 // clusters are ordered in increasing order of their IDs, with the "Exception"
228 // and "Cold" succeeding all other clusters.
229 // FuncBBClusterInfo represent the cluster information for basic blocks. If this
230 // is empty, it means unique sections for all basic blocks in the function.
231 static void
233  const std::vector<Optional<BBClusterInfo>> &FuncBBClusterInfo) {
234  assert(MF.hasBBSections() && "BB Sections is not set for function.");
235  // This variable stores the section ID of the cluster containing eh_pads (if
236  // all eh_pads are one cluster). If more than one cluster contain eh_pads, we
237  // set it equal to ExceptionSectionID.
238  Optional<MBBSectionID> EHPadsSectionID;
239 
240  for (auto &MBB : MF) {
241  // With the 'all' option, every basic block is placed in a unique section.
242  // With the 'list' option, every basic block is placed in a section
243  // associated with its cluster, unless we want individual unique sections
244  // for every basic block in this function (if FuncBBClusterInfo is empty).
245  if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All ||
246  FuncBBClusterInfo.empty()) {
247  // If unique sections are desired for all basic blocks of the function, we
248  // set every basic block's section ID equal to its number (basic block
249  // id). This further ensures that basic blocks are ordered canonically.
250  MBB.setSectionID({static_cast<unsigned int>(MBB.getNumber())});
251  } else if (FuncBBClusterInfo[MBB.getNumber()].hasValue())
252  MBB.setSectionID(FuncBBClusterInfo[MBB.getNumber()]->ClusterID);
253  else {
254  // BB goes into the special cold section if it is not specified in the
255  // cluster info map.
257  }
258 
259  if (MBB.isEHPad() && EHPadsSectionID != MBB.getSectionID() &&
260  EHPadsSectionID != MBBSectionID::ExceptionSectionID) {
261  // If we already have one cluster containing eh_pads, this must be updated
262  // to ExceptionSectionID. Otherwise, we set it equal to the current
263  // section ID.
264  EHPadsSectionID = EHPadsSectionID.hasValue()
266  : MBB.getSectionID();
267  }
268  }
269 
270  // If EHPads are in more than one section, this places all of them in the
271  // special exception section.
272  if (EHPadsSectionID == MBBSectionID::ExceptionSectionID)
273  for (auto &MBB : MF)
274  if (MBB.isEHPad())
275  MBB.setSectionID(EHPadsSectionID.getValue());
276 }
277 
281  MF.getNumBlockIDs());
282  for (auto &MBB : MF)
284 
285  MF.sort(MBBCmp);
286 
287  // Set IsBeginSection and IsEndSection according to the assigned section IDs.
288  MF.assignBeginEndSections();
289 
290  // After reordering basic blocks, we must update basic block branches to
291  // insert explicit fallthrough branches when required and optimize branches
292  // when possible.
293  updateBranches(MF, PreLayoutFallThroughs);
294 }
295 
296 // If the exception section begins with a landing pad, that landing pad will
297 // assume a zero offset (relative to @LPStart) in the LSDA. However, a value of
298 // zero implies "no landing pad." This function inserts a NOP just before the EH
299 // pad label to ensure a nonzero offset. Returns true if padding is not needed.
301  for (auto &MBB : MF) {
302  if (MBB.isBeginSection() && MBB.isEHPad()) {
304  while (!MI->isEHLabel())
305  ++MI;
306  MCInst Noop;
307  MF.getSubtarget().getInstrInfo()->getNoop(Noop);
308  BuildMI(MBB, MI, DebugLoc(),
309  MF.getSubtarget().getInstrInfo()->get(Noop.getOpcode()));
310  return false;
311  }
312  }
313  return true;
314 }
315 
316 bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
317  auto BBSectionsType = MF.getTarget().getBBSectionsType();
318  assert(BBSectionsType != BasicBlockSection::None &&
319  "BB Sections not enabled!");
320  // Renumber blocks before sorting them for basic block sections. This is
321  // useful during sorting, basic blocks in the same section will retain the
322  // default order. This renumbering should also be done for basic block
323  // labels to match the profiles with the correct blocks.
324  MF.RenumberBlocks();
325 
326  if (BBSectionsType == BasicBlockSection::Labels) {
327  MF.setBBSectionsType(BBSectionsType);
328  return true;
329  }
330 
331  std::vector<Optional<BBClusterInfo>> FuncBBClusterInfo;
332  if (BBSectionsType == BasicBlockSection::List &&
333  !getBBClusterInfoForFunction(MF, FuncAliasMap, ProgramBBClusterInfo,
334  FuncBBClusterInfo))
335  return true;
336  MF.setBBSectionsType(BBSectionsType);
337  assignSections(MF, FuncBBClusterInfo);
338 
339  // We make sure that the cluster including the entry basic block precedes all
340  // other clusters.
341  auto EntryBBSectionID = MF.front().getSectionID();
342 
343  // Helper function for ordering BB sections as follows:
344  // * Entry section (section including the entry block).
345  // * Regular sections (in increasing order of their Number).
346  // ...
347  // * Exception section
348  // * Cold section
349  auto MBBSectionOrder = [EntryBBSectionID](const MBBSectionID &LHS,
350  const MBBSectionID &RHS) {
351  // We make sure that the section containing the entry block precedes all the
352  // other sections.
353  if (LHS == EntryBBSectionID || RHS == EntryBBSectionID)
354  return LHS == EntryBBSectionID;
355  return LHS.Type == RHS.Type ? LHS.Number < RHS.Number : LHS.Type < RHS.Type;
356  };
357 
358  // We sort all basic blocks to make sure the basic blocks of every cluster are
359  // contiguous and ordered accordingly. Furthermore, clusters are ordered in
360  // increasing order of their section IDs, with the exception and the
361  // cold section placed at the end of the function.
362  auto Comparator = [&](const MachineBasicBlock &X,
363  const MachineBasicBlock &Y) {
364  auto XSectionID = X.getSectionID();
365  auto YSectionID = Y.getSectionID();
366  if (XSectionID != YSectionID)
367  return MBBSectionOrder(XSectionID, YSectionID);
368  // If the two basic block are in the same section, the order is decided by
369  // their position within the section.
370  if (XSectionID.Type == MBBSectionID::SectionType::Default)
371  return FuncBBClusterInfo[X.getNumber()]->PositionInCluster <
372  FuncBBClusterInfo[Y.getNumber()]->PositionInCluster;
373  return X.getNumber() < Y.getNumber();
374  };
375 
376  sortBasicBlocksAndUpdateBranches(MF, Comparator);
378  return true;
379 }
380 
381 // Basic Block Sections can be enabled for a subset of machine basic blocks.
382 // This is done by passing a file containing names of functions for which basic
383 // block sections are desired. Additionally, machine basic block ids of the
384 // functions can also be specified for a finer granularity. Moreover, a cluster
385 // of basic blocks could be assigned to the same section.
386 // A file with basic block sections for all of function main and three blocks
387 // for function foo (of which 1 and 2 are placed in a cluster) looks like this:
388 // ----------------------------
389 // list.txt:
390 // !main
391 // !foo
392 // !!1 2
393 // !!4
395  ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
396  StringMap<StringRef> &FuncAliasMap) {
397  assert(MBuf);
398  line_iterator LineIt(*MBuf, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
399 
400  auto invalidProfileError = [&](auto Message) {
401  return make_error<StringError>(
402  Twine("Invalid profile " + MBuf->getBufferIdentifier() + " at line " +
403  Twine(LineIt.line_number()) + ": " + Message),
405  };
406 
407  auto FI = ProgramBBClusterInfo.end();
408 
409  // Current cluster ID corresponding to this function.
410  unsigned CurrentCluster = 0;
411  // Current position in the current cluster.
412  unsigned CurrentPosition = 0;
413 
414  // Temporary set to ensure every basic block ID appears once in the clusters
415  // of a function.
416  SmallSet<unsigned, 4> FuncBBIDs;
417 
418  for (; !LineIt.is_at_eof(); ++LineIt) {
419  StringRef S(*LineIt);
420  if (S[0] == '@')
421  continue;
422  // Check for the leading "!"
423  if (!S.consume_front("!") || S.empty())
424  break;
425  // Check for second "!" which indicates a cluster of basic blocks.
426  if (S.consume_front("!")) {
427  if (FI == ProgramBBClusterInfo.end())
428  return invalidProfileError(
429  "Cluster list does not follow a function name specifier.");
430  SmallVector<StringRef, 4> BBIndexes;
431  S.split(BBIndexes, ' ');
432  // Reset current cluster position.
433  CurrentPosition = 0;
434  for (auto BBIndexStr : BBIndexes) {
435  unsigned long long BBIndex;
436  if (getAsUnsignedInteger(BBIndexStr, 10, BBIndex))
437  return invalidProfileError(Twine("Unsigned integer expected: '") +
438  BBIndexStr + "'.");
439  if (!FuncBBIDs.insert(BBIndex).second)
440  return invalidProfileError(Twine("Duplicate basic block id found '") +
441  BBIndexStr + "'.");
442  if (!BBIndex && CurrentPosition)
443  return invalidProfileError("Entry BB (0) does not begin a cluster.");
444 
445  FI->second.emplace_back(BBClusterInfo{
446  ((unsigned)BBIndex), CurrentCluster, CurrentPosition++});
447  }
448  CurrentCluster++;
449  } else { // This is a function name specifier.
450  // Function aliases are separated using '/'. We use the first function
451  // name for the cluster info mapping and delegate all other aliases to
452  // this one.
454  S.split(Aliases, '/');
455  for (size_t i = 1; i < Aliases.size(); ++i)
456  FuncAliasMap.try_emplace(Aliases[i], Aliases.front());
457 
458  // Prepare for parsing clusters of this function name.
459  // Start a new cluster map for this function name.
460  FI = ProgramBBClusterInfo.try_emplace(Aliases.front()).first;
461  CurrentCluster = 0;
462  FuncBBIDs.clear();
463  }
464  }
465  return Error::success();
466 }
467 
468 bool BasicBlockSections::doInitialization(Module &M) {
469  if (!MBuf)
470  return false;
471  if (auto Err = getBBClusterInfo(MBuf, ProgramBBClusterInfo, FuncAliasMap))
473  return false;
474 }
475 
476 void BasicBlockSections::getAnalysisUsage(AnalysisUsage &AU) const {
477  AU.setPreservesAll();
479 }
480 
483  return new BasicBlockSections(Buf);
484 }
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:75
void initializeBasicBlockSectionsPass(PassRegistry &)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void setSectionID(MBBSectionID V)
Sets the section ID for this basic block.
enum llvm::MBBSectionID::SectionType Type
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static const MBBSectionID ExceptionSectionID
DEBUG_TYPE to vector
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
Definition: StringRef.cpp:488
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:683
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:176
iterator find(StringRef Key)
Definition: StringMap.h:218
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
A debug info location.
Definition: DebugLoc.h:33
MachineBasicBlock & MBB
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
const HexagonInstrInfo * TII
MachineBasicBlock * getFallThrough()
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
Definition: LineIterator.h:55
MachineFunctionPass * createBasicBlockSectionsPass(const MemoryBuffer *Buf)
createBasicBlockSections Pass - This pass assigns sections to machine basic blocks and is enabled wit...
void clear()
Definition: SmallSet.h:218
void setBBSectionsType(BasicBlockSection V)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void sortBasicBlocksAndUpdateBranches(MachineFunction &MF, MachineBasicBlockComparator MBBCmp)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&... Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
Definition: StringMap.h:315
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
int64_t line_number() const
Return the current line number. May return any number at EOF.
Definition: LineIterator.h:61
TargetInstrInfo - Interface to description of machine instruction set.
const SmallVector< MachineBasicBlock *, 4 > & PreLayoutFallThroughs
static const MBBSectionID ColdSectionID
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:427
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
Represent the analysis usage information of a pass.
self_iterator getIterator()
Definition: ilist_node.h:81
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
bool isBeginSection() const
Returns true if this block begins any section.
const MachineBasicBlock & front() const
llvm::BasicBlockSection getBBSectionsType() const
If basic blocks should be emitted into their own section, corresponding to -fbasic-block-sections.
static bool getBBClusterInfoForFunction(const MachineFunction &MF, const StringMap< StringRef > FuncAliasMap, const ProgramBBClusterInfoMapTy &ProgramBBClusterInfo, std::vector< Optional< BBClusterInfo >> &V)
void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1116
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:730
static Error getBBClusterInfo(const MemoryBuffer *MBuf, ProgramBBClusterInfoMapTy &ProgramBBClusterInfo, StringMap< StringRef > &FuncAliasMap)
static void assignSections(MachineFunction &MF, const std::vector< Optional< BBClusterInfo >> &FuncBBClusterInfo)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
void setPreservesAll()
Set by analyses that do not transform their input at all.
DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1171
bool isEHPad() const
Returns true if the block is a landing pad.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
SmallVector< MachineOperand, 4 > Cond
INITIALIZE_PASS(BasicBlockSections, "bbsections-prepare", "Prepares for basic block sections, by splitting functions " "into clusters of basic blocks.", false, false) static void updateBranches(MachineFunction &MF
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
aarch64 promote const
bool isEndSection() const
Returns true if this block ends any section.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
IRTranslator LLVM IR MI
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1556
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
cl::opt< std::string > BBSectionsColdTextPrefix
unsigned getOpcode() const
Definition: MCInst.h:172
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Definition: SmallVector.h:1043
iterator end()
Definition: StringMap.h:205
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
static bool avoidZeroOffsetLandingPad(MachineFunction &MF)