blob: 98f2124209aa6c903389f413d22d4e9aefbb7887 [file] [log] [blame]
Richard Sandiford312425f2013-05-20 14:23:08 +00001//===-- SystemZLongBranch.cpp - Branch lengthening for SystemZ ------------===//
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//
Richard Sandifordbdbb8af2013-08-05 10:58:53 +000010// This pass makes sure that all branches are in range. There are several ways
11// in which this could be done. One aggressive approach is to assume that all
12// branches are in range and successively replace those that turn out not
13// to be in range with a longer form (branch relaxation). A simple
14// implementation is to continually walk through the function relaxing
15// branches until no more changes are needed and a fixed point is reached.
16// However, in the pathological worst case, this implementation is
17// quadratic in the number of blocks; relaxing branch N can make branch N-1
18// go out of range, which in turn can make branch N-2 go out of range,
19// and so on.
Richard Sandiford312425f2013-05-20 14:23:08 +000020//
21// An alternative approach is to assume that all branches must be
22// converted to their long forms, then reinstate the short forms of
23// branches that, even under this pessimistic assumption, turn out to be
24// in range (branch shortening). This too can be implemented as a function
25// walk that is repeated until a fixed point is reached. In general,
26// the result of shortening is not as good as that of relaxation, and
27// shortening is also quadratic in the worst case; shortening branch N
28// can bring branch N-1 in range of the short form, which in turn can do
29// the same for branch N-2, and so on. The main advantage of shortening
30// is that each walk through the function produces valid code, so it is
31// possible to stop at any point after the first walk. The quadraticness
32// could therefore be handled with a maximum pass count, although the
33// question then becomes: what maximum count should be used?
34//
35// On SystemZ, long branches are only needed for functions bigger than 64k,
36// which are relatively rare to begin with, and the long branch sequences
37// are actually relatively cheap. It therefore doesn't seem worth spending
38// much compilation time on the problem. Instead, the approach we take is:
39//
Richard Sandiford03528f32013-05-22 09:57:57 +000040// (1) Work out the address that each block would have if no branches
41// need relaxing. Exit the pass early if all branches are in range
42// according to this assumption.
43//
44// (2) Work out the address that each block would have if all branches
45// need relaxing.
46//
47// (3) Walk through the block calculating the final address of each instruction
48// and relaxing those that need to be relaxed. For backward branches,
49// this check uses the final address of the target block, as calculated
50// earlier in the walk. For forward branches, this check uses the
51// address of the target block that was calculated in (2). Both checks
52// give a conservatively-correct range.
Richard Sandiford312425f2013-05-20 14:23:08 +000053//
54//===----------------------------------------------------------------------===//
55
Richard Sandiford312425f2013-05-20 14:23:08 +000056#include "SystemZTargetMachine.h"
57#include "llvm/ADT/Statistic.h"
58#include "llvm/CodeGen/MachineFunctionPass.h"
59#include "llvm/CodeGen/MachineInstrBuilder.h"
60#include "llvm/IR/Function.h"
Richard Sandiford312425f2013-05-20 14:23:08 +000061#include "llvm/Support/MathExtras.h"
62#include "llvm/Target/TargetInstrInfo.h"
63#include "llvm/Target/TargetMachine.h"
64#include "llvm/Target/TargetRegisterInfo.h"
65
66using namespace llvm;
67
Chandler Carruth84e68b22014-04-22 02:41:26 +000068#define DEBUG_TYPE "systemz-long-branch"
69
Richard Sandiford312425f2013-05-20 14:23:08 +000070STATISTIC(LongBranches, "Number of long branches.");
71
72namespace {
Richard Sandifordc2312692014-03-06 10:38:30 +000073// Represents positional information about a basic block.
74struct MBBInfo {
75 // The address that we currently assume the block has.
76 uint64_t Address;
Richard Sandiford312425f2013-05-20 14:23:08 +000077
Richard Sandifordc2312692014-03-06 10:38:30 +000078 // The size of the block in bytes, excluding terminators.
79 // This value never changes.
80 uint64_t Size;
Richard Sandiford312425f2013-05-20 14:23:08 +000081
Richard Sandifordc2312692014-03-06 10:38:30 +000082 // The minimum alignment of the block, as a log2 value.
83 // This value never changes.
84 unsigned Alignment;
Richard Sandiford312425f2013-05-20 14:23:08 +000085
Richard Sandifordc2312692014-03-06 10:38:30 +000086 // The number of terminators in this block. This value never changes.
87 unsigned NumTerminators;
Richard Sandiford312425f2013-05-20 14:23:08 +000088
Richard Sandifordc2312692014-03-06 10:38:30 +000089 MBBInfo()
90 : Address(0), Size(0), Alignment(0), NumTerminators(0) {}
91};
Richard Sandiford312425f2013-05-20 14:23:08 +000092
Richard Sandifordc2312692014-03-06 10:38:30 +000093// Represents the state of a block terminator.
94struct TerminatorInfo {
95 // If this terminator is a relaxable branch, this points to the branch
96 // instruction, otherwise it is null.
97 MachineInstr *Branch;
Richard Sandiford312425f2013-05-20 14:23:08 +000098
Richard Sandifordc2312692014-03-06 10:38:30 +000099 // The address that we currently assume the terminator has.
100 uint64_t Address;
Richard Sandiford312425f2013-05-20 14:23:08 +0000101
Richard Sandifordc2312692014-03-06 10:38:30 +0000102 // The current size of the terminator in bytes.
103 uint64_t Size;
Richard Sandiford312425f2013-05-20 14:23:08 +0000104
Richard Sandifordc2312692014-03-06 10:38:30 +0000105 // If Branch is nonnull, this is the number of the target block,
106 // otherwise it is unused.
107 unsigned TargetBlock;
Richard Sandiford312425f2013-05-20 14:23:08 +0000108
Richard Sandifordc2312692014-03-06 10:38:30 +0000109 // If Branch is nonnull, this is the length of the longest relaxed form,
110 // otherwise it is zero.
111 unsigned ExtraRelaxSize;
Richard Sandiford312425f2013-05-20 14:23:08 +0000112
Craig Topper062a2ba2014-04-25 05:30:21 +0000113 TerminatorInfo() : Branch(nullptr), Size(0), TargetBlock(0),
114 ExtraRelaxSize(0) {}
Richard Sandifordc2312692014-03-06 10:38:30 +0000115};
Richard Sandiford312425f2013-05-20 14:23:08 +0000116
Richard Sandifordc2312692014-03-06 10:38:30 +0000117// Used to keep track of the current position while iterating over the blocks.
118struct BlockPosition {
119 // The address that we assume this position has.
120 uint64_t Address;
Richard Sandiford312425f2013-05-20 14:23:08 +0000121
Richard Sandifordc2312692014-03-06 10:38:30 +0000122 // The number of low bits in Address that are known to be the same
123 // as the runtime address.
124 unsigned KnownBits;
Richard Sandiford312425f2013-05-20 14:23:08 +0000125
Richard Sandifordc2312692014-03-06 10:38:30 +0000126 BlockPosition(unsigned InitialAlignment)
127 : Address(0), KnownBits(InitialAlignment) {}
128};
Richard Sandiford312425f2013-05-20 14:23:08 +0000129
Richard Sandifordc2312692014-03-06 10:38:30 +0000130class SystemZLongBranch : public MachineFunctionPass {
131public:
132 static char ID;
133 SystemZLongBranch(const SystemZTargetMachine &tm)
Craig Topper062a2ba2014-04-25 05:30:21 +0000134 : MachineFunctionPass(ID), TII(nullptr) {}
Richard Sandiford312425f2013-05-20 14:23:08 +0000135
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000136 const char *getPassName() const override {
Richard Sandifordc2312692014-03-06 10:38:30 +0000137 return "SystemZ Long Branch";
138 }
Richard Sandiford312425f2013-05-20 14:23:08 +0000139
Craig Topper9d74a5a2014-04-29 07:58:41 +0000140 bool runOnMachineFunction(MachineFunction &F) override;
Derek Schuff1dbf7a52016-04-04 17:09:25 +0000141 MachineFunctionProperties getRequiredProperties() const override {
142 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +0000143 MachineFunctionProperties::Property::NoVRegs);
Derek Schuff1dbf7a52016-04-04 17:09:25 +0000144 }
Richard Sandiford312425f2013-05-20 14:23:08 +0000145
Richard Sandifordc2312692014-03-06 10:38:30 +0000146private:
147 void skipNonTerminators(BlockPosition &Position, MBBInfo &Block);
148 void skipTerminator(BlockPosition &Position, TerminatorInfo &Terminator,
149 bool AssumeRelaxed);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000150 TerminatorInfo describeTerminator(MachineInstr &MI);
Richard Sandifordc2312692014-03-06 10:38:30 +0000151 uint64_t initMBBInfo();
152 bool mustRelaxBranch(const TerminatorInfo &Terminator, uint64_t Address);
153 bool mustRelaxABranch();
154 void setWorstCaseAddresses();
155 void splitBranchOnCount(MachineInstr *MI, unsigned AddOpcode);
156 void splitCompareBranch(MachineInstr *MI, unsigned CompareOpcode);
157 void relaxBranch(TerminatorInfo &Terminator);
158 void relaxBranches();
Richard Sandiford312425f2013-05-20 14:23:08 +0000159
Richard Sandifordc2312692014-03-06 10:38:30 +0000160 const SystemZInstrInfo *TII;
161 MachineFunction *MF;
162 SmallVector<MBBInfo, 16> MBBs;
163 SmallVector<TerminatorInfo, 16> Terminators;
164};
Richard Sandiford312425f2013-05-20 14:23:08 +0000165
Richard Sandifordc2312692014-03-06 10:38:30 +0000166char SystemZLongBranch::ID = 0;
Richard Sandiford312425f2013-05-20 14:23:08 +0000167
Richard Sandifordc2312692014-03-06 10:38:30 +0000168const uint64_t MaxBackwardRange = 0x10000;
169const uint64_t MaxForwardRange = 0xfffe;
170} // end anonymous namespace
Richard Sandiford312425f2013-05-20 14:23:08 +0000171
172FunctionPass *llvm::createSystemZLongBranchPass(SystemZTargetMachine &TM) {
173 return new SystemZLongBranch(TM);
174}
175
176// Position describes the state immediately before Block. Update Block
177// accordingly and move Position to the end of the block's non-terminator
178// instructions.
179void SystemZLongBranch::skipNonTerminators(BlockPosition &Position,
180 MBBInfo &Block) {
181 if (Block.Alignment > Position.KnownBits) {
182 // When calculating the address of Block, we need to conservatively
183 // assume that Block had the worst possible misalignment.
184 Position.Address += ((uint64_t(1) << Block.Alignment) -
185 (uint64_t(1) << Position.KnownBits));
186 Position.KnownBits = Block.Alignment;
187 }
188
189 // Align the addresses.
190 uint64_t AlignMask = (uint64_t(1) << Block.Alignment) - 1;
191 Position.Address = (Position.Address + AlignMask) & ~AlignMask;
192
193 // Record the block's position.
194 Block.Address = Position.Address;
195
196 // Move past the non-terminators in the block.
197 Position.Address += Block.Size;
198}
199
200// Position describes the state immediately before Terminator.
201// Update Terminator accordingly and move Position past it.
202// Assume that Terminator will be relaxed if AssumeRelaxed.
203void SystemZLongBranch::skipTerminator(BlockPosition &Position,
204 TerminatorInfo &Terminator,
205 bool AssumeRelaxed) {
206 Terminator.Address = Position.Address;
207 Position.Address += Terminator.Size;
208 if (AssumeRelaxed)
209 Position.Address += Terminator.ExtraRelaxSize;
210}
211
212// Return a description of terminator instruction MI.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000213TerminatorInfo SystemZLongBranch::describeTerminator(MachineInstr &MI) {
Richard Sandiford312425f2013-05-20 14:23:08 +0000214 TerminatorInfo Terminator;
215 Terminator.Size = TII->getInstSizeInBytes(MI);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000216 if (MI.isConditionalBranch() || MI.isUnconditionalBranch()) {
217 switch (MI.getOpcode()) {
Richard Sandiford312425f2013-05-20 14:23:08 +0000218 case SystemZ::J:
219 // Relaxes to JG, which is 2 bytes longer.
Richard Sandiford312425f2013-05-20 14:23:08 +0000220 Terminator.ExtraRelaxSize = 2;
221 break;
222 case SystemZ::BRC:
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000223 // Relaxes to BRCL, which is 2 bytes longer.
Richard Sandiford312425f2013-05-20 14:23:08 +0000224 Terminator.ExtraRelaxSize = 2;
225 break;
Richard Sandifordc2121252013-08-05 11:23:46 +0000226 case SystemZ::BRCT:
227 case SystemZ::BRCTG:
228 // Relaxes to A(G)HI and BRCL, which is 6 bytes longer.
229 Terminator.ExtraRelaxSize = 6;
230 break;
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000231 case SystemZ::CRJ:
Richard Sandiford93183ee2013-09-18 09:56:40 +0000232 case SystemZ::CLRJ:
233 // Relaxes to a C(L)R/BRCL sequence, which is 2 bytes longer.
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000234 Terminator.ExtraRelaxSize = 2;
235 break;
236 case SystemZ::CGRJ:
Richard Sandiford93183ee2013-09-18 09:56:40 +0000237 case SystemZ::CLGRJ:
238 // Relaxes to a C(L)GR/BRCL sequence, which is 4 bytes longer.
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000239 Terminator.ExtraRelaxSize = 4;
240 break;
Richard Sandiforde1d9f002013-05-29 11:58:52 +0000241 case SystemZ::CIJ:
242 case SystemZ::CGIJ:
243 // Relaxes to a C(G)HI/BRCL sequence, which is 4 bytes longer.
244 Terminator.ExtraRelaxSize = 4;
245 break;
Richard Sandiford93183ee2013-09-18 09:56:40 +0000246 case SystemZ::CLIJ:
247 case SystemZ::CLGIJ:
248 // Relaxes to a CL(G)FI/BRCL sequence, which is 6 bytes longer.
249 Terminator.ExtraRelaxSize = 6;
250 break;
Richard Sandiford312425f2013-05-20 14:23:08 +0000251 default:
252 llvm_unreachable("Unrecognized branch instruction");
253 }
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000254 Terminator.Branch = &MI;
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000255 Terminator.TargetBlock =
256 TII->getBranchInfo(MI).Target->getMBB()->getNumber();
Richard Sandiford312425f2013-05-20 14:23:08 +0000257 }
258 return Terminator;
259}
260
261// Fill MBBs and Terminators, setting the addresses on the assumption
262// that no branches need relaxation. Return the size of the function under
263// this assumption.
264uint64_t SystemZLongBranch::initMBBInfo() {
265 MF->RenumberBlocks();
266 unsigned NumBlocks = MF->size();
267
268 MBBs.clear();
269 MBBs.resize(NumBlocks);
270
271 Terminators.clear();
272 Terminators.reserve(NumBlocks);
273
274 BlockPosition Position(MF->getAlignment());
275 for (unsigned I = 0; I < NumBlocks; ++I) {
276 MachineBasicBlock *MBB = MF->getBlockNumbered(I);
277 MBBInfo &Block = MBBs[I];
278
279 // Record the alignment, for quick access.
280 Block.Alignment = MBB->getAlignment();
281
282 // Calculate the size of the fixed part of the block.
283 MachineBasicBlock::iterator MI = MBB->begin();
284 MachineBasicBlock::iterator End = MBB->end();
285 while (MI != End && !MI->isTerminator()) {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000286 Block.Size += TII->getInstSizeInBytes(*MI);
Richard Sandiford312425f2013-05-20 14:23:08 +0000287 ++MI;
288 }
289 skipNonTerminators(Position, Block);
290
291 // Add the terminators.
292 while (MI != End) {
293 if (!MI->isDebugValue()) {
294 assert(MI->isTerminator() && "Terminator followed by non-terminator");
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000295 Terminators.push_back(describeTerminator(*MI));
Richard Sandiford312425f2013-05-20 14:23:08 +0000296 skipTerminator(Position, Terminators.back(), false);
297 ++Block.NumTerminators;
298 }
299 ++MI;
300 }
301 }
302
303 return Position.Address;
304}
305
Richard Sandiford03528f32013-05-22 09:57:57 +0000306// Return true if, under current assumptions, Terminator would need to be
307// relaxed if it were placed at address Address.
308bool SystemZLongBranch::mustRelaxBranch(const TerminatorInfo &Terminator,
309 uint64_t Address) {
Richard Sandiford312425f2013-05-20 14:23:08 +0000310 if (!Terminator.Branch)
311 return false;
312
313 const MBBInfo &Target = MBBs[Terminator.TargetBlock];
Richard Sandiford03528f32013-05-22 09:57:57 +0000314 if (Address >= Target.Address) {
315 if (Address - Target.Address <= MaxBackwardRange)
Richard Sandiford312425f2013-05-20 14:23:08 +0000316 return false;
317 } else {
Richard Sandiford03528f32013-05-22 09:57:57 +0000318 if (Target.Address - Address <= MaxForwardRange)
Richard Sandiford312425f2013-05-20 14:23:08 +0000319 return false;
320 }
321
322 return true;
323}
324
325// Return true if, under current assumptions, any terminator needs
326// to be relaxed.
327bool SystemZLongBranch::mustRelaxABranch() {
Richard Sandiford28c111e2014-03-06 11:00:15 +0000328 for (auto &Terminator : Terminators)
329 if (mustRelaxBranch(Terminator, Terminator.Address))
Richard Sandiford312425f2013-05-20 14:23:08 +0000330 return true;
331 return false;
332}
333
334// Set the address of each block on the assumption that all branches
335// must be long.
336void SystemZLongBranch::setWorstCaseAddresses() {
337 SmallVector<TerminatorInfo, 16>::iterator TI = Terminators.begin();
338 BlockPosition Position(MF->getAlignment());
Richard Sandiford28c111e2014-03-06 11:00:15 +0000339 for (auto &Block : MBBs) {
340 skipNonTerminators(Position, Block);
341 for (unsigned BTI = 0, BTE = Block.NumTerminators; BTI != BTE; ++BTI) {
Richard Sandiford312425f2013-05-20 14:23:08 +0000342 skipTerminator(Position, *TI, true);
343 ++TI;
344 }
345 }
346}
347
Richard Sandifordc2121252013-08-05 11:23:46 +0000348// Split BRANCH ON COUNT MI into the addition given by AddOpcode followed
349// by a BRCL on the result.
350void SystemZLongBranch::splitBranchOnCount(MachineInstr *MI,
351 unsigned AddOpcode) {
352 MachineBasicBlock *MBB = MI->getParent();
353 DebugLoc DL = MI->getDebugLoc();
354 BuildMI(*MBB, MI, DL, TII->get(AddOpcode))
355 .addOperand(MI->getOperand(0))
356 .addOperand(MI->getOperand(1))
357 .addImm(-1);
358 MachineInstr *BRCL = BuildMI(*MBB, MI, DL, TII->get(SystemZ::BRCL))
359 .addImm(SystemZ::CCMASK_ICMP)
360 .addImm(SystemZ::CCMASK_CMP_NE)
361 .addOperand(MI->getOperand(2));
362 // The implicit use of CC is a killing use.
363 BRCL->addRegisterKilled(SystemZ::CC, &TII->getRegisterInfo());
364 MI->eraseFromParent();
365}
366
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000367// Split MI into the comparison given by CompareOpcode followed
368// a BRCL on the result.
369void SystemZLongBranch::splitCompareBranch(MachineInstr *MI,
370 unsigned CompareOpcode) {
371 MachineBasicBlock *MBB = MI->getParent();
372 DebugLoc DL = MI->getDebugLoc();
373 BuildMI(*MBB, MI, DL, TII->get(CompareOpcode))
374 .addOperand(MI->getOperand(0))
375 .addOperand(MI->getOperand(1));
376 MachineInstr *BRCL = BuildMI(*MBB, MI, DL, TII->get(SystemZ::BRCL))
Richard Sandiford3d768e32013-07-31 12:30:20 +0000377 .addImm(SystemZ::CCMASK_ICMP)
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000378 .addOperand(MI->getOperand(2))
379 .addOperand(MI->getOperand(3));
380 // The implicit use of CC is a killing use.
Richard Sandiford3d768e32013-07-31 12:30:20 +0000381 BRCL->addRegisterKilled(SystemZ::CC, &TII->getRegisterInfo());
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000382 MI->eraseFromParent();
383}
384
Richard Sandiford312425f2013-05-20 14:23:08 +0000385// Relax the branch described by Terminator.
386void SystemZLongBranch::relaxBranch(TerminatorInfo &Terminator) {
387 MachineInstr *Branch = Terminator.Branch;
388 switch (Branch->getOpcode()) {
Richard Sandiford3b105a02013-05-21 08:48:24 +0000389 case SystemZ::J:
390 Branch->setDesc(TII->get(SystemZ::JG));
391 break;
392 case SystemZ::BRC:
393 Branch->setDesc(TII->get(SystemZ::BRCL));
394 break;
Richard Sandifordc2121252013-08-05 11:23:46 +0000395 case SystemZ::BRCT:
396 splitBranchOnCount(Branch, SystemZ::AHI);
397 break;
398 case SystemZ::BRCTG:
399 splitBranchOnCount(Branch, SystemZ::AGHI);
400 break;
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000401 case SystemZ::CRJ:
402 splitCompareBranch(Branch, SystemZ::CR);
403 break;
404 case SystemZ::CGRJ:
405 splitCompareBranch(Branch, SystemZ::CGR);
406 break;
Richard Sandiforde1d9f002013-05-29 11:58:52 +0000407 case SystemZ::CIJ:
408 splitCompareBranch(Branch, SystemZ::CHI);
409 break;
410 case SystemZ::CGIJ:
411 splitCompareBranch(Branch, SystemZ::CGHI);
412 break;
Richard Sandiford93183ee2013-09-18 09:56:40 +0000413 case SystemZ::CLRJ:
414 splitCompareBranch(Branch, SystemZ::CLR);
415 break;
416 case SystemZ::CLGRJ:
417 splitCompareBranch(Branch, SystemZ::CLGR);
418 break;
419 case SystemZ::CLIJ:
420 splitCompareBranch(Branch, SystemZ::CLFI);
421 break;
422 case SystemZ::CLGIJ:
423 splitCompareBranch(Branch, SystemZ::CLGFI);
424 break;
Richard Sandiford3b105a02013-05-21 08:48:24 +0000425 default:
426 llvm_unreachable("Unrecognized branch");
427 }
Richard Sandiford312425f2013-05-20 14:23:08 +0000428
429 Terminator.Size += Terminator.ExtraRelaxSize;
430 Terminator.ExtraRelaxSize = 0;
Craig Topper062a2ba2014-04-25 05:30:21 +0000431 Terminator.Branch = nullptr;
Richard Sandiford312425f2013-05-20 14:23:08 +0000432
433 ++LongBranches;
434}
435
Richard Sandiford03528f32013-05-22 09:57:57 +0000436// Run a shortening pass and relax any branches that need to be relaxed.
Richard Sandiford312425f2013-05-20 14:23:08 +0000437void SystemZLongBranch::relaxBranches() {
Richard Sandiford03528f32013-05-22 09:57:57 +0000438 SmallVector<TerminatorInfo, 16>::iterator TI = Terminators.begin();
439 BlockPosition Position(MF->getAlignment());
Richard Sandiford28c111e2014-03-06 11:00:15 +0000440 for (auto &Block : MBBs) {
441 skipNonTerminators(Position, Block);
442 for (unsigned BTI = 0, BTE = Block.NumTerminators; BTI != BTE; ++BTI) {
Richard Sandiford03528f32013-05-22 09:57:57 +0000443 assert(Position.Address <= TI->Address &&
444 "Addresses shouldn't go forwards");
445 if (mustRelaxBranch(*TI, Position.Address))
446 relaxBranch(*TI);
447 skipTerminator(Position, *TI, false);
448 ++TI;
449 }
450 }
Richard Sandiford312425f2013-05-20 14:23:08 +0000451}
452
453bool SystemZLongBranch::runOnMachineFunction(MachineFunction &F) {
Eric Christopherfc6de422014-08-05 02:39:49 +0000454 TII = static_cast<const SystemZInstrInfo *>(F.getSubtarget().getInstrInfo());
Richard Sandiford312425f2013-05-20 14:23:08 +0000455 MF = &F;
456 uint64_t Size = initMBBInfo();
457 if (Size <= MaxForwardRange || !mustRelaxABranch())
458 return false;
459
460 setWorstCaseAddresses();
461 relaxBranches();
462 return true;
463}