LLVM  5.0.0
MipsLongBranch.cpp
Go to the documentation of this file.
1 //===-- MipsLongBranch.cpp - Emit long branches ---------------------------===//
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 //
10 // This pass expands a branch or jump instruction into a long branch if its
11 // offset is too large to fit into its immediate field.
12 //
13 // FIXME: Fix pc-region jump instructions which cross 256MB segment boundaries.
14 //===----------------------------------------------------------------------===//
15 
19 #include "Mips.h"
20 #include "MipsInstrInfo.h"
21 #include "MipsMachineFunction.h"
22 #include "MipsSubtarget.h"
23 #include "MipsTargetMachine.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/Statistic.h"
26 #include "llvm/ADT/StringRef.h"
33 #include "llvm/IR/DebugLoc.h"
38 #include <cassert>
39 #include <cstdint>
40 #include <iterator>
41 
42 using namespace llvm;
43 
44 #define DEBUG_TYPE "mips-long-branch"
45 
46 STATISTIC(LongBranches, "Number of long branches.");
47 
49  "skip-mips-long-branch",
50  cl::init(false),
51  cl::desc("MIPS: Skip long branch pass."),
52  cl::Hidden);
53 
55  "force-mips-long-branch",
56  cl::init(false),
57  cl::desc("MIPS: Expand all branches to long format."),
58  cl::Hidden);
59 
60 namespace {
61 
62  typedef MachineBasicBlock::iterator Iter;
63  typedef MachineBasicBlock::reverse_iterator ReverseIter;
64 
65  struct MBBInfo {
66  uint64_t Size = 0;
67  uint64_t Address;
68  bool HasLongBranch = false;
69  MachineInstr *Br = nullptr;
70 
71  MBBInfo() = default;
72  };
73 
74  class MipsLongBranch : public MachineFunctionPass {
75  public:
76  static char ID;
77 
78  MipsLongBranch()
80 
81  StringRef getPassName() const override { return "Mips Long Branch"; }
82 
83  bool runOnMachineFunction(MachineFunction &F) override;
84 
85  MachineFunctionProperties getRequiredProperties() const override {
88  }
89 
90  private:
91  void splitMBB(MachineBasicBlock *MBB);
92  void initMBBInfo();
93  int64_t computeOffset(const MachineInstr *Br);
94  void replaceBranch(MachineBasicBlock &MBB, Iter Br, const DebugLoc &DL,
95  MachineBasicBlock *MBBOpnd);
96  void expandToLongBranch(MBBInfo &Info);
97 
98  MachineFunction *MF;
99  SmallVector<MBBInfo, 16> MBBInfos;
100  bool IsPIC;
101  MipsABIInfo ABI;
102  unsigned LongBranchSeqSize;
103  };
104 
105  char MipsLongBranch::ID = 0;
106 
107 } // end anonymous namespace
108 
109 /// Iterate over list of Br's operands and search for a MachineBasicBlock
110 /// operand.
112  for (unsigned I = 0, E = Br.getDesc().getNumOperands(); I < E; ++I) {
113  const MachineOperand &MO = Br.getOperand(I);
114 
115  if (MO.isMBB())
116  return MO.getMBB();
117  }
118 
119  llvm_unreachable("This instruction does not have an MBB operand.");
120 }
121 
122 // Traverse the list of instructions backwards until a non-debug instruction is
123 // found or it reaches E.
124 static ReverseIter getNonDebugInstr(ReverseIter B, const ReverseIter &E) {
125  for (; B != E; ++B)
126  if (!B->isDebugValue())
127  return B;
128 
129  return E;
130 }
131 
132 // Split MBB if it has two direct jumps/branches.
133 void MipsLongBranch::splitMBB(MachineBasicBlock *MBB) {
134  ReverseIter End = MBB->rend();
135  ReverseIter LastBr = getNonDebugInstr(MBB->rbegin(), End);
136 
137  // Return if MBB has no branch instructions.
138  if ((LastBr == End) ||
139  (!LastBr->isConditionalBranch() && !LastBr->isUnconditionalBranch()))
140  return;
141 
142  ReverseIter FirstBr = getNonDebugInstr(std::next(LastBr), End);
143 
144  // MBB has only one branch instruction if FirstBr is not a branch
145  // instruction.
146  if ((FirstBr == End) ||
147  (!FirstBr->isConditionalBranch() && !FirstBr->isUnconditionalBranch()))
148  return;
149 
150  assert(!FirstBr->isIndirectBranch() && "Unexpected indirect branch found.");
151 
152  // Create a new MBB. Move instructions in MBB to the newly created MBB.
153  MachineBasicBlock *NewMBB =
154  MF->CreateMachineBasicBlock(MBB->getBasicBlock());
155 
156  // Insert NewMBB and fix control flow.
157  MachineBasicBlock *Tgt = getTargetMBB(*FirstBr);
158  NewMBB->transferSuccessors(MBB);
159  NewMBB->removeSuccessor(Tgt, true);
160  MBB->addSuccessor(NewMBB);
161  MBB->addSuccessor(Tgt);
162  MF->insert(std::next(MachineFunction::iterator(MBB)), NewMBB);
163 
164  NewMBB->splice(NewMBB->end(), MBB, LastBr.getReverse(), MBB->end());
165 }
166 
167 // Fill MBBInfos.
168 void MipsLongBranch::initMBBInfo() {
169  // Split the MBBs if they have two branches. Each basic block should have at
170  // most one branch after this loop is executed.
171  for (auto &MBB : *MF)
172  splitMBB(&MBB);
173 
174  MF->RenumberBlocks();
175  MBBInfos.clear();
176  MBBInfos.resize(MF->size());
177 
178  const MipsInstrInfo *TII =
179  static_cast<const MipsInstrInfo *>(MF->getSubtarget().getInstrInfo());
180  for (unsigned I = 0, E = MBBInfos.size(); I < E; ++I) {
181  MachineBasicBlock *MBB = MF->getBlockNumbered(I);
182 
183  // Compute size of MBB.
185  MI != MBB->instr_end(); ++MI)
186  MBBInfos[I].Size += TII->getInstSizeInBytes(*MI);
187 
188  // Search for MBB's branch instruction.
189  ReverseIter End = MBB->rend();
190  ReverseIter Br = getNonDebugInstr(MBB->rbegin(), End);
191 
192  if ((Br != End) && !Br->isIndirectBranch() &&
193  (Br->isConditionalBranch() || (Br->isUnconditionalBranch() && IsPIC)))
194  MBBInfos[I].Br = &*Br;
195  }
196 }
197 
198 // Compute offset of branch in number of bytes.
199 int64_t MipsLongBranch::computeOffset(const MachineInstr *Br) {
200  int64_t Offset = 0;
201  int ThisMBB = Br->getParent()->getNumber();
202  int TargetMBB = getTargetMBB(*Br)->getNumber();
203 
204  // Compute offset of a forward branch.
205  if (ThisMBB < TargetMBB) {
206  for (int N = ThisMBB + 1; N < TargetMBB; ++N)
207  Offset += MBBInfos[N].Size;
208 
209  return Offset + 4;
210  }
211 
212  // Compute offset of a backward branch.
213  for (int N = ThisMBB; N >= TargetMBB; --N)
214  Offset += MBBInfos[N].Size;
215 
216  return -Offset + 4;
217 }
218 
219 // Replace Br with a branch which has the opposite condition code and a
220 // MachineBasicBlock operand MBBOpnd.
221 void MipsLongBranch::replaceBranch(MachineBasicBlock &MBB, Iter Br,
222  const DebugLoc &DL,
223  MachineBasicBlock *MBBOpnd) {
224  const MipsInstrInfo *TII = static_cast<const MipsInstrInfo *>(
225  MBB.getParent()->getSubtarget().getInstrInfo());
226  unsigned NewOpc = TII->getOppositeBranchOpc(Br->getOpcode());
227  const MCInstrDesc &NewDesc = TII->get(NewOpc);
228 
229  MachineInstrBuilder MIB = BuildMI(MBB, Br, DL, NewDesc);
230 
231  for (unsigned I = 0, E = Br->getDesc().getNumOperands(); I < E; ++I) {
232  MachineOperand &MO = Br->getOperand(I);
233 
234  if (!MO.isReg()) {
235  assert(MO.isMBB() && "MBB operand expected.");
236  break;
237  }
238 
239  MIB.addReg(MO.getReg());
240  }
241 
242  MIB.addMBB(MBBOpnd);
243 
244  if (Br->hasDelaySlot()) {
245  // Bundle the instruction in the delay slot to the newly created branch
246  // and erase the original branch.
247  assert(Br->isBundledWithSucc());
248  MachineBasicBlock::instr_iterator II = Br.getInstrIterator();
249  MIBundleBuilder(&*MIB).append((++II)->removeFromBundle());
250  }
251  Br->eraseFromParent();
252 }
253 
254 // Expand branch instructions to long branches.
255 // TODO: This function has to be fixed for beqz16 and bnez16, because it
256 // currently assumes that all branches have 16-bit offsets, and will produce
257 // wrong code if branches whose allowed offsets are [-128, -126, ..., 126]
258 // are present.
259 void MipsLongBranch::expandToLongBranch(MBBInfo &I) {
261  MachineBasicBlock *MBB = I.Br->getParent(), *TgtMBB = getTargetMBB(*I.Br);
262  DebugLoc DL = I.Br->getDebugLoc();
263  const BasicBlock *BB = MBB->getBasicBlock();
265  MachineBasicBlock *LongBrMBB = MF->CreateMachineBasicBlock(BB);
266  const MipsSubtarget &Subtarget =
267  static_cast<const MipsSubtarget &>(MF->getSubtarget());
268  const MipsInstrInfo *TII =
269  static_cast<const MipsInstrInfo *>(Subtarget.getInstrInfo());
270 
271  MF->insert(FallThroughMBB, LongBrMBB);
272  MBB->replaceSuccessor(TgtMBB, LongBrMBB);
273 
274  if (IsPIC) {
275  MachineBasicBlock *BalTgtMBB = MF->CreateMachineBasicBlock(BB);
276  MF->insert(FallThroughMBB, BalTgtMBB);
277  LongBrMBB->addSuccessor(BalTgtMBB);
278  BalTgtMBB->addSuccessor(TgtMBB);
279 
280  // We must select between the MIPS32r6/MIPS64r6 BAL (which is a normal
281  // instruction) and the pre-MIPS32r6/MIPS64r6 definition (which is an
282  // pseudo-instruction wrapping BGEZAL).
283  unsigned BalOp = Subtarget.hasMips32r6() ? Mips::BAL : Mips::BAL_BR;
284 
285  if (!ABI.IsN64()) {
286  // $longbr:
287  // addiu $sp, $sp, -8
288  // sw $ra, 0($sp)
289  // lui $at, %hi($tgt - $baltgt)
290  // bal $baltgt
291  // addiu $at, $at, %lo($tgt - $baltgt)
292  // $baltgt:
293  // addu $at, $ra, $at
294  // lw $ra, 0($sp)
295  // jr $at
296  // addiu $sp, $sp, 8
297  // $fallthrough:
298  //
299 
300  Pos = LongBrMBB->begin();
301 
302  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::ADDiu), Mips::SP)
303  .addReg(Mips::SP).addImm(-8);
304  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::SW)).addReg(Mips::RA)
305  .addReg(Mips::SP).addImm(0);
306 
307  // LUi and ADDiu instructions create 32-bit offset of the target basic
308  // block from the target of BAL instruction. We cannot use immediate
309  // value for this offset because it cannot be determined accurately when
310  // the program has inline assembly statements. We therefore use the
311  // relocation expressions %hi($tgt-$baltgt) and %lo($tgt-$baltgt) which
312  // are resolved during the fixup, so the values will always be correct.
313  //
314  // Since we cannot create %hi($tgt-$baltgt) and %lo($tgt-$baltgt)
315  // expressions at this point (it is possible only at the MC layer),
316  // we replace LUi and ADDiu with pseudo instructions
317  // LONG_BRANCH_LUi and LONG_BRANCH_ADDiu, and add both basic
318  // blocks as operands to these instructions. When lowering these pseudo
319  // instructions to LUi and ADDiu in the MC layer, we will create
320  // %hi($tgt-$baltgt) and %lo($tgt-$baltgt) expressions and add them as
321  // operands to lowered instructions.
322 
323  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::LONG_BRANCH_LUi), Mips::AT)
324  .addMBB(TgtMBB).addMBB(BalTgtMBB);
325  MIBundleBuilder(*LongBrMBB, Pos)
326  .append(BuildMI(*MF, DL, TII->get(BalOp)).addMBB(BalTgtMBB))
327  .append(BuildMI(*MF, DL, TII->get(Mips::LONG_BRANCH_ADDiu), Mips::AT)
328  .addReg(Mips::AT)
329  .addMBB(TgtMBB)
330  .addMBB(BalTgtMBB));
331 
332  Pos = BalTgtMBB->begin();
333 
334  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::ADDu), Mips::AT)
335  .addReg(Mips::RA).addReg(Mips::AT);
336  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::LW), Mips::RA)
337  .addReg(Mips::SP).addImm(0);
338 
339  // In NaCl, modifying the sp is not allowed in branch delay slot.
340  if (Subtarget.isTargetNaCl())
341  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::ADDiu), Mips::SP)
342  .addReg(Mips::SP).addImm(8);
343 
344  if (Subtarget.hasMips32r6())
345  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JALR))
346  .addReg(Mips::ZERO).addReg(Mips::AT);
347  else
348  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JR)).addReg(Mips::AT);
349 
350  if (Subtarget.isTargetNaCl()) {
351  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::NOP));
352  // Bundle-align the target of indirect branch JR.
353  TgtMBB->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
354  } else
355  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::ADDiu), Mips::SP)
356  .addReg(Mips::SP).addImm(8);
357 
358  BalTgtMBB->rbegin()->bundleWithPred();
359  } else {
360  // $longbr:
361  // daddiu $sp, $sp, -16
362  // sd $ra, 0($sp)
363  // daddiu $at, $zero, %hi($tgt - $baltgt)
364  // dsll $at, $at, 16
365  // bal $baltgt
366  // daddiu $at, $at, %lo($tgt - $baltgt)
367  // $baltgt:
368  // daddu $at, $ra, $at
369  // ld $ra, 0($sp)
370  // jr64 $at
371  // daddiu $sp, $sp, 16
372  // $fallthrough:
373  //
374 
375  // We assume the branch is within-function, and that offset is within
376  // +/- 2GB. High 32 bits will therefore always be zero.
377 
378  // Note that this will work even if the offset is negative, because
379  // of the +1 modification that's added in that case. For example, if the
380  // offset is -1MB (0xFFFFFFFFFFF00000), the computation for %higher is
381  //
382  // 0xFFFFFFFFFFF00000 + 0x80008000 = 0x000000007FF08000
383  //
384  // and the bits [47:32] are zero. For %highest
385  //
386  // 0xFFFFFFFFFFF00000 + 0x800080008000 = 0x000080007FF08000
387  //
388  // and the bits [63:48] are zero.
389 
390  Pos = LongBrMBB->begin();
391 
392  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::DADDiu), Mips::SP_64)
393  .addReg(Mips::SP_64).addImm(-16);
394  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::SD)).addReg(Mips::RA_64)
395  .addReg(Mips::SP_64).addImm(0);
396  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::LONG_BRANCH_DADDiu),
397  Mips::AT_64).addReg(Mips::ZERO_64)
398  .addMBB(TgtMBB, MipsII::MO_ABS_HI).addMBB(BalTgtMBB);
399  BuildMI(*LongBrMBB, Pos, DL, TII->get(Mips::DSLL), Mips::AT_64)
400  .addReg(Mips::AT_64).addImm(16);
401 
402  MIBundleBuilder(*LongBrMBB, Pos)
403  .append(BuildMI(*MF, DL, TII->get(BalOp)).addMBB(BalTgtMBB))
404  .append(
405  BuildMI(*MF, DL, TII->get(Mips::LONG_BRANCH_DADDiu), Mips::AT_64)
406  .addReg(Mips::AT_64)
407  .addMBB(TgtMBB, MipsII::MO_ABS_LO)
408  .addMBB(BalTgtMBB));
409 
410  Pos = BalTgtMBB->begin();
411 
412  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::DADDu), Mips::AT_64)
413  .addReg(Mips::RA_64).addReg(Mips::AT_64);
414  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::LD), Mips::RA_64)
415  .addReg(Mips::SP_64).addImm(0);
416 
417  if (Subtarget.hasMips64r6())
418  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JALR64))
419  .addReg(Mips::ZERO_64).addReg(Mips::AT_64);
420  else
421  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JR64)).addReg(Mips::AT_64);
422 
423  BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::DADDiu), Mips::SP_64)
424  .addReg(Mips::SP_64).addImm(16);
425  BalTgtMBB->rbegin()->bundleWithPred();
426  }
427 
428  assert(LongBrMBB->size() + BalTgtMBB->size() == LongBranchSeqSize);
429  } else {
430  // $longbr:
431  // j $tgt
432  // nop
433  // $fallthrough:
434  //
435  Pos = LongBrMBB->begin();
436  LongBrMBB->addSuccessor(TgtMBB);
437  MIBundleBuilder(*LongBrMBB, Pos)
438  .append(BuildMI(*MF, DL, TII->get(Mips::J)).addMBB(TgtMBB))
439  .append(BuildMI(*MF, DL, TII->get(Mips::NOP)));
440 
441  assert(LongBrMBB->size() == LongBranchSeqSize);
442  }
443 
444  if (I.Br->isUnconditionalBranch()) {
445  // Change branch destination.
446  assert(I.Br->getDesc().getNumOperands() == 1);
447  I.Br->RemoveOperand(0);
448  I.Br->addOperand(MachineOperand::CreateMBB(LongBrMBB));
449  } else
450  // Change branch destination and reverse condition.
451  replaceBranch(*MBB, I.Br, DL, &*FallThroughMBB);
452 }
453 
454 static void emitGPDisp(MachineFunction &F, const MipsInstrInfo *TII) {
455  MachineBasicBlock &MBB = F.front();
457  DebugLoc DL = MBB.findDebugLoc(MBB.begin());
458  BuildMI(MBB, I, DL, TII->get(Mips::LUi), Mips::V0)
459  .addExternalSymbol("_gp_disp", MipsII::MO_ABS_HI);
460  BuildMI(MBB, I, DL, TII->get(Mips::ADDiu), Mips::V0)
461  .addReg(Mips::V0).addExternalSymbol("_gp_disp", MipsII::MO_ABS_LO);
462  MBB.removeLiveIn(Mips::V0);
463 }
464 
465 bool MipsLongBranch::runOnMachineFunction(MachineFunction &F) {
466  const MipsSubtarget &STI =
467  static_cast<const MipsSubtarget &>(F.getSubtarget());
468  const MipsInstrInfo *TII =
469  static_cast<const MipsInstrInfo *>(STI.getInstrInfo());
470 
471 
472  const TargetMachine& TM = F.getTarget();
473  IsPIC = TM.isPositionIndependent();
474  ABI = static_cast<const MipsTargetMachine &>(TM).getABI();
475 
476  LongBranchSeqSize =
477  !IsPIC ? 2 : (ABI.IsN64() ? 10 : (!STI.isTargetNaCl() ? 9 : 10));
478 
479  if (STI.inMips16Mode() || !STI.enableLongBranchPass())
480  return false;
481  if (IsPIC && static_cast<const MipsTargetMachine &>(TM).getABI().IsO32() &&
482  F.getInfo<MipsFunctionInfo>()->globalBaseRegSet())
483  emitGPDisp(F, TII);
484 
485  if (SkipLongBranch)
486  return true;
487 
488  MF = &F;
489  initMBBInfo();
490 
491  SmallVectorImpl<MBBInfo>::iterator I, E = MBBInfos.end();
492  bool EverMadeChange = false, MadeChange = true;
493 
494  while (MadeChange) {
495  MadeChange = false;
496 
497  for (I = MBBInfos.begin(); I != E; ++I) {
498  // Skip if this MBB doesn't have a branch or the branch has already been
499  // converted to a long branch.
500  if (!I->Br || I->HasLongBranch)
501  continue;
502 
503  int ShVal = STI.inMicroMipsMode() ? 2 : 4;
504  int64_t Offset = computeOffset(I->Br) / ShVal;
505 
506  if (STI.isTargetNaCl()) {
507  // The offset calculation does not include sandboxing instructions
508  // that will be added later in the MC layer. Since at this point we
509  // don't know the exact amount of code that "sandboxing" will add, we
510  // conservatively estimate that code will not grow more than 100%.
511  Offset *= 2;
512  }
513 
514  // Check if offset fits into 16-bit immediate field of branches.
515  if (!ForceLongBranch && isInt<16>(Offset))
516  continue;
517 
518  I->HasLongBranch = true;
519  I->Size += LongBranchSeqSize * 4;
520  ++LongBranches;
521  EverMadeChange = MadeChange = true;
522  }
523  }
524 
525  if (!EverMadeChange)
526  return true;
527 
528  // Compute basic block addresses.
529  if (IsPIC) {
530  uint64_t Address = 0;
531 
532  for (I = MBBInfos.begin(); I != E; Address += I->Size, ++I)
533  I->Address = Address;
534  }
535 
536  // Do the expansion.
537  for (I = MBBInfos.begin(); I != E; ++I)
538  if (I->HasLongBranch)
539  expandToLongBranch(*I);
540 
541  MF->RenumberBlocks();
542 
543  return true;
544 }
545 
546 /// createMipsLongBranchPass - Returns a pass that converts branches to long
547 /// branches.
548 FunctionPass *llvm::createMipsLongBranchPass() { return new MipsLongBranch(); }
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
Return the number of bytes of code the specified instruction may be.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
instr_iterator instr_begin()
instr_iterator instr_end()
STATISTIC(NumFunctions,"Total number of functions")
MachineBasicBlock * getMBB() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
DataLayout DL
const MipsInstrInfo * getInstrInfo() const override
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:276
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:298
A debug info location.
Definition: DebugLoc.h:34
virtual unsigned getOppositeBranchOpc(unsigned Opc) const =0
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
static void emitGPDisp(MachineFunction &F, const MipsInstrInfo *TII)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:465
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol address.
Definition: MipsBaseInfo.h:52
const MachineBasicBlock & front() const
#define F(x, y, z)
Definition: MD5.cpp:55
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
reverse_iterator rend()
reverse_iterator rbegin()
BasicBlockListType::iterator iterator
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:139
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
static cl::opt< bool > SkipLongBranch("skip-mips-long-branch", cl::init(false), cl::desc("MIPS: Skip long branch pass."), cl::Hidden)
bool isPositionIndependent() const
static const unsigned End
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
bool inMicroMipsMode() const
bool inMips16Mode() const
bool hasMips32r6() const
Iterator for intrusive lists based on ilist_node.
bool isTargetNaCl() const
#define E
Definition: LargeTest.cpp:27
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
#define B
Definition: LargeTest.cpp:24
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
const size_t N
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
bool hasMips64r6() const
typename SuperClass::iterator iterator
Definition: SmallVector.h:325
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineFunctionProperties & set(Property P)
static const unsigned MIPS_NACL_BUNDLE_ALIGN
Definition: MipsMCNaCl.h:18
Representation of each machine instruction.
Definition: MachineInstr.h:59
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0)
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
#define I(x, y, z)
Definition: MD5.cpp:58
static cl::opt< bool > ForceLongBranch("force-mips-long-branch", cl::init(false), cl::desc("MIPS: Expand all branches to long format."), cl::Hidden)
FunctionPass * createMipsLongBranchPass()
createMipsLongBranchPass - Returns a pass that converts branches to long branches.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
bool enableLongBranchPass() const
Instructions::iterator instr_iterator
unsigned getReg() const
getReg - Returns the register number.
MIBundleBuilder & append(MachineInstr *MI)
Insert MI into MBB by appending it to the instructions in the bundle.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
static ReverseIter getNonDebugInstr(ReverseIter B, const ReverseIter &E)
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:210
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static MachineBasicBlock * getTargetMBB(const MachineInstr &Br)
Iterate over list of Br's operands and search for a MachineBasicBlock operand.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Properties which a MachineFunction may have at a given point in time.
Helper class for constructing bundles of MachineInstrs.