LLVM  9.0.0svn
MachineFunction.cpp
Go to the documentation of this file.
1 //===- MachineFunction.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Collect native machine code information for a function. This allows
10 // target-specific information about the generated code to be stored with each
11 // function.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/BitVector.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/DenseSet.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Twine.h"
41 #include "llvm/Config/llvm-config.h"
42 #include "llvm/IR/Attributes.h"
43 #include "llvm/IR/BasicBlock.h"
44 #include "llvm/IR/Constant.h"
45 #include "llvm/IR/DataLayout.h"
46 #include "llvm/IR/DerivedTypes.h"
47 #include "llvm/IR/Function.h"
48 #include "llvm/IR/GlobalValue.h"
49 #include "llvm/IR/Instruction.h"
50 #include "llvm/IR/Instructions.h"
51 #include "llvm/IR/Metadata.h"
52 #include "llvm/IR/Module.h"
54 #include "llvm/IR/Value.h"
55 #include "llvm/MC/MCContext.h"
56 #include "llvm/MC/MCSymbol.h"
57 #include "llvm/MC/SectionKind.h"
58 #include "llvm/Support/Casting.h"
60 #include "llvm/Support/Compiler.h"
62 #include "llvm/Support/Debug.h"
67 #include <algorithm>
68 #include <cassert>
69 #include <cstddef>
70 #include <cstdint>
71 #include <iterator>
72 #include <string>
73 #include <utility>
74 #include <vector>
75 
76 using namespace llvm;
77 
78 #define DEBUG_TYPE "codegen"
79 
80 static cl::opt<unsigned>
81 AlignAllFunctions("align-all-functions",
82  cl::desc("Force the alignment of all functions."),
83  cl::init(0), cl::Hidden);
84 
87 
88  switch(Prop) {
89  case P::FailedISel: return "FailedISel";
90  case P::IsSSA: return "IsSSA";
91  case P::Legalized: return "Legalized";
92  case P::NoPHIs: return "NoPHIs";
93  case P::NoVRegs: return "NoVRegs";
94  case P::RegBankSelected: return "RegBankSelected";
95  case P::Selected: return "Selected";
96  case P::TracksLiveness: return "TracksLiveness";
97  }
98  llvm_unreachable("Invalid machine function property");
99 }
100 
101 // Pin the vtable to this file.
102 void MachineFunction::Delegate::anchor() {}
103 
105  const char *Separator = "";
106  for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
107  if (!Properties[I])
108  continue;
109  OS << Separator << getPropertyName(static_cast<Property>(I));
110  Separator = ", ";
111  }
112 }
113 
114 //===----------------------------------------------------------------------===//
115 // MachineFunction implementation
116 //===----------------------------------------------------------------------===//
117 
118 // Out-of-line virtual method.
120 
122  MBB->getParent()->DeleteMachineBasicBlock(MBB);
123 }
124 
125 static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
126  const Function &F) {
127  if (F.hasFnAttribute(Attribute::StackAlignment))
128  return F.getFnStackAlignment();
129  return STI->getFrameLowering()->getStackAlignment();
130 }
131 
133  const LLVMTargetMachine &Target,
134  const TargetSubtargetInfo &STI,
135  unsigned FunctionNum, MachineModuleInfo &mmi)
136  : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
137  FunctionNumber = FunctionNum;
138  init();
139 }
140 
141 void MachineFunction::handleInsertion(MachineInstr &MI) {
142  if (TheDelegate)
143  TheDelegate->MF_HandleInsertion(MI);
144 }
145 
146 void MachineFunction::handleRemoval(MachineInstr &MI) {
147  if (TheDelegate)
148  TheDelegate->MF_HandleRemoval(MI);
149 }
150 
151 void MachineFunction::init() {
152  // Assume the function starts in SSA form with correct liveness.
155  if (STI->getRegisterInfo())
156  RegInfo = new (Allocator) MachineRegisterInfo(this);
157  else
158  RegInfo = nullptr;
159 
160  MFInfo = nullptr;
161  // We can realign the stack if the target supports it and the user hasn't
162  // explicitly asked us not to.
163  bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
164  !F.hasFnAttribute("no-realign-stack");
165  FrameInfo = new (Allocator) MachineFrameInfo(
166  getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
167  /*ForceRealign=*/CanRealignSP &&
168  F.hasFnAttribute(Attribute::StackAlignment));
169 
170  if (F.hasFnAttribute(Attribute::StackAlignment))
171  FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
172 
173  ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
174  Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
175 
176  // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
177  // FIXME: Use Function::optForSize().
178  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
179  Alignment = std::max(Alignment,
181 
182  if (AlignAllFunctions)
183  Alignment = AlignAllFunctions;
184 
185  JumpTableInfo = nullptr;
186 
188  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
189  WinEHInfo = new (Allocator) WinEHFuncInfo();
190  }
191 
193  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
194  WasmEHInfo = new (Allocator) WasmEHFuncInfo();
195  }
196 
197  assert(Target.isCompatibleDataLayout(getDataLayout()) &&
198  "Can't create a MachineFunction using a Module with a "
199  "Target-incompatible DataLayout attached\n");
200 
201  PSVManager =
202  llvm::make_unique<PseudoSourceValueManager>(*(getSubtarget().
203  getInstrInfo()));
204 }
205 
207  clear();
208 }
209 
210 void MachineFunction::clear() {
211  Properties.reset();
212  // Don't call destructors on MachineInstr and MachineOperand. All of their
213  // memory comes from the BumpPtrAllocator which is about to be purged.
214  //
215  // Do call MachineBasicBlock destructors, it contains std::vectors.
216  for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
217  I->Insts.clearAndLeakNodesUnsafely();
218  MBBNumbering.clear();
219 
220  InstructionRecycler.clear(Allocator);
221  OperandRecycler.clear(Allocator);
222  BasicBlockRecycler.clear(Allocator);
223  CodeViewAnnotations.clear();
225  if (RegInfo) {
226  RegInfo->~MachineRegisterInfo();
227  Allocator.Deallocate(RegInfo);
228  }
229  if (MFInfo) {
230  MFInfo->~MachineFunctionInfo();
231  Allocator.Deallocate(MFInfo);
232  }
233 
234  FrameInfo->~MachineFrameInfo();
235  Allocator.Deallocate(FrameInfo);
236 
237  ConstantPool->~MachineConstantPool();
238  Allocator.Deallocate(ConstantPool);
239 
240  if (JumpTableInfo) {
241  JumpTableInfo->~MachineJumpTableInfo();
242  Allocator.Deallocate(JumpTableInfo);
243  }
244 
245  if (WinEHInfo) {
246  WinEHInfo->~WinEHFuncInfo();
247  Allocator.Deallocate(WinEHInfo);
248  }
249 
250  if (WasmEHInfo) {
251  WasmEHInfo->~WasmEHFuncInfo();
252  Allocator.Deallocate(WasmEHInfo);
253  }
254 }
255 
257  return F.getParent()->getDataLayout();
258 }
259 
260 /// Get the JumpTableInfo for this function.
261 /// If it does not already exist, allocate one.
263 getOrCreateJumpTableInfo(unsigned EntryKind) {
264  if (JumpTableInfo) return JumpTableInfo;
265 
266  JumpTableInfo = new (Allocator)
268  return JumpTableInfo;
269 }
270 
271 /// Should we be emitting segmented stack stuff for the function
273  return getFunction().hasFnAttribute("split-stack");
274 }
275 
276 /// This discards all of the MachineBasicBlock numbers and recomputes them.
277 /// This guarantees that the MBB numbers are sequential, dense, and match the
278 /// ordering of the blocks within the function. If a specific MachineBasicBlock
279 /// is specified, only that block and those after it are renumbered.
281  if (empty()) { MBBNumbering.clear(); return; }
282  MachineFunction::iterator MBBI, E = end();
283  if (MBB == nullptr)
284  MBBI = begin();
285  else
286  MBBI = MBB->getIterator();
287 
288  // Figure out the block number this should have.
289  unsigned BlockNo = 0;
290  if (MBBI != begin())
291  BlockNo = std::prev(MBBI)->getNumber() + 1;
292 
293  for (; MBBI != E; ++MBBI, ++BlockNo) {
294  if (MBBI->getNumber() != (int)BlockNo) {
295  // Remove use of the old number.
296  if (MBBI->getNumber() != -1) {
297  assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
298  "MBB number mismatch!");
299  MBBNumbering[MBBI->getNumber()] = nullptr;
300  }
301 
302  // If BlockNo is already taken, set that block's number to -1.
303  if (MBBNumbering[BlockNo])
304  MBBNumbering[BlockNo]->setNumber(-1);
305 
306  MBBNumbering[BlockNo] = &*MBBI;
307  MBBI->setNumber(BlockNo);
308  }
309  }
310 
311  // Okay, all the blocks are renumbered. If we have compactified the block
312  // numbering, shrink MBBNumbering now.
313  assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
314  MBBNumbering.resize(BlockNo);
315 }
316 
317 /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'.
319  const DebugLoc &DL,
320  bool NoImp) {
321  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
322  MachineInstr(*this, MCID, DL, NoImp);
323 }
324 
325 /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
326 /// identical in all ways except the instruction has no parent, prev, or next.
327 MachineInstr *
329  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
330  MachineInstr(*this, *Orig);
331 }
332 
334  MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
335  MachineInstr *FirstClone = nullptr;
337  while (true) {
338  MachineInstr *Cloned = CloneMachineInstr(&*I);
339  MBB.insert(InsertBefore, Cloned);
340  if (FirstClone == nullptr) {
341  FirstClone = Cloned;
342  } else {
343  Cloned->bundleWithPred();
344  }
345 
346  if (!I->isBundledWithSucc())
347  break;
348  ++I;
349  }
350  return *FirstClone;
351 }
352 
353 /// Delete the given MachineInstr.
354 ///
355 /// This function also serves as the MachineInstr destructor - the real
356 /// ~MachineInstr() destructor must be empty.
357 void
359  // Strip it for parts. The operand array and the MI object itself are
360  // independently recyclable.
361  if (MI->Operands)
362  deallocateOperandArray(MI->CapOperands, MI->Operands);
363  // Don't call ~MachineInstr() which must be trivial anyway because
364  // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
365  // destructors.
366  InstructionRecycler.Deallocate(Allocator, MI);
367 }
368 
369 /// Allocate a new MachineBasicBlock. Use this instead of
370 /// `new MachineBasicBlock'.
373  return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
374  MachineBasicBlock(*this, bb);
375 }
376 
377 /// Delete the given MachineBasicBlock.
378 void
380  assert(MBB->getParent() == this && "MBB parent mismatch!");
381  MBB->~MachineBasicBlock();
382  BasicBlockRecycler.Deallocate(Allocator, MBB);
383 }
384 
386  MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
387  unsigned base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
388  SyncScope::ID SSID, AtomicOrdering Ordering,
389  AtomicOrdering FailureOrdering) {
390  return new (Allocator)
391  MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges,
392  SSID, Ordering, FailureOrdering);
393 }
394 
397  int64_t Offset, uint64_t Size) {
398  if (MMO->getValue())
399  return new (Allocator)
401  MMO->getOffset()+Offset),
402  MMO->getFlags(), Size, MMO->getBaseAlignment(),
403  AAMDNodes(), nullptr, MMO->getSyncScopeID(),
404  MMO->getOrdering(), MMO->getFailureOrdering());
405  return new (Allocator)
407  MMO->getOffset()+Offset),
408  MMO->getFlags(), Size, MMO->getBaseAlignment(),
409  AAMDNodes(), nullptr, MMO->getSyncScopeID(),
410  MMO->getOrdering(), MMO->getFailureOrdering());
411 }
412 
415  const AAMDNodes &AAInfo) {
416  MachinePointerInfo MPI = MMO->getValue() ?
417  MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
419 
420  return new (Allocator)
421  MachineMemOperand(MPI, MMO->getFlags(), MMO->getSize(),
422  MMO->getBaseAlignment(), AAInfo,
423  MMO->getRanges(), MMO->getSyncScopeID(),
424  MMO->getOrdering(), MMO->getFailureOrdering());
425 }
426 
427 MachineInstr::ExtraInfo *
429  MCSymbol *PreInstrSymbol,
430  MCSymbol *PostInstrSymbol) {
431  return MachineInstr::ExtraInfo::create(Allocator, MMOs, PreInstrSymbol,
432  PostInstrSymbol);
433 }
434 
436  char *Dest = Allocator.Allocate<char>(Name.size() + 1);
437  llvm::copy(Name, Dest);
438  Dest[Name.size()] = 0;
439  return Dest;
440 }
441 
443  unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs();
444  unsigned Size = MachineOperand::getRegMaskSize(NumRegs);
445  uint32_t *Mask = Allocator.Allocate<uint32_t>(Size);
446  memset(Mask, 0, Size * sizeof(Mask[0]));
447  return Mask;
448 }
449 
450 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
452  print(dbgs());
453 }
454 #endif
455 
457  return getFunction().getName();
458 }
459 
460 void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
461  OS << "# Machine code for function " << getName() << ": ";
462  getProperties().print(OS);
463  OS << '\n';
464 
465  // Print Frame Information
466  FrameInfo->print(*this, OS);
467 
468  // Print JumpTable Information
469  if (JumpTableInfo)
470  JumpTableInfo->print(OS);
471 
472  // Print Constant Pool
473  ConstantPool->print(OS);
474 
476 
477  if (RegInfo && !RegInfo->livein_empty()) {
478  OS << "Function Live Ins: ";
480  I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
481  OS << printReg(I->first, TRI);
482  if (I->second)
483  OS << " in " << printReg(I->second, TRI);
484  if (std::next(I) != E)
485  OS << ", ";
486  }
487  OS << '\n';
488  }
489 
492  for (const auto &BB : *this) {
493  OS << '\n';
494  // If we print the whole function, print it at its most verbose level.
495  BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
496  }
497 
498  OS << "\n# End machine code for function " << getName() << ".\n\n";
499 }
500 
501 namespace llvm {
502 
503  template<>
506 
507  static std::string getGraphName(const MachineFunction *F) {
508  return ("CFG for '" + F->getName() + "' function").str();
509  }
510 
511  std::string getNodeLabel(const MachineBasicBlock *Node,
512  const MachineFunction *Graph) {
513  std::string OutStr;
514  {
515  raw_string_ostream OSS(OutStr);
516 
517  if (isSimple()) {
518  OSS << printMBBReference(*Node);
519  if (const BasicBlock *BB = Node->getBasicBlock())
520  OSS << ": " << BB->getName();
521  } else
522  Node->print(OSS);
523  }
524 
525  if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
526 
527  // Process string output to make it nicer...
528  for (unsigned i = 0; i != OutStr.length(); ++i)
529  if (OutStr[i] == '\n') { // Left justify
530  OutStr[i] = '\\';
531  OutStr.insert(OutStr.begin()+i+1, 'l');
532  }
533  return OutStr;
534  }
535  };
536 
537 } // end namespace llvm
538 
540 {
541 #ifndef NDEBUG
542  ViewGraph(this, "mf" + getName());
543 #else
544  errs() << "MachineFunction::viewCFG is only available in debug builds on "
545  << "systems with Graphviz or gv!\n";
546 #endif // NDEBUG
547 }
548 
550 {
551 #ifndef NDEBUG
552  ViewGraph(this, "mf" + getName(), true);
553 #else
554  errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
555  << "systems with Graphviz or gv!\n";
556 #endif // NDEBUG
557 }
558 
559 /// Add the specified physical register as a live-in value and
560 /// create a corresponding virtual register for it.
561 unsigned MachineFunction::addLiveIn(unsigned PReg,
562  const TargetRegisterClass *RC) {
564  unsigned VReg = MRI.getLiveInVirtReg(PReg);
565  if (VReg) {
566  const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
567  (void)VRegRC;
568  // A physical register can be added several times.
569  // Between two calls, the register class of the related virtual register
570  // may have been constrained to match some operation constraints.
571  // In that case, check that the current register class includes the
572  // physical register and is a sub class of the specified RC.
573  assert((VRegRC == RC || (VRegRC->contains(PReg) &&
574  RC->hasSubClassEq(VRegRC))) &&
575  "Register class mismatch!");
576  return VReg;
577  }
578  VReg = MRI.createVirtualRegister(RC);
579  MRI.addLiveIn(PReg, VReg);
580  return VReg;
581 }
582 
583 /// Return the MCSymbol for the specified non-empty jump table.
584 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
585 /// normal 'L' label is returned.
587  bool isLinkerPrivate) const {
588  const DataLayout &DL = getDataLayout();
589  assert(JumpTableInfo && "No jump tables");
590  assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
591 
592  StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
593  : DL.getPrivateGlobalPrefix();
595  raw_svector_ostream(Name)
596  << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
597  return Ctx.getOrCreateSymbol(Name);
598 }
599 
600 /// Return a function-local symbol to represent the PIC base.
602  const DataLayout &DL = getDataLayout();
603  return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
604  Twine(getFunctionNumber()) + "$pb");
605 }
606 
607 /// \name Exception Handling
608 /// \{
609 
612  unsigned N = LandingPads.size();
613  for (unsigned i = 0; i < N; ++i) {
614  LandingPadInfo &LP = LandingPads[i];
615  if (LP.LandingPadBlock == LandingPad)
616  return LP;
617  }
618 
619  LandingPads.push_back(LandingPadInfo(LandingPad));
620  return LandingPads[N];
621 }
622 
624  MCSymbol *BeginLabel, MCSymbol *EndLabel) {
625  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
626  LP.BeginLabels.push_back(BeginLabel);
627  LP.EndLabels.push_back(EndLabel);
628 }
629 
631  MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
632  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
633  LP.LandingPadLabel = LandingPadLabel;
634 
635  const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
636  if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
637  if (const auto *PF =
638  dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()))
639  getMMI().addPersonality(PF);
640 
641  if (LPI->isCleanup())
642  addCleanup(LandingPad);
643 
644  // FIXME: New EH - Add the clauses in reverse order. This isn't 100%
645  // correct, but we need to do it this way because of how the DWARF EH
646  // emitter processes the clauses.
647  for (unsigned I = LPI->getNumClauses(); I != 0; --I) {
648  Value *Val = LPI->getClause(I - 1);
649  if (LPI->isCatch(I - 1)) {
650  addCatchTypeInfo(LandingPad,
651  dyn_cast<GlobalValue>(Val->stripPointerCasts()));
652  } else {
653  // Add filters in a list.
654  auto *CVal = cast<Constant>(Val);
656  for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
657  II != IE; ++II)
658  FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
659 
660  addFilterTypeInfo(LandingPad, FilterList);
661  }
662  }
663 
664  } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) {
665  for (unsigned I = CPI->getNumArgOperands(); I != 0; --I) {
666  Value *TypeInfo = CPI->getArgOperand(I - 1)->stripPointerCasts();
667  addCatchTypeInfo(LandingPad, dyn_cast<GlobalValue>(TypeInfo));
668  }
669 
670  } else {
671  assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!");
672  }
673 
674  return LandingPadLabel;
675 }
676 
679  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
680  for (unsigned N = TyInfo.size(); N; --N)
681  LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
682 }
683 
686  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
687  std::vector<unsigned> IdsInFilter(TyInfo.size());
688  for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
689  IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
690  LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
691 }
692 
694  bool TidyIfNoBeginLabels) {
695  for (unsigned i = 0; i != LandingPads.size(); ) {
696  LandingPadInfo &LandingPad = LandingPads[i];
697  if (LandingPad.LandingPadLabel &&
698  !LandingPad.LandingPadLabel->isDefined() &&
699  (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
700  LandingPad.LandingPadLabel = nullptr;
701 
702  // Special case: we *should* emit LPs with null LP MBB. This indicates
703  // "nounwind" case.
704  if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
705  LandingPads.erase(LandingPads.begin() + i);
706  continue;
707  }
708 
709  if (TidyIfNoBeginLabels) {
710  for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
711  MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
712  MCSymbol *EndLabel = LandingPad.EndLabels[j];
713  if ((BeginLabel->isDefined() || (LPMap && (*LPMap)[BeginLabel] != 0)) &&
714  (EndLabel->isDefined() || (LPMap && (*LPMap)[EndLabel] != 0)))
715  continue;
716 
717  LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
718  LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
719  --j;
720  --e;
721  }
722 
723  // Remove landing pads with no try-ranges.
724  if (LandingPads[i].BeginLabels.empty()) {
725  LandingPads.erase(LandingPads.begin() + i);
726  continue;
727  }
728  }
729 
730  // If there is no landing pad, ensure that the list of typeids is empty.
731  // If the only typeid is a cleanup, this is the same as having no typeids.
732  if (!LandingPad.LandingPadBlock ||
733  (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
734  LandingPad.TypeIds.clear();
735  ++i;
736  }
737 }
738 
740  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
741  LP.TypeIds.push_back(0);
742 }
743 
745  const Function *Filter,
746  const BlockAddress *RecoverBA) {
747  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
748  SEHHandler Handler;
749  Handler.FilterOrFinally = Filter;
750  Handler.RecoverBA = RecoverBA;
751  LP.SEHHandlers.push_back(Handler);
752 }
753 
755  const Function *Cleanup) {
756  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
757  SEHHandler Handler;
758  Handler.FilterOrFinally = Cleanup;
759  Handler.RecoverBA = nullptr;
760  LP.SEHHandlers.push_back(Handler);
761 }
762 
764  ArrayRef<unsigned> Sites) {
765  LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
766 }
767 
769  for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
770  if (TypeInfos[i] == TI) return i + 1;
771 
772  TypeInfos.push_back(TI);
773  return TypeInfos.size();
774 }
775 
776 int MachineFunction::getFilterIDFor(std::vector<unsigned> &TyIds) {
777  // If the new filter coincides with the tail of an existing filter, then
778  // re-use the existing filter. Folding filters more than this requires
779  // re-ordering filters and/or their elements - probably not worth it.
780  for (std::vector<unsigned>::iterator I = FilterEnds.begin(),
781  E = FilterEnds.end(); I != E; ++I) {
782  unsigned i = *I, j = TyIds.size();
783 
784  while (i && j)
785  if (FilterIds[--i] != TyIds[--j])
786  goto try_next;
787 
788  if (!j)
789  // The new filter coincides with range [i, end) of the existing filter.
790  return -(1 + i);
791 
792 try_next:;
793  }
794 
795  // Add the new filter.
796  int FilterID = -(1 + FilterIds.size());
797  FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
798  FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
799  FilterEnds.push_back(FilterIds.size());
800  FilterIds.push_back(0); // terminator
801  return FilterID;
802 }
803 
804 /// \}
805 
806 //===----------------------------------------------------------------------===//
807 // MachineJumpTableInfo implementation
808 //===----------------------------------------------------------------------===//
809 
810 /// Return the size of each entry in the jump table.
812  // The size of a jump table entry is 4 bytes unless the entry is just the
813  // address of a block, in which case it is the pointer size.
814  switch (getEntryKind()) {
816  return TD.getPointerSize();
818  return 8;
822  return 4;
824  return 0;
825  }
826  llvm_unreachable("Unknown jump table encoding!");
827 }
828 
829 /// Return the alignment of each entry in the jump table.
831  // The alignment of a jump table entry is the alignment of int32 unless the
832  // entry is just the address of a block, in which case it is the pointer
833  // alignment.
834  switch (getEntryKind()) {
836  return TD.getPointerABIAlignment(0);
838  return TD.getABIIntegerTypeAlignment(64);
842  return TD.getABIIntegerTypeAlignment(32);
844  return 1;
845  }
846  llvm_unreachable("Unknown jump table encoding!");
847 }
848 
849 /// Create a new jump table entry in the jump table info.
851  const std::vector<MachineBasicBlock*> &DestBBs) {
852  assert(!DestBBs.empty() && "Cannot create an empty jump table!");
853  JumpTables.push_back(MachineJumpTableEntry(DestBBs));
854  return JumpTables.size()-1;
855 }
856 
857 /// If Old is the target of any jump tables, update the jump tables to branch
858 /// to New instead.
860  MachineBasicBlock *New) {
861  assert(Old != New && "Not making a change?");
862  bool MadeChange = false;
863  for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
864  ReplaceMBBInJumpTable(i, Old, New);
865  return MadeChange;
866 }
867 
868 /// If Old is a target of the jump tables, update the jump table to branch to
869 /// New instead.
871  MachineBasicBlock *Old,
872  MachineBasicBlock *New) {
873  assert(Old != New && "Not making a change?");
874  bool MadeChange = false;
875  MachineJumpTableEntry &JTE = JumpTables[Idx];
876  for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
877  if (JTE.MBBs[j] == Old) {
878  JTE.MBBs[j] = New;
879  MadeChange = true;
880  }
881  return MadeChange;
882 }
883 
885  if (JumpTables.empty()) return;
886 
887  OS << "Jump Tables:\n";
888 
889  for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
890  OS << printJumpTableEntryReference(i) << ": ";
891  for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
892  OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
893  }
894 
895  OS << '\n';
896 }
897 
898 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
900 #endif
901 
903  return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
904 }
905 
906 //===----------------------------------------------------------------------===//
907 // MachineConstantPool implementation
908 //===----------------------------------------------------------------------===//
909 
910 void MachineConstantPoolValue::anchor() {}
911 
913  if (isMachineConstantPoolEntry())
914  return Val.MachineCPVal->getType();
915  return Val.ConstVal->getType();
916 }
917 
919  if (isMachineConstantPoolEntry())
920  return true;
921  return Val.ConstVal->needsRelocation();
922 }
923 
926  if (needsRelocation())
928  switch (DL->getTypeAllocSize(getType())) {
929  case 4:
931  case 8:
933  case 16:
935  case 32:
937  default:
938  return SectionKind::getReadOnly();
939  }
940 }
941 
943  // A constant may be a member of both Constants and MachineCPVsSharingEntries,
944  // so keep track of which we've deleted to avoid double deletions.
946  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
947  if (Constants[i].isMachineConstantPoolEntry()) {
948  Deleted.insert(Constants[i].Val.MachineCPVal);
949  delete Constants[i].Val.MachineCPVal;
950  }
952  MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
953  I != E; ++I) {
954  if (Deleted.count(*I) == 0)
955  delete *I;
956  }
957 }
958 
959 /// Test whether the given two constants can be allocated the same constant pool
960 /// entry.
961 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
962  const DataLayout &DL) {
963  // Handle the trivial case quickly.
964  if (A == B) return true;
965 
966  // If they have the same type but weren't the same constant, quickly
967  // reject them.
968  if (A->getType() == B->getType()) return false;
969 
970  // We can't handle structs or arrays.
971  if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
972  isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
973  return false;
974 
975  // For now, only support constants with the same size.
976  uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
977  if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
978  return false;
979 
980  Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
981 
982  // Try constant folding a bitcast of both instructions to an integer. If we
983  // get two identical ConstantInt's, then we are good to share them. We use
984  // the constant folding APIs to do this so that we get the benefit of
985  // DataLayout.
986  if (isa<PointerType>(A->getType()))
987  A = ConstantFoldCastOperand(Instruction::PtrToInt,
988  const_cast<Constant *>(A), IntTy, DL);
989  else if (A->getType() != IntTy)
990  A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
991  IntTy, DL);
992  if (isa<PointerType>(B->getType()))
993  B = ConstantFoldCastOperand(Instruction::PtrToInt,
994  const_cast<Constant *>(B), IntTy, DL);
995  else if (B->getType() != IntTy)
996  B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
997  IntTy, DL);
998 
999  return A == B;
1000 }
1001 
1002 /// Create a new entry in the constant pool or return an existing one.
1003 /// User must specify the log2 of the minimum required alignment for the object.
1005  unsigned Alignment) {
1006  assert(Alignment && "Alignment must be specified!");
1007  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1008 
1009  // Check to see if we already have this constant.
1010  //
1011  // FIXME, this could be made much more efficient for large constant pools.
1012  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1013  if (!Constants[i].isMachineConstantPoolEntry() &&
1014  CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1015  if ((unsigned)Constants[i].getAlignment() < Alignment)
1016  Constants[i].Alignment = Alignment;
1017  return i;
1018  }
1019 
1020  Constants.push_back(MachineConstantPoolEntry(C, Alignment));
1021  return Constants.size()-1;
1022 }
1023 
1025  unsigned Alignment) {
1026  assert(Alignment && "Alignment must be specified!");
1027  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1028 
1029  // Check to see if we already have this constant.
1030  //
1031  // FIXME, this could be made much more efficient for large constant pools.
1032  int Idx = V->getExistingMachineCPValue(this, Alignment);
1033  if (Idx != -1) {
1034  MachineCPVsSharingEntries.insert(V);
1035  return (unsigned)Idx;
1036  }
1037 
1038  Constants.push_back(MachineConstantPoolEntry(V, Alignment));
1039  return Constants.size()-1;
1040 }
1041 
1043  if (Constants.empty()) return;
1044 
1045  OS << "Constant Pool:\n";
1046  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
1047  OS << " cp#" << i << ": ";
1048  if (Constants[i].isMachineConstantPoolEntry())
1049  Constants[i].Val.MachineCPVal->print(OS);
1050  else
1051  Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1052  OS << ", align=" << Constants[i].getAlignment();
1053  OS << "\n";
1054  }
1055 }
1056 
1057 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1059 #endif
Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
uint64_t CallInst * C
void bundleWithPred()
Bundle this instruction with its predecessor.
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned getFnStackAlignment() const
Return the stack alignment for the function.
Definition: Function.h:340
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
livein_iterator livein_begin() const
static SectionKind getMergeableConst32()
Definition: SectionKind.h:194
iterator erase(iterator where)
Definition: ilist.h:266
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineFunctionProperties & reset(Property P)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:464
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
MCSymbol * addLandingPad(MachineBasicBlock *LandingPad)
Add a new panding pad, and extract the exception handling information from the landingpad instruction...
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:293
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
iterator begin() const
Definition: ArrayRef.h:136
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
const Function * FilterOrFinally
Filter or finally function. Null indicates a catch-all.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
unsigned size() const
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur...
void push_back(const T &Elt)
Definition: SmallVector.h:217
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:137
This file contains the declarations for metadata subclasses.
EK_Inline - Jump table entries are emitted inline at their point of use.
std::string getNodeLabel(const MachineBasicBlock *Node, const MachineFunction *Graph)
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
virtual const TargetLowering * getTargetLowering() const
uint64_t getSize() const
Return the size in bytes of the memory reference.
static SectionKind getMergeableConst8()
Definition: SectionKind.h:192
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:704
static SectionKind getMergeableConst16()
Definition: SectionKind.h:193
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:320
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:863
F(f)
MachineModuleInfo & getMMI() const
Manage lifetime of a slot tracker for printing IR.
unsigned getTypeIDFor(const GlobalValue *TI)
Return the type id for the specified typeinfo. This is function wide.
uint64_t getBaseAlignment() const
Return the minimum known alignment in bytes of the base address, without the offset.
void dump() const
dump - Print the current MachineFunction to cerr, useful for debugger use.
MachineInstr * CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL, bool NoImp=false)
CreateMachineInstr - Allocate a new MachineInstr.
void DeleteMachineBasicBlock(MachineBasicBlock *MBB)
DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
unsigned getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:610
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:273
static SectionKind getMergeableConst4()
Definition: SectionKind.h:191
bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTable - If Old is a target of the jump tables, update the jump table to branch to New...
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist...
*ViewGraph Emit a dot run run gv on the postscript *then cleanup For use from the debugger *void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
Definition: GraphWriter.h:366
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about jump tables.
void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter, const BlockAddress *RecoverBA)
JTEntryKind
JTEntryKind - This enum indicates how each entry of the jump table is represented and emitted...
The address of a basic block.
Definition: Constants.h:839
void addSEHCleanupHandler(MachineBasicBlock *LandingPad, const Function *Cleanup)
void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
A description of a memory reference used in the backend.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:370
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
SmallVector< MCSymbol *, 1 > EndLabels
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
const MDNode * getRanges() const
Return the range tag for the memory reference.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
SmallVector< SEHHandler, 1 > SEHHandlers
MachineInstr & CloneMachineInstrBundle(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig)
Clones instruction or the whole instruction bundle Orig and insert into MBB before InsertBefore...
This file contains the simple types necessary to represent the attributes associated with functions a...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
int getFilterIDFor(std::vector< unsigned > &TyIds)
Return the id of the filter encoded by TyIds. This is function wide.
void Deallocate(const void *Ptr, size_t Size)
Definition: Allocator.h:277
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineInstr::ExtraInfo * createMIExtraInfo(ArrayRef< MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol=nullptr, MCSymbol *PostInstrSymbol=nullptr)
Allocate and construct an extra info structure for a MachineInstr.
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch, catchpad/ret, and cleanuppad/ret.
static bool isSimple(Instruction *I)
Context object for machine code objects.
Definition: MCContext.h:62
unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
This structure is used to retain landing pad info for the current function.
AtomicOrdering getOrdering() const
Return the atomic ordering requirements for this memory operation.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
SlotIndexes pass.
Definition: SlotIndexes.h:330
void tidyLandingPads(DenseMap< MCSymbol *, uintptr_t > *LPMap=nullptr, bool TidyIfNoBeginLabels=true)
Remap landing pad labels and remove any deleted landing pads.
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table...
livein_iterator livein_end() const
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)=0
static std::string getGraphName(const MachineFunction *F)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
EK_BlockAddress - Each entry is a plain address of block, e.g.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
unsigned getPrefFunctionAlignment() const
Return the preferred function alignment.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:701
This class is a data container for one entry in a MachineConstantPool.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const Value * getValue() const
Return the base address of the memory access.
MCContext & getContext() const
#define P(N)
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:422
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about constant pool objects...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:189
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
unsigned const MachineRegisterInfo * MRI
void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
void addInvoke(MachineBasicBlock *LandingPad, MCSymbol *BeginLabel, MCSymbol *EndLabel)
Provide the begin and end labels of an invoke style call and associate it with a try landing pad bloc...
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static unsigned getFnStackAlignment(const TargetSubtargetInfo *STI, const Function &F)
static cl::opt< unsigned > AlignAllFunctions("align-all-functions", cl::desc("Force the alignment of all functions."), cl::init(0), cl::Hidden)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
void addPersonality(const Function *Personality)
Provide the personality function for the exception information.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
SmallVector< MCSymbol *, 1 > BeginLabels
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:628
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:214
static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, const DataLayout &DL)
Test whether the given two constants can be allocated the same constant pool entry.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
std::vector< int > TypeIds
const PseudoSourceValue * getPseudoValue() const
This class describes a target machine that is implemented with the LLVM target-independent code gener...
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
self_iterator getIterator()
Definition: ilist_node.h:81
Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:840
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:528
virtual void MF_HandleInsertion(MachineInstr &MI)=0
Callback after an insertion. This should not modify the MI directly.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Abstract base class for all machine specific constantpool value subclasses.
static wasm::ValType getType(const TargetRegisterClass *RC)
This class contains a discriminated union of information about pointers in memory operands...
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream...
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
void addCleanup(MachineBasicBlock *LandingPad)
Add a cleanup action for a landing pad.
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to &#39;dot...
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:239
Iterator for intrusive lists based on ilist_node.
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:846
Module.h This file contains the declarations for the Module class.
iterator end() const
Definition: ArrayRef.h:137
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:643
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:202
unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.cpp:735
void addCatchTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue *> TyInfo)
Provide the catch typeinfo for a landing pad.
uint32_t * allocateRegMask()
Allocate and initialize a register mask with NumRegister bits.
void clear(AllocatorType &Allocator)
Release all the tracked allocations to the allocator.
virtual void MF_HandleRemoval(MachineInstr &MI)=0
Callback before a removal. This should not modify the MI directly.
static void deleteNode(NodeTy *V)
Definition: ilist.h:41
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef< unsigned > Sites)
Map the landing pad&#39;s EH symbol to the call site indexes.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:247
Target - Wrapper for Target specific information.
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
MachineJumpTableEntry - One jump table in the jump table info.
MachineBasicBlock * LandingPadBlock
Flags
Flags values. These may be or&#39;d together.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
TargetSubtargetInfo - Generic base class for all target subtargets.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:435
static const char * getPropertyName(MachineFunctionProperties::Property Prop)
Representation of each machine instruction.
Definition: MachineInstr.h:63
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:122
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:213
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Flags getFlags() const
Return the raw flags of the source value,.
virtual const TargetFrameLowering * getFrameLowering() const
SectionKind getSectionKind(const DataLayout *DL) const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
uint32_t Size
Definition: Profile.cpp:46
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
void dump() const
dump - Call print(cerr) to be called from the debugger.
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinFunctionAlignment() const
Return the minimum function alignment.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:482
aarch64 promote const
LandingPadInfo & getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad)
Find or create an LandingPadInfo for the specified MachineBasicBlock.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
LLVM Value Representation.
Definition: Value.h:72
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1298
MachineFunction(const Function &F, const LLVMTargetMachine &Target, const TargetSubtargetInfo &STI, unsigned FunctionNum, MachineModuleInfo &MMI)
void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array)
Dellocate an array of MachineOperands and recycle the memory.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:418
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
MCSymbol * getPICBaseSymbol() const
getPICBaseSymbol - Return a function-local symbol to represent the PIC base.
const BlockAddress * RecoverBA
Address of block to recover at. Null for a finally handler.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock *> &DestBBs)
createJumpTableIndex - Create a new jump table.
void dump() const
dump - Call to stderr.
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:37
unsigned getLiveInVirtReg(unsigned PReg) const
getLiveInVirtReg - If PReg is a live-in physical register, return the corresponding live-in physical ...
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1237
VariableDbgInfoMapTy VariableDbgInfos
static SectionKind getReadOnly()
Definition: SectionKind.h:181
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry...
This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
void addFilterTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue *> TyInfo)
Provide the filter typeinfo for a landing pad.