BasicBlockSections.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. We insert a symbol at the beginning of every cluster's section to
  25. // allow the linker to reorder the sections in any arbitrary sequence. A global
  26. // order of these sections would encapsulate the function layout.
  27. // For example, consider the following clusters for a function foo (consisting
  28. // of 6 basic blocks 0, 1, ..., 5).
  29. //
  30. // 0 2
  31. // 1 3 5
  32. //
  33. // * Basic blocks 0 and 2 are placed in one section with symbol `foo`
  34. // referencing the beginning of this section.
  35. // * Basic blocks 1, 3, 5 are placed in a separate section. A new symbol
  36. // `foo.__part.1` will reference the beginning of this section.
  37. // * Basic block 4 (note that it is not referenced in the list) is placed in
  38. // one section, and a new symbol `foo.cold` will point to it.
  39. //
  40. // There are a couple of challenges to be addressed:
  41. //
  42. // 1. The last basic block of every cluster should not have any implicit
  43. // fallthrough to its next basic block, as it can be reordered by the linker.
  44. // The compiler should make these fallthroughs explicit by adding
  45. // unconditional jumps..
  46. //
  47. // 2. All inter-cluster branch targets would now need to be resolved by the
  48. // linker as they cannot be calculated during compile time. This is done
  49. // using static relocations. Further, the compiler tries to use short branch
  50. // instructions on some ISAs for small branch offsets. This is not possible
  51. // for inter-cluster branches as the offset is not determined at compile
  52. // time, and therefore, long branch instructions have to be used for those.
  53. //
  54. // 3. Debug Information (DebugInfo) and Call Frame Information (CFI) emission
  55. // needs special handling with basic block sections. DebugInfo needs to be
  56. // emitted with more relocations as basic block sections can break a
  57. // function into potentially several disjoint pieces, and CFI needs to be
  58. // emitted per cluster. This also bloats the object file and binary sizes.
  59. //
  60. // Basic Block Labels
  61. // ==================
  62. //
  63. // With -fbasic-block-sections=labels, we emit the offsets of BB addresses of
  64. // every function into the .llvm_bb_addr_map section. Along with the function
  65. // symbols, this allows for mapping of virtual addresses in PMU profiles back to
  66. // the corresponding basic blocks. This logic is implemented in AsmPrinter. This
  67. // pass only assigns the BBSectionType of every function to ``labels``.
  68. //
  69. //===----------------------------------------------------------------------===//
  70. #include "llvm/ADT/Optional.h"
  71. #include "llvm/ADT/SmallSet.h"
  72. #include "llvm/ADT/SmallVector.h"
  73. #include "llvm/ADT/StringMap.h"
  74. #include "llvm/ADT/StringRef.h"
  75. #include "llvm/CodeGen/BasicBlockSectionUtils.h"
  76. #include "llvm/CodeGen/MachineFunction.h"
  77. #include "llvm/CodeGen/MachineFunctionPass.h"
  78. #include "llvm/CodeGen/MachineModuleInfo.h"
  79. #include "llvm/CodeGen/Passes.h"
  80. #include "llvm/CodeGen/TargetInstrInfo.h"
  81. #include "llvm/InitializePasses.h"
  82. #include "llvm/Support/Error.h"
  83. #include "llvm/Support/LineIterator.h"
  84. #include "llvm/Support/MemoryBuffer.h"
  85. #include "llvm/Target/TargetMachine.h"
  86. using llvm::SmallSet;
  87. using llvm::SmallVector;
  88. using llvm::StringMap;
  89. using llvm::StringRef;
  90. using namespace llvm;
  91. // Placing the cold clusters in a separate section mitigates against poor
  92. // profiles and allows optimizations such as hugepage mapping to be applied at a
  93. // section granularity. Defaults to ".text.split." which is recognized by lld
  94. // via the `-z keep-text-section-prefix` flag.
  95. cl::opt<std::string> llvm::BBSectionsColdTextPrefix(
  96. "bbsections-cold-text-prefix",
  97. cl::desc("The text prefix to use for cold basic block clusters"),
  98. cl::init(".text.split."), cl::Hidden);
  99. cl::opt<bool> BBSectionsDetectSourceDrift(
  100. "bbsections-detect-source-drift",
  101. cl::desc("This checks if there is a fdo instr. profile hash "
  102. "mismatch for this function"),
  103. cl::init(true), cl::Hidden);
  104. namespace {
  105. // This struct represents the cluster information for a machine basic block.
  106. struct BBClusterInfo {
  107. // MachineBasicBlock ID.
  108. unsigned MBBNumber;
  109. // Cluster ID this basic block belongs to.
  110. unsigned ClusterID;
  111. // Position of basic block within the cluster.
  112. unsigned PositionInCluster;
  113. };
  114. using ProgramBBClusterInfoMapTy = StringMap<SmallVector<BBClusterInfo, 4>>;
  115. class BasicBlockSections : public MachineFunctionPass {
  116. public:
  117. static char ID;
  118. // This contains the basic-block-sections profile.
  119. const MemoryBuffer *MBuf = nullptr;
  120. // This encapsulates the BB cluster information for the whole program.
  121. //
  122. // For every function name, it contains the cluster information for (all or
  123. // some of) its basic blocks. The cluster information for every basic block
  124. // includes its cluster ID along with the position of the basic block in that
  125. // cluster.
  126. ProgramBBClusterInfoMapTy ProgramBBClusterInfo;
  127. // Some functions have alias names. We use this map to find the main alias
  128. // name for which we have mapping in ProgramBBClusterInfo.
  129. StringMap<StringRef> FuncAliasMap;
  130. BasicBlockSections(const MemoryBuffer *Buf)
  131. : MachineFunctionPass(ID), MBuf(Buf) {
  132. initializeBasicBlockSectionsPass(*PassRegistry::getPassRegistry());
  133. };
  134. BasicBlockSections() : MachineFunctionPass(ID) {
  135. initializeBasicBlockSectionsPass(*PassRegistry::getPassRegistry());
  136. }
  137. StringRef getPassName() const override {
  138. return "Basic Block Sections Analysis";
  139. }
  140. void getAnalysisUsage(AnalysisUsage &AU) const override;
  141. /// Read profiles of basic blocks if available here.
  142. bool doInitialization(Module &M) override;
  143. /// Identify basic blocks that need separate sections and prepare to emit them
  144. /// accordingly.
  145. bool runOnMachineFunction(MachineFunction &MF) override;
  146. };
  147. } // end anonymous namespace
  148. char BasicBlockSections::ID = 0;
  149. INITIALIZE_PASS(BasicBlockSections, "bbsections-prepare",
  150. "Prepares for basic block sections, by splitting functions "
  151. "into clusters of basic blocks.",
  152. false, false)
  153. // This function updates and optimizes the branching instructions of every basic
  154. // block in a given function to account for changes in the layout.
  155. static void updateBranches(
  156. MachineFunction &MF,
  157. const SmallVector<MachineBasicBlock *, 4> &PreLayoutFallThroughs) {
  158. const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
  159. SmallVector<MachineOperand, 4> Cond;
  160. for (auto &MBB : MF) {
  161. auto NextMBBI = std::next(MBB.getIterator());
  162. auto *FTMBB = PreLayoutFallThroughs[MBB.getNumber()];
  163. // If this block had a fallthrough before we need an explicit unconditional
  164. // branch to that block if either
  165. // 1- the block ends a section, which means its next block may be
  166. // reorderd by the linker, or
  167. // 2- the fallthrough block is not adjacent to the block in the new
  168. // order.
  169. if (FTMBB && (MBB.isEndSection() || &*NextMBBI != FTMBB))
  170. TII->insertUnconditionalBranch(MBB, FTMBB, MBB.findBranchDebugLoc());
  171. // We do not optimize branches for machine basic blocks ending sections, as
  172. // their adjacent block might be reordered by the linker.
  173. if (MBB.isEndSection())
  174. continue;
  175. // It might be possible to optimize branches by flipping the branch
  176. // condition.
  177. Cond.clear();
  178. MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For analyzeBranch.
  179. if (TII->analyzeBranch(MBB, TBB, FBB, Cond))
  180. continue;
  181. MBB.updateTerminator(FTMBB);
  182. }
  183. }
  184. // This function provides the BBCluster information associated with a function.
  185. // Returns true if a valid association exists and false otherwise.
  186. static bool getBBClusterInfoForFunction(
  187. const MachineFunction &MF, const StringMap<StringRef> FuncAliasMap,
  188. const ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
  189. std::vector<Optional<BBClusterInfo>> &V) {
  190. // Get the main alias name for the function.
  191. auto FuncName = MF.getName();
  192. auto R = FuncAliasMap.find(FuncName);
  193. StringRef AliasName = R == FuncAliasMap.end() ? FuncName : R->second;
  194. // Find the assoicated cluster information.
  195. auto P = ProgramBBClusterInfo.find(AliasName);
  196. if (P == ProgramBBClusterInfo.end())
  197. return false;
  198. if (P->second.empty()) {
  199. // This indicates that sections are desired for all basic blocks of this
  200. // function. We clear the BBClusterInfo vector to denote this.
  201. V.clear();
  202. return true;
  203. }
  204. V.resize(MF.getNumBlockIDs());
  205. for (auto bbClusterInfo : P->second) {
  206. // Bail out if the cluster information contains invalid MBB numbers.
  207. if (bbClusterInfo.MBBNumber >= MF.getNumBlockIDs())
  208. return false;
  209. V[bbClusterInfo.MBBNumber] = bbClusterInfo;
  210. }
  211. return true;
  212. }
  213. // This function sorts basic blocks according to the cluster's information.
  214. // All explicitly specified clusters of basic blocks will be ordered
  215. // accordingly. All non-specified BBs go into a separate "Cold" section.
  216. // Additionally, if exception handling landing pads end up in more than one
  217. // clusters, they are moved into a single "Exception" section. Eventually,
  218. // clusters are ordered in increasing order of their IDs, with the "Exception"
  219. // and "Cold" succeeding all other clusters.
  220. // FuncBBClusterInfo represent the cluster information for basic blocks. If this
  221. // is empty, it means unique sections for all basic blocks in the function.
  222. static void
  223. assignSections(MachineFunction &MF,
  224. const std::vector<Optional<BBClusterInfo>> &FuncBBClusterInfo) {
  225. assert(MF.hasBBSections() && "BB Sections is not set for function.");
  226. // This variable stores the section ID of the cluster containing eh_pads (if
  227. // all eh_pads are one cluster). If more than one cluster contain eh_pads, we
  228. // set it equal to ExceptionSectionID.
  229. Optional<MBBSectionID> EHPadsSectionID;
  230. for (auto &MBB : MF) {
  231. // With the 'all' option, every basic block is placed in a unique section.
  232. // With the 'list' option, every basic block is placed in a section
  233. // associated with its cluster, unless we want individual unique sections
  234. // for every basic block in this function (if FuncBBClusterInfo is empty).
  235. if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All ||
  236. FuncBBClusterInfo.empty()) {
  237. // If unique sections are desired for all basic blocks of the function, we
  238. // set every basic block's section ID equal to its number (basic block
  239. // id). This further ensures that basic blocks are ordered canonically.
  240. MBB.setSectionID({static_cast<unsigned int>(MBB.getNumber())});
  241. } else if (FuncBBClusterInfo[MBB.getNumber()].hasValue())
  242. MBB.setSectionID(FuncBBClusterInfo[MBB.getNumber()]->ClusterID);
  243. else {
  244. // BB goes into the special cold section if it is not specified in the
  245. // cluster info map.
  246. MBB.setSectionID(MBBSectionID::ColdSectionID);
  247. }
  248. if (MBB.isEHPad() && EHPadsSectionID != MBB.getSectionID() &&
  249. EHPadsSectionID != MBBSectionID::ExceptionSectionID) {
  250. // If we already have one cluster containing eh_pads, this must be updated
  251. // to ExceptionSectionID. Otherwise, we set it equal to the current
  252. // section ID.
  253. EHPadsSectionID = EHPadsSectionID.hasValue()
  254. ? MBBSectionID::ExceptionSectionID
  255. : MBB.getSectionID();
  256. }
  257. }
  258. // If EHPads are in more than one section, this places all of them in the
  259. // special exception section.
  260. if (EHPadsSectionID == MBBSectionID::ExceptionSectionID)
  261. for (auto &MBB : MF)
  262. if (MBB.isEHPad())
  263. MBB.setSectionID(EHPadsSectionID.getValue());
  264. }
  265. void llvm::sortBasicBlocksAndUpdateBranches(
  266. MachineFunction &MF, MachineBasicBlockComparator MBBCmp) {
  267. SmallVector<MachineBasicBlock *, 4> PreLayoutFallThroughs(
  268. MF.getNumBlockIDs());
  269. for (auto &MBB : MF)
  270. PreLayoutFallThroughs[MBB.getNumber()] = MBB.getFallThrough();
  271. MF.sort(MBBCmp);
  272. // Set IsBeginSection and IsEndSection according to the assigned section IDs.
  273. MF.assignBeginEndSections();
  274. // After reordering basic blocks, we must update basic block branches to
  275. // insert explicit fallthrough branches when required and optimize branches
  276. // when possible.
  277. updateBranches(MF, PreLayoutFallThroughs);
  278. }
  279. // If the exception section begins with a landing pad, that landing pad will
  280. // assume a zero offset (relative to @LPStart) in the LSDA. However, a value of
  281. // zero implies "no landing pad." This function inserts a NOP just before the EH
  282. // pad label to ensure a nonzero offset. Returns true if padding is not needed.
  283. static bool avoidZeroOffsetLandingPad(MachineFunction &MF) {
  284. for (auto &MBB : MF) {
  285. if (MBB.isBeginSection() && MBB.isEHPad()) {
  286. MachineBasicBlock::iterator MI = MBB.begin();
  287. while (!MI->isEHLabel())
  288. ++MI;
  289. MCInst Nop = MF.getSubtarget().getInstrInfo()->getNop();
  290. BuildMI(MBB, MI, DebugLoc(),
  291. MF.getSubtarget().getInstrInfo()->get(Nop.getOpcode()));
  292. return false;
  293. }
  294. }
  295. return true;
  296. }
  297. // This checks if the source of this function has drifted since this binary was
  298. // profiled previously. For now, we are piggy backing on what PGO does to
  299. // detect this with instrumented profiles. PGO emits an hash of the IR and
  300. // checks if the hash has changed. Advanced basic block layout is usually done
  301. // on top of PGO optimized binaries and hence this check works well in practice.
  302. static bool hasInstrProfHashMismatch(MachineFunction &MF) {
  303. if (!BBSectionsDetectSourceDrift)
  304. return false;
  305. const char MetadataName[] = "instr_prof_hash_mismatch";
  306. auto *Existing = MF.getFunction().getMetadata(LLVMContext::MD_annotation);
  307. if (Existing) {
  308. MDTuple *Tuple = cast<MDTuple>(Existing);
  309. for (auto &N : Tuple->operands())
  310. if (cast<MDString>(N.get())->getString() == MetadataName)
  311. return true;
  312. }
  313. return false;
  314. }
  315. bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
  316. auto BBSectionsType = MF.getTarget().getBBSectionsType();
  317. assert(BBSectionsType != BasicBlockSection::None &&
  318. "BB Sections not enabled!");
  319. // Check for source drift. If the source has changed since the profiles
  320. // were obtained, optimizing basic blocks might be sub-optimal.
  321. // This only applies to BasicBlockSection::List as it creates
  322. // clusters of basic blocks using basic block ids. Source drift can
  323. // invalidate these groupings leading to sub-optimal code generation with
  324. // regards to performance.
  325. if (BBSectionsType == BasicBlockSection::List &&
  326. hasInstrProfHashMismatch(MF))
  327. return true;
  328. // Renumber blocks before sorting them for basic block sections. This is
  329. // useful during sorting, basic blocks in the same section will retain the
  330. // default order. This renumbering should also be done for basic block
  331. // labels to match the profiles with the correct blocks.
  332. MF.RenumberBlocks();
  333. if (BBSectionsType == BasicBlockSection::Labels) {
  334. MF.setBBSectionsType(BBSectionsType);
  335. return true;
  336. }
  337. std::vector<Optional<BBClusterInfo>> FuncBBClusterInfo;
  338. if (BBSectionsType == BasicBlockSection::List &&
  339. !getBBClusterInfoForFunction(MF, FuncAliasMap, ProgramBBClusterInfo,
  340. FuncBBClusterInfo))
  341. return true;
  342. MF.setBBSectionsType(BBSectionsType);
  343. assignSections(MF, FuncBBClusterInfo);
  344. // We make sure that the cluster including the entry basic block precedes all
  345. // other clusters.
  346. auto EntryBBSectionID = MF.front().getSectionID();
  347. // Helper function for ordering BB sections as follows:
  348. // * Entry section (section including the entry block).
  349. // * Regular sections (in increasing order of their Number).
  350. // ...
  351. // * Exception section
  352. // * Cold section
  353. auto MBBSectionOrder = [EntryBBSectionID](const MBBSectionID &LHS,
  354. const MBBSectionID &RHS) {
  355. // We make sure that the section containing the entry block precedes all the
  356. // other sections.
  357. if (LHS == EntryBBSectionID || RHS == EntryBBSectionID)
  358. return LHS == EntryBBSectionID;
  359. return LHS.Type == RHS.Type ? LHS.Number < RHS.Number : LHS.Type < RHS.Type;
  360. };
  361. // We sort all basic blocks to make sure the basic blocks of every cluster are
  362. // contiguous and ordered accordingly. Furthermore, clusters are ordered in
  363. // increasing order of their section IDs, with the exception and the
  364. // cold section placed at the end of the function.
  365. auto Comparator = [&](const MachineBasicBlock &X,
  366. const MachineBasicBlock &Y) {
  367. auto XSectionID = X.getSectionID();
  368. auto YSectionID = Y.getSectionID();
  369. if (XSectionID != YSectionID)
  370. return MBBSectionOrder(XSectionID, YSectionID);
  371. // If the two basic block are in the same section, the order is decided by
  372. // their position within the section.
  373. if (XSectionID.Type == MBBSectionID::SectionType::Default)
  374. return FuncBBClusterInfo[X.getNumber()]->PositionInCluster <
  375. FuncBBClusterInfo[Y.getNumber()]->PositionInCluster;
  376. return X.getNumber() < Y.getNumber();
  377. };
  378. sortBasicBlocksAndUpdateBranches(MF, Comparator);
  379. avoidZeroOffsetLandingPad(MF);
  380. return true;
  381. }
  382. // Basic Block Sections can be enabled for a subset of machine basic blocks.
  383. // This is done by passing a file containing names of functions for which basic
  384. // block sections are desired. Additionally, machine basic block ids of the
  385. // functions can also be specified for a finer granularity. Moreover, a cluster
  386. // of basic blocks could be assigned to the same section.
  387. // A file with basic block sections for all of function main and three blocks
  388. // for function foo (of which 1 and 2 are placed in a cluster) looks like this:
  389. // ----------------------------
  390. // list.txt:
  391. // !main
  392. // !foo
  393. // !!1 2
  394. // !!4
  395. static Error getBBClusterInfo(const MemoryBuffer *MBuf,
  396. ProgramBBClusterInfoMapTy &ProgramBBClusterInfo,
  397. StringMap<StringRef> &FuncAliasMap) {
  398. assert(MBuf);
  399. line_iterator LineIt(*MBuf, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
  400. auto invalidProfileError = [&](auto Message) {
  401. return make_error<StringError>(
  402. Twine("Invalid profile " + MBuf->getBufferIdentifier() + " at line " +
  403. Twine(LineIt.line_number()) + ": " + Message),
  404. inconvertibleErrorCode());
  405. };
  406. auto FI = ProgramBBClusterInfo.end();
  407. // Current cluster ID corresponding to this function.
  408. unsigned CurrentCluster = 0;
  409. // Current position in the current cluster.
  410. unsigned CurrentPosition = 0;
  411. // Temporary set to ensure every basic block ID appears once in the clusters
  412. // of a function.
  413. SmallSet<unsigned, 4> FuncBBIDs;
  414. for (; !LineIt.is_at_eof(); ++LineIt) {
  415. StringRef S(*LineIt);
  416. if (S[0] == '@')
  417. continue;
  418. // Check for the leading "!"
  419. if (!S.consume_front("!") || S.empty())
  420. break;
  421. // Check for second "!" which indicates a cluster of basic blocks.
  422. if (S.consume_front("!")) {
  423. if (FI == ProgramBBClusterInfo.end())
  424. return invalidProfileError(
  425. "Cluster list does not follow a function name specifier.");
  426. SmallVector<StringRef, 4> BBIndexes;
  427. S.split(BBIndexes, ' ');
  428. // Reset current cluster position.
  429. CurrentPosition = 0;
  430. for (auto BBIndexStr : BBIndexes) {
  431. unsigned long long BBIndex;
  432. if (getAsUnsignedInteger(BBIndexStr, 10, BBIndex))
  433. return invalidProfileError(Twine("Unsigned integer expected: '") +
  434. BBIndexStr + "'.");
  435. if (!FuncBBIDs.insert(BBIndex).second)
  436. return invalidProfileError(Twine("Duplicate basic block id found '") +
  437. BBIndexStr + "'.");
  438. if (!BBIndex && CurrentPosition)
  439. return invalidProfileError("Entry BB (0) does not begin a cluster.");
  440. FI->second.emplace_back(BBClusterInfo{
  441. ((unsigned)BBIndex), CurrentCluster, CurrentPosition++});
  442. }
  443. CurrentCluster++;
  444. } else { // This is a function name specifier.
  445. // Function aliases are separated using '/'. We use the first function
  446. // name for the cluster info mapping and delegate all other aliases to
  447. // this one.
  448. SmallVector<StringRef, 4> Aliases;
  449. S.split(Aliases, '/');
  450. for (size_t i = 1; i < Aliases.size(); ++i)
  451. FuncAliasMap.try_emplace(Aliases[i], Aliases.front());
  452. // Prepare for parsing clusters of this function name.
  453. // Start a new cluster map for this function name.
  454. FI = ProgramBBClusterInfo.try_emplace(Aliases.front()).first;
  455. CurrentCluster = 0;
  456. FuncBBIDs.clear();
  457. }
  458. }
  459. return Error::success();
  460. }
  461. bool BasicBlockSections::doInitialization(Module &M) {
  462. if (!MBuf)
  463. return false;
  464. if (auto Err = getBBClusterInfo(MBuf, ProgramBBClusterInfo, FuncAliasMap))
  465. report_fatal_error(std::move(Err));
  466. return false;
  467. }
  468. void BasicBlockSections::getAnalysisUsage(AnalysisUsage &AU) const {
  469. AU.setPreservesAll();
  470. MachineFunctionPass::getAnalysisUsage(AU);
  471. }
  472. MachineFunctionPass *
  473. llvm::createBasicBlockSectionsPass(const MemoryBuffer *Buf) {
  474. return new BasicBlockSections(Buf);
  475. }