BranchRelaxation.cpp 19 KB

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