BranchRelaxation.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. //===- BranchRelaxation.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. #include "llvm/ADT/SmallVector.h"
  9. #include "llvm/ADT/Statistic.h"
  10. #include "llvm/CodeGen/LivePhysRegs.h"
  11. #include "llvm/CodeGen/MachineBasicBlock.h"
  12. #include "llvm/CodeGen/MachineFunction.h"
  13. #include "llvm/CodeGen/MachineFunctionPass.h"
  14. #include "llvm/CodeGen/MachineInstr.h"
  15. #include "llvm/CodeGen/RegisterScavenging.h"
  16. #include "llvm/CodeGen/TargetInstrInfo.h"
  17. #include "llvm/CodeGen/TargetRegisterInfo.h"
  18. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  19. #include "llvm/Config/llvm-config.h"
  20. #include "llvm/IR/DebugLoc.h"
  21. #include "llvm/Pass.h"
  22. #include "llvm/Support/Compiler.h"
  23. #include "llvm/Support/Debug.h"
  24. #include "llvm/Support/Format.h"
  25. #include "llvm/Support/MathExtras.h"
  26. #include "llvm/Support/raw_ostream.h"
  27. #include <cassert>
  28. #include <cstdint>
  29. #include <iterator>
  30. #include <memory>
  31. using namespace llvm;
  32. #define DEBUG_TYPE "branch-relaxation"
  33. STATISTIC(NumSplit, "Number of basic blocks split");
  34. STATISTIC(NumConditionalRelaxed, "Number of conditional branches relaxed");
  35. STATISTIC(NumUnconditionalRelaxed, "Number of unconditional branches relaxed");
  36. #define BRANCH_RELAX_NAME "Branch relaxation pass"
  37. namespace {
  38. class BranchRelaxation : public MachineFunctionPass {
  39. /// BasicBlockInfo - Information about the offset and size of a single
  40. /// basic block.
  41. struct BasicBlockInfo {
  42. /// Offset - Distance from the beginning of the function to the beginning
  43. /// of this basic block.
  44. ///
  45. /// The offset is always aligned as required by the basic block.
  46. unsigned Offset = 0;
  47. /// Size - Size of the basic block in bytes. If the block contains
  48. /// inline assembly, this is a worst case estimate.
  49. ///
  50. /// The size does not include any alignment padding whether from the
  51. /// beginning of the block, or from an aligned jump table at the end.
  52. unsigned Size = 0;
  53. BasicBlockInfo() = default;
  54. /// Compute the offset immediately following this block. \p MBB is the next
  55. /// block.
  56. unsigned postOffset(const MachineBasicBlock &MBB) const {
  57. const unsigned PO = Offset + Size;
  58. const llvm::Align Align = MBB.getAlignment();
  59. if (Align == 1)
  60. return PO;
  61. const llvm::Align ParentAlign = MBB.getParent()->getAlignment();
  62. if (Align <= ParentAlign)
  63. return PO + offsetToAlignment(PO, Align);
  64. // The alignment of this MBB is larger than the function's alignment, so we
  65. // can't tell whether or not it will insert nops. Assume that it will.
  66. return PO + Align.value() + offsetToAlignment(PO, Align);
  67. }
  68. };
  69. SmallVector<BasicBlockInfo, 16> BlockInfo;
  70. std::unique_ptr<RegScavenger> RS;
  71. LivePhysRegs LiveRegs;
  72. MachineFunction *MF;
  73. const TargetRegisterInfo *TRI;
  74. const TargetInstrInfo *TII;
  75. bool relaxBranchInstructions();
  76. void scanFunction();
  77. MachineBasicBlock *createNewBlockAfter(MachineBasicBlock &BB);
  78. MachineBasicBlock *splitBlockBeforeInstr(MachineInstr &MI,
  79. MachineBasicBlock *DestBB);
  80. void adjustBlockOffsets(MachineBasicBlock &Start);
  81. bool isBlockInRange(const MachineInstr &MI, const MachineBasicBlock &BB) const;
  82. bool fixupConditionalBranch(MachineInstr &MI);
  83. bool fixupUnconditionalBranch(MachineInstr &MI);
  84. uint64_t computeBlockSize(const MachineBasicBlock &MBB) const;
  85. unsigned getInstrOffset(const MachineInstr &MI) const;
  86. void dumpBBs();
  87. void verify();
  88. public:
  89. static char ID;
  90. BranchRelaxation() : MachineFunctionPass(ID) {}
  91. bool runOnMachineFunction(MachineFunction &MF) override;
  92. StringRef getPassName() const override { return BRANCH_RELAX_NAME; }
  93. };
  94. } // end anonymous namespace
  95. char BranchRelaxation::ID = 0;
  96. char &llvm::BranchRelaxationPassID = BranchRelaxation::ID;
  97. INITIALIZE_PASS(BranchRelaxation, DEBUG_TYPE, BRANCH_RELAX_NAME, false, false)
  98. /// verify - check BBOffsets, BBSizes, alignment of islands
  99. void BranchRelaxation::verify() {
  100. #ifndef NDEBUG
  101. unsigned PrevNum = MF->begin()->getNumber();
  102. for (MachineBasicBlock &MBB : *MF) {
  103. const unsigned Num = MBB.getNumber();
  104. assert(isAligned(MBB.getAlignment(), BlockInfo[Num].Offset));
  105. assert(!Num || BlockInfo[PrevNum].postOffset(MBB) <= BlockInfo[Num].Offset);
  106. assert(BlockInfo[Num].Size == computeBlockSize(MBB));
  107. PrevNum = Num;
  108. }
  109. #endif
  110. }
  111. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  112. /// print block size and offset information - debugging
  113. LLVM_DUMP_METHOD void BranchRelaxation::dumpBBs() {
  114. for (auto &MBB : *MF) {
  115. const BasicBlockInfo &BBI = BlockInfo[MBB.getNumber()];
  116. dbgs() << format("%%bb.%u\toffset=%08x\t", MBB.getNumber(), BBI.Offset)
  117. << format("size=%#x\n", BBI.Size);
  118. }
  119. }
  120. #endif
  121. /// scanFunction - Do the initial scan of the function, building up
  122. /// information about each block.
  123. void BranchRelaxation::scanFunction() {
  124. BlockInfo.clear();
  125. BlockInfo.resize(MF->getNumBlockIDs());
  126. // First thing, compute the size of all basic blocks, and see if the function
  127. // has any inline assembly in it. If so, we have to be conservative about
  128. // alignment assumptions, as we don't know for sure the size of any
  129. // instructions in the inline assembly.
  130. for (MachineBasicBlock &MBB : *MF)
  131. BlockInfo[MBB.getNumber()].Size = computeBlockSize(MBB);
  132. // Compute block offsets and known bits.
  133. adjustBlockOffsets(*MF->begin());
  134. }
  135. /// computeBlockSize - Compute the size for MBB.
  136. uint64_t BranchRelaxation::computeBlockSize(const MachineBasicBlock &MBB) const {
  137. uint64_t Size = 0;
  138. for (const MachineInstr &MI : MBB)
  139. Size += TII->getInstSizeInBytes(MI);
  140. return Size;
  141. }
  142. /// getInstrOffset - Return the current offset of the specified machine
  143. /// instruction from the start of the function. This offset changes as stuff is
  144. /// moved around inside the function.
  145. unsigned BranchRelaxation::getInstrOffset(const MachineInstr &MI) const {
  146. const MachineBasicBlock *MBB = MI.getParent();
  147. // The offset is composed of two things: the sum of the sizes of all MBB's
  148. // before this instruction's block, and the offset from the start of the block
  149. // it is in.
  150. unsigned Offset = BlockInfo[MBB->getNumber()].Offset;
  151. // Sum instructions before MI in MBB.
  152. for (MachineBasicBlock::const_iterator I = MBB->begin(); &*I != &MI; ++I) {
  153. assert(I != MBB->end() && "Didn't find MI in its own basic block?");
  154. Offset += TII->getInstSizeInBytes(*I);
  155. }
  156. return Offset;
  157. }
  158. void BranchRelaxation::adjustBlockOffsets(MachineBasicBlock &Start) {
  159. unsigned PrevNum = Start.getNumber();
  160. for (auto &MBB : make_range(MachineFunction::iterator(Start), MF->end())) {
  161. unsigned Num = MBB.getNumber();
  162. if (!Num) // block zero is never changed from offset zero.
  163. continue;
  164. // Get the offset and known bits at the end of the layout predecessor.
  165. // Include the alignment of the current block.
  166. BlockInfo[Num].Offset = BlockInfo[PrevNum].postOffset(MBB);
  167. PrevNum = Num;
  168. }
  169. }
  170. /// Insert a new empty basic block and insert it after \BB
  171. MachineBasicBlock *BranchRelaxation::createNewBlockAfter(MachineBasicBlock &BB) {
  172. // Create a new MBB for the code after the OrigBB.
  173. MachineBasicBlock *NewBB =
  174. MF->CreateMachineBasicBlock(BB.getBasicBlock());
  175. MF->insert(++BB.getIterator(), NewBB);
  176. // Insert an entry into BlockInfo to align it properly with the block numbers.
  177. BlockInfo.insert(BlockInfo.begin() + NewBB->getNumber(), BasicBlockInfo());
  178. return NewBB;
  179. }
  180. /// Split the basic block containing MI into two blocks, which are joined by
  181. /// an unconditional branch. Update data structures and renumber blocks to
  182. /// account for this change and returns the newly created block.
  183. MachineBasicBlock *BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI,
  184. MachineBasicBlock *DestBB) {
  185. MachineBasicBlock *OrigBB = MI.getParent();
  186. // Create a new MBB for the code after the OrigBB.
  187. MachineBasicBlock *NewBB =
  188. MF->CreateMachineBasicBlock(OrigBB->getBasicBlock());
  189. MF->insert(++OrigBB->getIterator(), NewBB);
  190. // Splice the instructions starting with MI over to NewBB.
  191. NewBB->splice(NewBB->end(), OrigBB, MI.getIterator(), OrigBB->end());
  192. // Add an unconditional branch from OrigBB to NewBB.
  193. // Note the new unconditional branch is not being recorded.
  194. // There doesn't seem to be meaningful DebugInfo available; this doesn't
  195. // correspond to anything in the source.
  196. TII->insertUnconditionalBranch(*OrigBB, NewBB, DebugLoc());
  197. // Insert an entry into BlockInfo to align it properly with the block numbers.
  198. BlockInfo.insert(BlockInfo.begin() + NewBB->getNumber(), BasicBlockInfo());
  199. NewBB->transferSuccessors(OrigBB);
  200. OrigBB->addSuccessor(NewBB);
  201. OrigBB->addSuccessor(DestBB);
  202. // Cleanup potential unconditional branch to successor block.
  203. // Note that updateTerminator may change the size of the blocks.
  204. NewBB->updateTerminator();
  205. OrigBB->updateTerminator();
  206. // Figure out how large the OrigBB is. As the first half of the original
  207. // block, it cannot contain a tablejump. The size includes
  208. // the new jump we added. (It should be possible to do this without
  209. // recounting everything, but it's very confusing, and this is rarely
  210. // executed.)
  211. BlockInfo[OrigBB->getNumber()].Size = computeBlockSize(*OrigBB);
  212. // Figure out how large the NewMBB is. As the second half of the original
  213. // block, it may contain a tablejump.
  214. BlockInfo[NewBB->getNumber()].Size = computeBlockSize(*NewBB);
  215. // All BBOffsets following these blocks must be modified.
  216. adjustBlockOffsets(*OrigBB);
  217. // Need to fix live-in lists if we track liveness.
  218. if (TRI->trackLivenessAfterRegAlloc(*MF))
  219. computeAndAddLiveIns(LiveRegs, *NewBB);
  220. ++NumSplit;
  221. return NewBB;
  222. }
  223. /// isBlockInRange - Returns true if the distance between specific MI and
  224. /// specific BB can fit in MI's displacement field.
  225. bool BranchRelaxation::isBlockInRange(
  226. const MachineInstr &MI, const MachineBasicBlock &DestBB) const {
  227. int64_t BrOffset = getInstrOffset(MI);
  228. int64_t DestOffset = BlockInfo[DestBB.getNumber()].Offset;
  229. if (TII->isBranchOffsetInRange(MI.getOpcode(), DestOffset - BrOffset))
  230. return true;
  231. LLVM_DEBUG(dbgs() << "Out of range branch to destination "
  232. << printMBBReference(DestBB) << " from "
  233. << printMBBReference(*MI.getParent()) << " to "
  234. << DestOffset << " offset " << DestOffset - BrOffset << '\t'
  235. << MI);
  236. return false;
  237. }
  238. /// fixupConditionalBranch - Fix up a conditional branch whose destination is
  239. /// too far away to fit in its displacement field. It is converted to an inverse
  240. /// conditional branch + an unconditional branch to the destination.
  241. bool BranchRelaxation::fixupConditionalBranch(MachineInstr &MI) {
  242. DebugLoc DL = MI.getDebugLoc();
  243. MachineBasicBlock *MBB = MI.getParent();
  244. MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
  245. MachineBasicBlock *NewBB = nullptr;
  246. SmallVector<MachineOperand, 4> Cond;
  247. auto insertUncondBranch = [&](MachineBasicBlock *MBB,
  248. MachineBasicBlock *DestBB) {
  249. unsigned &BBSize = BlockInfo[MBB->getNumber()].Size;
  250. int NewBrSize = 0;
  251. TII->insertUnconditionalBranch(*MBB, DestBB, DL, &NewBrSize);
  252. BBSize += NewBrSize;
  253. };
  254. auto insertBranch = [&](MachineBasicBlock *MBB, MachineBasicBlock *TBB,
  255. MachineBasicBlock *FBB,
  256. SmallVectorImpl<MachineOperand>& Cond) {
  257. unsigned &BBSize = BlockInfo[MBB->getNumber()].Size;
  258. int NewBrSize = 0;
  259. TII->insertBranch(*MBB, TBB, FBB, Cond, DL, &NewBrSize);
  260. BBSize += NewBrSize;
  261. };
  262. auto removeBranch = [&](MachineBasicBlock *MBB) {
  263. unsigned &BBSize = BlockInfo[MBB->getNumber()].Size;
  264. int RemovedSize = 0;
  265. TII->removeBranch(*MBB, &RemovedSize);
  266. BBSize -= RemovedSize;
  267. };
  268. auto finalizeBlockChanges = [&](MachineBasicBlock *MBB,
  269. MachineBasicBlock *NewBB) {
  270. // Keep the block offsets up to date.
  271. adjustBlockOffsets(*MBB);
  272. // Need to fix live-in lists if we track liveness.
  273. if (NewBB && TRI->trackLivenessAfterRegAlloc(*MF))
  274. computeAndAddLiveIns(LiveRegs, *NewBB);
  275. };
  276. bool Fail = TII->analyzeBranch(*MBB, TBB, FBB, Cond);
  277. assert(!Fail && "branches to be relaxed must be analyzable");
  278. (void)Fail;
  279. // Add an unconditional branch to the destination and invert the branch
  280. // condition to jump over it:
  281. // tbz L1
  282. // =>
  283. // tbnz L2
  284. // b L1
  285. // L2:
  286. bool ReversedCond = !TII->reverseBranchCondition(Cond);
  287. if (ReversedCond) {
  288. if (FBB && isBlockInRange(MI, *FBB)) {
  289. // Last MI in the BB is an unconditional branch. We can simply invert the
  290. // condition and swap destinations:
  291. // beq L1
  292. // b L2
  293. // =>
  294. // bne L2
  295. // b L1
  296. LLVM_DEBUG(dbgs() << " Invert condition and swap "
  297. "its destination with "
  298. << MBB->back());
  299. removeBranch(MBB);
  300. insertBranch(MBB, FBB, TBB, Cond);
  301. finalizeBlockChanges(MBB, nullptr);
  302. return true;
  303. }
  304. if (FBB) {
  305. // We need to split the basic block here to obtain two long-range
  306. // unconditional branches.
  307. NewBB = createNewBlockAfter(*MBB);
  308. insertUncondBranch(NewBB, FBB);
  309. // Update the succesor lists according to the transformation to follow.
  310. // Do it here since if there's no split, no update is needed.
  311. MBB->replaceSuccessor(FBB, NewBB);
  312. NewBB->addSuccessor(FBB);
  313. }
  314. // We now have an appropriate fall-through block in place (either naturally or
  315. // just created), so we can use the inverted the condition.
  316. MachineBasicBlock &NextBB = *std::next(MachineFunction::iterator(MBB));
  317. LLVM_DEBUG(dbgs() << " Insert B to " << printMBBReference(*TBB)
  318. << ", invert condition and change dest. to "
  319. << printMBBReference(NextBB) << '\n');
  320. removeBranch(MBB);
  321. // Insert a new conditional branch and a new unconditional branch.
  322. insertBranch(MBB, &NextBB, TBB, Cond);
  323. finalizeBlockChanges(MBB, NewBB);
  324. return true;
  325. }
  326. // Branch cond can't be inverted.
  327. // In this case we always add a block after the MBB.
  328. LLVM_DEBUG(dbgs() << " The branch condition can't be inverted. "
  329. << " Insert a new BB after " << MBB->back());
  330. if (!FBB)
  331. FBB = &(*std::next(MachineFunction::iterator(MBB)));
  332. // This is the block with cond. branch and the distance to TBB is too long.
  333. // beq L1
  334. // L2:
  335. // We do the following transformation:
  336. // beq NewBB
  337. // b L2
  338. // NewBB:
  339. // b L1
  340. // L2:
  341. NewBB = createNewBlockAfter(*MBB);
  342. insertUncondBranch(NewBB, TBB);
  343. LLVM_DEBUG(dbgs() << " Insert cond B to the new BB "
  344. << printMBBReference(*NewBB)
  345. << " Keep the exiting condition.\n"
  346. << " Insert B to " << printMBBReference(*FBB) << ".\n"
  347. << " In the new BB: Insert B to "
  348. << printMBBReference(*TBB) << ".\n");
  349. // Update the successor lists according to the transformation to follow.
  350. MBB->replaceSuccessor(TBB, NewBB);
  351. NewBB->addSuccessor(TBB);
  352. // Replace branch in the current (MBB) block.
  353. removeBranch(MBB);
  354. insertBranch(MBB, NewBB, FBB, Cond);
  355. finalizeBlockChanges(MBB, NewBB);
  356. return true;
  357. }
  358. bool BranchRelaxation::fixupUnconditionalBranch(MachineInstr &MI) {
  359. MachineBasicBlock *MBB = MI.getParent();
  360. unsigned OldBrSize = TII->getInstSizeInBytes(MI);
  361. MachineBasicBlock *DestBB = TII->getBranchDestBlock(MI);
  362. int64_t DestOffset = BlockInfo[DestBB->getNumber()].Offset;
  363. int64_t SrcOffset = getInstrOffset(MI);
  364. assert(!TII->isBranchOffsetInRange(MI.getOpcode(), DestOffset - SrcOffset));
  365. BlockInfo[MBB->getNumber()].Size -= OldBrSize;
  366. MachineBasicBlock *BranchBB = MBB;
  367. // If this was an expanded conditional branch, there is already a single
  368. // unconditional branch in a block.
  369. if (!MBB->empty()) {
  370. BranchBB = createNewBlockAfter(*MBB);
  371. // Add live outs.
  372. for (const MachineBasicBlock *Succ : MBB->successors()) {
  373. for (const MachineBasicBlock::RegisterMaskPair &LiveIn : Succ->liveins())
  374. BranchBB->addLiveIn(LiveIn);
  375. }
  376. BranchBB->sortUniqueLiveIns();
  377. BranchBB->addSuccessor(DestBB);
  378. MBB->replaceSuccessor(DestBB, BranchBB);
  379. }
  380. DebugLoc DL = MI.getDebugLoc();
  381. MI.eraseFromParent();
  382. BlockInfo[BranchBB->getNumber()].Size += TII->insertIndirectBranch(
  383. *BranchBB, *DestBB, DL, DestOffset - SrcOffset, RS.get());
  384. adjustBlockOffsets(*MBB);
  385. return true;
  386. }
  387. bool BranchRelaxation::relaxBranchInstructions() {
  388. bool Changed = false;
  389. // Relaxing branches involves creating new basic blocks, so re-eval
  390. // end() for termination.
  391. for (MachineFunction::iterator I = MF->begin(); I != MF->end(); ++I) {
  392. MachineBasicBlock &MBB = *I;
  393. // Empty block?
  394. MachineBasicBlock::iterator Last = MBB.getLastNonDebugInstr();
  395. if (Last == MBB.end())
  396. continue;
  397. // Expand the unconditional branch first if necessary. If there is a
  398. // conditional branch, this will end up changing the branch destination of
  399. // it to be over the newly inserted indirect branch block, which may avoid
  400. // the need to try expanding the conditional branch first, saving an extra
  401. // jump.
  402. if (Last->isUnconditionalBranch()) {
  403. // Unconditional branch destination might be unanalyzable, assume these
  404. // are OK.
  405. if (MachineBasicBlock *DestBB = TII->getBranchDestBlock(*Last)) {
  406. if (!isBlockInRange(*Last, *DestBB)) {
  407. fixupUnconditionalBranch(*Last);
  408. ++NumUnconditionalRelaxed;
  409. Changed = true;
  410. }
  411. }
  412. }
  413. // Loop over the conditional branches.
  414. MachineBasicBlock::iterator Next;
  415. for (MachineBasicBlock::iterator J = MBB.getFirstTerminator();
  416. J != MBB.end(); J = Next) {
  417. Next = std::next(J);
  418. MachineInstr &MI = *J;
  419. if (MI.isConditionalBranch()) {
  420. MachineBasicBlock *DestBB = TII->getBranchDestBlock(MI);
  421. if (!isBlockInRange(MI, *DestBB)) {
  422. if (Next != MBB.end() && Next->isConditionalBranch()) {
  423. // If there are multiple conditional branches, this isn't an
  424. // analyzable block. Split later terminators into a new block so
  425. // each one will be analyzable.
  426. splitBlockBeforeInstr(*Next, DestBB);
  427. } else {
  428. fixupConditionalBranch(MI);
  429. ++NumConditionalRelaxed;
  430. }
  431. Changed = true;
  432. // This may have modified all of the terminators, so start over.
  433. Next = MBB.getFirstTerminator();
  434. }
  435. }
  436. }
  437. }
  438. return Changed;
  439. }
  440. bool BranchRelaxation::runOnMachineFunction(MachineFunction &mf) {
  441. MF = &mf;
  442. LLVM_DEBUG(dbgs() << "***** BranchRelaxation *****\n");
  443. const TargetSubtargetInfo &ST = MF->getSubtarget();
  444. TII = ST.getInstrInfo();
  445. TRI = ST.getRegisterInfo();
  446. if (TRI->trackLivenessAfterRegAlloc(*MF))
  447. RS.reset(new RegScavenger());
  448. // Renumber all of the machine basic blocks in the function, guaranteeing that
  449. // the numbers agree with the position of the block in the function.
  450. MF->RenumberBlocks();
  451. // Do the initial scan of the function, building up information about the
  452. // sizes of each block.
  453. scanFunction();
  454. LLVM_DEBUG(dbgs() << " Basic blocks before relaxation\n"; dumpBBs(););
  455. bool MadeChange = false;
  456. while (relaxBranchInstructions())
  457. MadeChange = true;
  458. // After a while, this might be made debug-only, but it is not expensive.
  459. verify();
  460. LLVM_DEBUG(dbgs() << " Basic blocks after relaxation\n\n"; dumpBBs());
  461. BlockInfo.clear();
  462. return MadeChange;
  463. }