LLVM  10.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"
47 #include "llvm/IR/DerivedTypes.h"
48 #include "llvm/IR/Function.h"
49 #include "llvm/IR/GlobalValue.h"
50 #include "llvm/IR/Instruction.h"
51 #include "llvm/IR/Instructions.h"
52 #include "llvm/IR/Metadata.h"
53 #include "llvm/IR/Module.h"
55 #include "llvm/IR/Value.h"
56 #include "llvm/MC/MCContext.h"
57 #include "llvm/MC/MCSymbol.h"
58 #include "llvm/MC/SectionKind.h"
59 #include "llvm/Support/Casting.h"
61 #include "llvm/Support/Compiler.h"
63 #include "llvm/Support/Debug.h"
68 #include <algorithm>
69 #include <cassert>
70 #include <cstddef>
71 #include <cstdint>
72 #include <iterator>
73 #include <string>
74 #include <utility>
75 #include <vector>
76 
77 using namespace llvm;
78 
79 #define DEBUG_TYPE "codegen"
80 
81 static cl::opt<unsigned>
82 AlignAllFunctions("align-all-functions",
83  cl::desc("Force the alignment of all functions."),
84  cl::init(0), cl::Hidden);
85 
88 
89  switch(Prop) {
90  case P::FailedISel: return "FailedISel";
91  case P::IsSSA: return "IsSSA";
92  case P::Legalized: return "Legalized";
93  case P::NoPHIs: return "NoPHIs";
94  case P::NoVRegs: return "NoVRegs";
95  case P::RegBankSelected: return "RegBankSelected";
96  case P::Selected: return "Selected";
97  case P::TracksLiveness: return "TracksLiveness";
98  }
99  llvm_unreachable("Invalid machine function property");
100 }
101 
102 // Pin the vtable to this file.
103 void MachineFunction::Delegate::anchor() {}
104 
106  const char *Separator = "";
107  for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
108  if (!Properties[I])
109  continue;
110  OS << Separator << getPropertyName(static_cast<Property>(I));
111  Separator = ", ";
112  }
113 }
114 
115 //===----------------------------------------------------------------------===//
116 // MachineFunction implementation
117 //===----------------------------------------------------------------------===//
118 
119 // Out-of-line virtual method.
121 
123  MBB->getParent()->DeleteMachineBasicBlock(MBB);
124 }
125 
126 static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
127  const Function &F) {
128  if (F.hasFnAttribute(Attribute::StackAlignment))
129  return F.getFnStackAlignment();
130  return STI->getFrameLowering()->getStackAlignment();
131 }
132 
134  const LLVMTargetMachine &Target,
135  const TargetSubtargetInfo &STI,
136  unsigned FunctionNum, MachineModuleInfo &mmi)
137  : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
138  FunctionNumber = FunctionNum;
139  init();
140 }
141 
142 void MachineFunction::handleInsertion(MachineInstr &MI) {
143  if (TheDelegate)
144  TheDelegate->MF_HandleInsertion(MI);
145 }
146 
147 void MachineFunction::handleRemoval(MachineInstr &MI) {
148  if (TheDelegate)
149  TheDelegate->MF_HandleRemoval(MI);
150 }
151 
152 void MachineFunction::init() {
153  // Assume the function starts in SSA form with correct liveness.
156  if (STI->getRegisterInfo())
157  RegInfo = new (Allocator) MachineRegisterInfo(this);
158  else
159  RegInfo = nullptr;
160 
161  MFInfo = nullptr;
162  // We can realign the stack if the target supports it and the user hasn't
163  // explicitly asked us not to.
164  bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
165  !F.hasFnAttribute("no-realign-stack");
166  FrameInfo = new (Allocator) MachineFrameInfo(
167  getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
168  /*ForcedRealign=*/CanRealignSP &&
169  F.hasFnAttribute(Attribute::StackAlignment));
170 
171  if (F.hasFnAttribute(Attribute::StackAlignment))
172  FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
173 
174  ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
175  Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
176 
177  // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
178  // FIXME: Use Function::hasOptSize().
179  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
180  Alignment = std::max(Alignment,
182 
183  if (AlignAllFunctions)
184  Alignment = AlignAllFunctions;
185 
186  JumpTableInfo = nullptr;
187 
189  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
190  WinEHInfo = new (Allocator) WinEHFuncInfo();
191  }
192 
194  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
195  WasmEHInfo = new (Allocator) WasmEHFuncInfo();
196  }
197 
198  assert(Target.isCompatibleDataLayout(getDataLayout()) &&
199  "Can't create a MachineFunction using a Module with a "
200  "Target-incompatible DataLayout attached\n");
201 
202  PSVManager =
203  llvm::make_unique<PseudoSourceValueManager>(*(getSubtarget().
204  getInstrInfo()));
205 }
206 
208  clear();
209 }
210 
211 void MachineFunction::clear() {
212  Properties.reset();
213  // Don't call destructors on MachineInstr and MachineOperand. All of their
214  // memory comes from the BumpPtrAllocator which is about to be purged.
215  //
216  // Do call MachineBasicBlock destructors, it contains std::vectors.
217  for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
218  I->Insts.clearAndLeakNodesUnsafely();
219  MBBNumbering.clear();
220 
221  InstructionRecycler.clear(Allocator);
222  OperandRecycler.clear(Allocator);
223  BasicBlockRecycler.clear(Allocator);
224  CodeViewAnnotations.clear();
226  if (RegInfo) {
227  RegInfo->~MachineRegisterInfo();
228  Allocator.Deallocate(RegInfo);
229  }
230  if (MFInfo) {
231  MFInfo->~MachineFunctionInfo();
232  Allocator.Deallocate(MFInfo);
233  }
234 
235  FrameInfo->~MachineFrameInfo();
236  Allocator.Deallocate(FrameInfo);
237 
238  ConstantPool->~MachineConstantPool();
239  Allocator.Deallocate(ConstantPool);
240 
241  if (JumpTableInfo) {
242  JumpTableInfo->~MachineJumpTableInfo();
243  Allocator.Deallocate(JumpTableInfo);
244  }
245 
246  if (WinEHInfo) {
247  WinEHInfo->~WinEHFuncInfo();
248  Allocator.Deallocate(WinEHInfo);
249  }
250 
251  if (WasmEHInfo) {
252  WasmEHInfo->~WasmEHFuncInfo();
253  Allocator.Deallocate(WasmEHInfo);
254  }
255 }
256 
258  return F.getParent()->getDataLayout();
259 }
260 
261 /// Get the JumpTableInfo for this function.
262 /// If it does not already exist, allocate one.
264 getOrCreateJumpTableInfo(unsigned EntryKind) {
265  if (JumpTableInfo) return JumpTableInfo;
266 
267  JumpTableInfo = new (Allocator)
269  return JumpTableInfo;
270 }
271 
272 /// Should we be emitting segmented stack stuff for the function
274  return getFunction().hasFnAttribute("split-stack");
275 }
276 
277 LLVM_NODISCARD unsigned
279  FrameInstructions.push_back(Inst);
280  return FrameInstructions.size() - 1;
281 }
282 
283 /// This discards all of the MachineBasicBlock numbers and recomputes them.
284 /// This guarantees that the MBB numbers are sequential, dense, and match the
285 /// ordering of the blocks within the function. If a specific MachineBasicBlock
286 /// is specified, only that block and those after it are renumbered.
288  if (empty()) { MBBNumbering.clear(); return; }
289  MachineFunction::iterator MBBI, E = end();
290  if (MBB == nullptr)
291  MBBI = begin();
292  else
293  MBBI = MBB->getIterator();
294 
295  // Figure out the block number this should have.
296  unsigned BlockNo = 0;
297  if (MBBI != begin())
298  BlockNo = std::prev(MBBI)->getNumber() + 1;
299 
300  for (; MBBI != E; ++MBBI, ++BlockNo) {
301  if (MBBI->getNumber() != (int)BlockNo) {
302  // Remove use of the old number.
303  if (MBBI->getNumber() != -1) {
304  assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
305  "MBB number mismatch!");
306  MBBNumbering[MBBI->getNumber()] = nullptr;
307  }
308 
309  // If BlockNo is already taken, set that block's number to -1.
310  if (MBBNumbering[BlockNo])
311  MBBNumbering[BlockNo]->setNumber(-1);
312 
313  MBBNumbering[BlockNo] = &*MBBI;
314  MBBI->setNumber(BlockNo);
315  }
316  }
317 
318  // Okay, all the blocks are renumbered. If we have compactified the block
319  // numbering, shrink MBBNumbering now.
320  assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
321  MBBNumbering.resize(BlockNo);
322 }
323 
324 /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'.
326  const DebugLoc &DL,
327  bool NoImp) {
328  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
329  MachineInstr(*this, MCID, DL, NoImp);
330 }
331 
332 /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
333 /// identical in all ways except the instruction has no parent, prev, or next.
334 MachineInstr *
336  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
337  MachineInstr(*this, *Orig);
338 }
339 
341  MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
342  MachineInstr *FirstClone = nullptr;
344  while (true) {
345  MachineInstr *Cloned = CloneMachineInstr(&*I);
346  MBB.insert(InsertBefore, Cloned);
347  if (FirstClone == nullptr) {
348  FirstClone = Cloned;
349  } else {
350  Cloned->bundleWithPred();
351  }
352 
353  if (!I->isBundledWithSucc())
354  break;
355  ++I;
356  }
357  return *FirstClone;
358 }
359 
360 /// Delete the given MachineInstr.
361 ///
362 /// This function also serves as the MachineInstr destructor - the real
363 /// ~MachineInstr() destructor must be empty.
364 void
366  // Verify that a call site info is at valid state. This assertion should
367  // be triggered during the implementation of support for the
368  // call site info of a new architecture. If the assertion is triggered,
369  // back trace will tell where to insert a call to updateCallSiteInfo().
371  CallSitesInfo.find(MI) == CallSitesInfo.end()) &&
372  "Call site info was not updated!");
373  // Strip it for parts. The operand array and the MI object itself are
374  // independently recyclable.
375  if (MI->Operands)
376  deallocateOperandArray(MI->CapOperands, MI->Operands);
377  // Don't call ~MachineInstr() which must be trivial anyway because
378  // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
379  // destructors.
380  InstructionRecycler.Deallocate(Allocator, MI);
381 }
382 
383 /// Allocate a new MachineBasicBlock. Use this instead of
384 /// `new MachineBasicBlock'.
387  return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
388  MachineBasicBlock(*this, bb);
389 }
390 
391 /// Delete the given MachineBasicBlock.
392 void
394  assert(MBB->getParent() == this && "MBB parent mismatch!");
395  MBB->~MachineBasicBlock();
396  BasicBlockRecycler.Deallocate(Allocator, MBB);
397 }
398 
400  MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
401  unsigned base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
402  SyncScope::ID SSID, AtomicOrdering Ordering,
403  AtomicOrdering FailureOrdering) {
404  return new (Allocator)
405  MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges,
406  SSID, Ordering, FailureOrdering);
407 }
408 
411  int64_t Offset, uint64_t Size) {
412  const MachinePointerInfo &PtrInfo = MMO->getPointerInfo();
413 
414  // If there is no pointer value, the offset isn't tracked so we need to adjust
415  // the base alignment.
416  unsigned Align = PtrInfo.V.isNull()
417  ? MinAlign(MMO->getBaseAlignment(), Offset)
418  : MMO->getBaseAlignment();
419 
420  return new (Allocator)
421  MachineMemOperand(PtrInfo.getWithOffset(Offset), MMO->getFlags(), Size,
422  Align, AAMDNodes(), nullptr, MMO->getSyncScopeID(),
423  MMO->getOrdering(), MMO->getFailureOrdering());
424 }
425 
428  const AAMDNodes &AAInfo) {
429  MachinePointerInfo MPI = MMO->getValue() ?
430  MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
432 
433  return new (Allocator)
434  MachineMemOperand(MPI, MMO->getFlags(), MMO->getSize(),
435  MMO->getBaseAlignment(), AAInfo,
436  MMO->getRanges(), MMO->getSyncScopeID(),
437  MMO->getOrdering(), MMO->getFailureOrdering());
438 }
439 
442  MachineMemOperand::Flags Flags) {
443  return new (Allocator) MachineMemOperand(
444  MMO->getPointerInfo(), Flags, MMO->getSize(), MMO->getBaseAlignment(),
445  MMO->getAAInfo(), MMO->getRanges(), MMO->getSyncScopeID(),
446  MMO->getOrdering(), MMO->getFailureOrdering());
447 }
448 
449 MachineInstr::ExtraInfo *
451  MCSymbol *PreInstrSymbol,
452  MCSymbol *PostInstrSymbol) {
453  return MachineInstr::ExtraInfo::create(Allocator, MMOs, PreInstrSymbol,
454  PostInstrSymbol);
455 }
456 
458  char *Dest = Allocator.Allocate<char>(Name.size() + 1);
459  llvm::copy(Name, Dest);
460  Dest[Name.size()] = 0;
461  return Dest;
462 }
463 
465  unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs();
466  unsigned Size = MachineOperand::getRegMaskSize(NumRegs);
467  uint32_t *Mask = Allocator.Allocate<uint32_t>(Size);
468  memset(Mask, 0, Size * sizeof(Mask[0]));
469  return Mask;
470 }
471 
472 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
474  print(dbgs());
475 }
476 #endif
477 
479  return getFunction().getName();
480 }
481 
482 void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
483  OS << "# Machine code for function " << getName() << ": ";
484  getProperties().print(OS);
485  OS << '\n';
486 
487  // Print Frame Information
488  FrameInfo->print(*this, OS);
489 
490  // Print JumpTable Information
491  if (JumpTableInfo)
492  JumpTableInfo->print(OS);
493 
494  // Print Constant Pool
495  ConstantPool->print(OS);
496 
498 
499  if (RegInfo && !RegInfo->livein_empty()) {
500  OS << "Function Live Ins: ";
502  I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
503  OS << printReg(I->first, TRI);
504  if (I->second)
505  OS << " in " << printReg(I->second, TRI);
506  if (std::next(I) != E)
507  OS << ", ";
508  }
509  OS << '\n';
510  }
511 
514  for (const auto &BB : *this) {
515  OS << '\n';
516  // If we print the whole function, print it at its most verbose level.
517  BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
518  }
519 
520  OS << "\n# End machine code for function " << getName() << ".\n\n";
521 }
522 
523 namespace llvm {
524 
525  template<>
528 
529  static std::string getGraphName(const MachineFunction *F) {
530  return ("CFG for '" + F->getName() + "' function").str();
531  }
532 
533  std::string getNodeLabel(const MachineBasicBlock *Node,
534  const MachineFunction *Graph) {
535  std::string OutStr;
536  {
537  raw_string_ostream OSS(OutStr);
538 
539  if (isSimple()) {
540  OSS << printMBBReference(*Node);
541  if (const BasicBlock *BB = Node->getBasicBlock())
542  OSS << ": " << BB->getName();
543  } else
544  Node->print(OSS);
545  }
546 
547  if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
548 
549  // Process string output to make it nicer...
550  for (unsigned i = 0; i != OutStr.length(); ++i)
551  if (OutStr[i] == '\n') { // Left justify
552  OutStr[i] = '\\';
553  OutStr.insert(OutStr.begin()+i+1, 'l');
554  }
555  return OutStr;
556  }
557  };
558 
559 } // end namespace llvm
560 
562 {
563 #ifndef NDEBUG
564  ViewGraph(this, "mf" + getName());
565 #else
566  errs() << "MachineFunction::viewCFG is only available in debug builds on "
567  << "systems with Graphviz or gv!\n";
568 #endif // NDEBUG
569 }
570 
572 {
573 #ifndef NDEBUG
574  ViewGraph(this, "mf" + getName(), true);
575 #else
576  errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
577  << "systems with Graphviz or gv!\n";
578 #endif // NDEBUG
579 }
580 
581 /// Add the specified physical register as a live-in value and
582 /// create a corresponding virtual register for it.
583 unsigned MachineFunction::addLiveIn(unsigned PReg,
584  const TargetRegisterClass *RC) {
586  unsigned VReg = MRI.getLiveInVirtReg(PReg);
587  if (VReg) {
588  const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
589  (void)VRegRC;
590  // A physical register can be added several times.
591  // Between two calls, the register class of the related virtual register
592  // may have been constrained to match some operation constraints.
593  // In that case, check that the current register class includes the
594  // physical register and is a sub class of the specified RC.
595  assert((VRegRC == RC || (VRegRC->contains(PReg) &&
596  RC->hasSubClassEq(VRegRC))) &&
597  "Register class mismatch!");
598  return VReg;
599  }
600  VReg = MRI.createVirtualRegister(RC);
601  MRI.addLiveIn(PReg, VReg);
602  return VReg;
603 }
604 
605 /// Return the MCSymbol for the specified non-empty jump table.
606 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
607 /// normal 'L' label is returned.
609  bool isLinkerPrivate) const {
610  const DataLayout &DL = getDataLayout();
611  assert(JumpTableInfo && "No jump tables");
612  assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
613 
614  StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
615  : DL.getPrivateGlobalPrefix();
617  raw_svector_ostream(Name)
618  << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
619  return Ctx.getOrCreateSymbol(Name);
620 }
621 
622 /// Return a function-local symbol to represent the PIC base.
624  const DataLayout &DL = getDataLayout();
625  return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
626  Twine(getFunctionNumber()) + "$pb");
627 }
628 
629 /// \name Exception Handling
630 /// \{
631 
634  unsigned N = LandingPads.size();
635  for (unsigned i = 0; i < N; ++i) {
636  LandingPadInfo &LP = LandingPads[i];
637  if (LP.LandingPadBlock == LandingPad)
638  return LP;
639  }
640 
641  LandingPads.push_back(LandingPadInfo(LandingPad));
642  return LandingPads[N];
643 }
644 
646  MCSymbol *BeginLabel, MCSymbol *EndLabel) {
647  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
648  LP.BeginLabels.push_back(BeginLabel);
649  LP.EndLabels.push_back(EndLabel);
650 }
651 
653  MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
654  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
655  LP.LandingPadLabel = LandingPadLabel;
656 
657  const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
658  if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
659  if (const auto *PF =
660  dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()))
661  getMMI().addPersonality(PF);
662 
663  if (LPI->isCleanup())
664  addCleanup(LandingPad);
665 
666  // FIXME: New EH - Add the clauses in reverse order. This isn't 100%
667  // correct, but we need to do it this way because of how the DWARF EH
668  // emitter processes the clauses.
669  for (unsigned I = LPI->getNumClauses(); I != 0; --I) {
670  Value *Val = LPI->getClause(I - 1);
671  if (LPI->isCatch(I - 1)) {
672  addCatchTypeInfo(LandingPad,
673  dyn_cast<GlobalValue>(Val->stripPointerCasts()));
674  } else {
675  // Add filters in a list.
676  auto *CVal = cast<Constant>(Val);
678  for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
679  II != IE; ++II)
680  FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
681 
682  addFilterTypeInfo(LandingPad, FilterList);
683  }
684  }
685 
686  } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) {
687  for (unsigned I = CPI->getNumArgOperands(); I != 0; --I) {
688  Value *TypeInfo = CPI->getArgOperand(I - 1)->stripPointerCasts();
689  addCatchTypeInfo(LandingPad, dyn_cast<GlobalValue>(TypeInfo));
690  }
691 
692  } else {
693  assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!");
694  }
695 
696  return LandingPadLabel;
697 }
698 
701  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
702  for (unsigned N = TyInfo.size(); N; --N)
703  LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
704 }
705 
708  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
709  std::vector<unsigned> IdsInFilter(TyInfo.size());
710  for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
711  IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
712  LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
713 }
714 
716  bool TidyIfNoBeginLabels) {
717  for (unsigned i = 0; i != LandingPads.size(); ) {
718  LandingPadInfo &LandingPad = LandingPads[i];
719  if (LandingPad.LandingPadLabel &&
720  !LandingPad.LandingPadLabel->isDefined() &&
721  (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
722  LandingPad.LandingPadLabel = nullptr;
723 
724  // Special case: we *should* emit LPs with null LP MBB. This indicates
725  // "nounwind" case.
726  if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
727  LandingPads.erase(LandingPads.begin() + i);
728  continue;
729  }
730 
731  if (TidyIfNoBeginLabels) {
732  for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
733  MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
734  MCSymbol *EndLabel = LandingPad.EndLabels[j];
735  if ((BeginLabel->isDefined() || (LPMap && (*LPMap)[BeginLabel] != 0)) &&
736  (EndLabel->isDefined() || (LPMap && (*LPMap)[EndLabel] != 0)))
737  continue;
738 
739  LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
740  LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
741  --j;
742  --e;
743  }
744 
745  // Remove landing pads with no try-ranges.
746  if (LandingPads[i].BeginLabels.empty()) {
747  LandingPads.erase(LandingPads.begin() + i);
748  continue;
749  }
750  }
751 
752  // If there is no landing pad, ensure that the list of typeids is empty.
753  // If the only typeid is a cleanup, this is the same as having no typeids.
754  if (!LandingPad.LandingPadBlock ||
755  (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
756  LandingPad.TypeIds.clear();
757  ++i;
758  }
759 }
760 
762  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
763  LP.TypeIds.push_back(0);
764 }
765 
767  const Function *Filter,
768  const BlockAddress *RecoverBA) {
769  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
770  SEHHandler Handler;
771  Handler.FilterOrFinally = Filter;
772  Handler.RecoverBA = RecoverBA;
773  LP.SEHHandlers.push_back(Handler);
774 }
775 
777  const Function *Cleanup) {
778  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
779  SEHHandler Handler;
780  Handler.FilterOrFinally = Cleanup;
781  Handler.RecoverBA = nullptr;
782  LP.SEHHandlers.push_back(Handler);
783 }
784 
786  ArrayRef<unsigned> Sites) {
787  LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
788 }
789 
791  for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
792  if (TypeInfos[i] == TI) return i + 1;
793 
794  TypeInfos.push_back(TI);
795  return TypeInfos.size();
796 }
797 
798 int MachineFunction::getFilterIDFor(std::vector<unsigned> &TyIds) {
799  // If the new filter coincides with the tail of an existing filter, then
800  // re-use the existing filter. Folding filters more than this requires
801  // re-ordering filters and/or their elements - probably not worth it.
802  for (std::vector<unsigned>::iterator I = FilterEnds.begin(),
803  E = FilterEnds.end(); I != E; ++I) {
804  unsigned i = *I, j = TyIds.size();
805 
806  while (i && j)
807  if (FilterIds[--i] != TyIds[--j])
808  goto try_next;
809 
810  if (!j)
811  // The new filter coincides with range [i, end) of the existing filter.
812  return -(1 + i);
813 
814 try_next:;
815  }
816 
817  // Add the new filter.
818  int FilterID = -(1 + FilterIds.size());
819  FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
820  FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
821  FilterEnds.push_back(FilterIds.size());
822  FilterIds.push_back(0); // terminator
823  return FilterID;
824 }
825 
827  const MDNode *MD) {
828  MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true);
829  MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true);
830  I->setPreInstrSymbol(*this, BeginLabel);
831  I->setPostInstrSymbol(*this, EndLabel);
832 
833  const DIType *DI = dyn_cast<DIType>(MD);
834  CodeViewHeapAllocSites.push_back(std::make_tuple(BeginLabel, EndLabel, DI));
835 }
836 
838  const MachineInstr *New) {
839  if (!Target.Options.EnableDebugEntryValues || Old == New)
840  return;
841 
842  assert(Old->isCall() && (!New || New->isCall()) &&
843  "Call site info referes only to call instructions!");
844  CallSiteInfoMap::iterator CSIt = CallSitesInfo.find(Old);
845  if (CSIt == CallSitesInfo.end())
846  return;
847  CallSiteInfo CSInfo = std::move(CSIt->second);
848  CallSitesInfo.erase(CSIt);
849  if (New)
850  CallSitesInfo[New] = CSInfo;
851 }
852 
853 /// \}
854 
855 //===----------------------------------------------------------------------===//
856 // MachineJumpTableInfo implementation
857 //===----------------------------------------------------------------------===//
858 
859 /// Return the size of each entry in the jump table.
861  // The size of a jump table entry is 4 bytes unless the entry is just the
862  // address of a block, in which case it is the pointer size.
863  switch (getEntryKind()) {
865  return TD.getPointerSize();
867  return 8;
871  return 4;
873  return 0;
874  }
875  llvm_unreachable("Unknown jump table encoding!");
876 }
877 
878 /// Return the alignment of each entry in the jump table.
880  // The alignment of a jump table entry is the alignment of int32 unless the
881  // entry is just the address of a block, in which case it is the pointer
882  // alignment.
883  switch (getEntryKind()) {
885  return TD.getPointerABIAlignment(0);
887  return TD.getABIIntegerTypeAlignment(64);
891  return TD.getABIIntegerTypeAlignment(32);
893  return 1;
894  }
895  llvm_unreachable("Unknown jump table encoding!");
896 }
897 
898 /// Create a new jump table entry in the jump table info.
900  const std::vector<MachineBasicBlock*> &DestBBs) {
901  assert(!DestBBs.empty() && "Cannot create an empty jump table!");
902  JumpTables.push_back(MachineJumpTableEntry(DestBBs));
903  return JumpTables.size()-1;
904 }
905 
906 /// If Old is the target of any jump tables, update the jump tables to branch
907 /// to New instead.
909  MachineBasicBlock *New) {
910  assert(Old != New && "Not making a change?");
911  bool MadeChange = false;
912  for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
913  ReplaceMBBInJumpTable(i, Old, New);
914  return MadeChange;
915 }
916 
917 /// If Old is a target of the jump tables, update the jump table to branch to
918 /// New instead.
920  MachineBasicBlock *Old,
921  MachineBasicBlock *New) {
922  assert(Old != New && "Not making a change?");
923  bool MadeChange = false;
924  MachineJumpTableEntry &JTE = JumpTables[Idx];
925  for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
926  if (JTE.MBBs[j] == Old) {
927  JTE.MBBs[j] = New;
928  MadeChange = true;
929  }
930  return MadeChange;
931 }
932 
934  if (JumpTables.empty()) return;
935 
936  OS << "Jump Tables:\n";
937 
938  for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
939  OS << printJumpTableEntryReference(i) << ':';
940  for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
941  OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
942  if (i != e)
943  OS << '\n';
944  }
945 
946  OS << '\n';
947 }
948 
949 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
951 #endif
952 
954  return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
955 }
956 
957 //===----------------------------------------------------------------------===//
958 // MachineConstantPool implementation
959 //===----------------------------------------------------------------------===//
960 
961 void MachineConstantPoolValue::anchor() {}
962 
964  if (isMachineConstantPoolEntry())
965  return Val.MachineCPVal->getType();
966  return Val.ConstVal->getType();
967 }
968 
970  if (isMachineConstantPoolEntry())
971  return true;
972  return Val.ConstVal->needsRelocation();
973 }
974 
977  if (needsRelocation())
979  switch (DL->getTypeAllocSize(getType())) {
980  case 4:
982  case 8:
984  case 16:
986  case 32:
988  default:
989  return SectionKind::getReadOnly();
990  }
991 }
992 
994  // A constant may be a member of both Constants and MachineCPVsSharingEntries,
995  // so keep track of which we've deleted to avoid double deletions.
997  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
998  if (Constants[i].isMachineConstantPoolEntry()) {
999  Deleted.insert(Constants[i].Val.MachineCPVal);
1000  delete Constants[i].Val.MachineCPVal;
1001  }
1003  MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
1004  I != E; ++I) {
1005  if (Deleted.count(*I) == 0)
1006  delete *I;
1007  }
1008 }
1009 
1010 /// Test whether the given two constants can be allocated the same constant pool
1011 /// entry.
1012 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
1013  const DataLayout &DL) {
1014  // Handle the trivial case quickly.
1015  if (A == B) return true;
1016 
1017  // If they have the same type but weren't the same constant, quickly
1018  // reject them.
1019  if (A->getType() == B->getType()) return false;
1020 
1021  // We can't handle structs or arrays.
1022  if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
1023  isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
1024  return false;
1025 
1026  // For now, only support constants with the same size.
1027  uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
1028  if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
1029  return false;
1030 
1031  Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
1032 
1033  // Try constant folding a bitcast of both instructions to an integer. If we
1034  // get two identical ConstantInt's, then we are good to share them. We use
1035  // the constant folding APIs to do this so that we get the benefit of
1036  // DataLayout.
1037  if (isa<PointerType>(A->getType()))
1038  A = ConstantFoldCastOperand(Instruction::PtrToInt,
1039  const_cast<Constant *>(A), IntTy, DL);
1040  else if (A->getType() != IntTy)
1041  A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
1042  IntTy, DL);
1043  if (isa<PointerType>(B->getType()))
1044  B = ConstantFoldCastOperand(Instruction::PtrToInt,
1045  const_cast<Constant *>(B), IntTy, DL);
1046  else if (B->getType() != IntTy)
1047  B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
1048  IntTy, DL);
1049 
1050  return A == B;
1051 }
1052 
1053 /// Create a new entry in the constant pool or return an existing one.
1054 /// User must specify the log2 of the minimum required alignment for the object.
1056  unsigned Alignment) {
1057  assert(Alignment && "Alignment must be specified!");
1058  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1059 
1060  // Check to see if we already have this constant.
1061  //
1062  // FIXME, this could be made much more efficient for large constant pools.
1063  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1064  if (!Constants[i].isMachineConstantPoolEntry() &&
1065  CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1066  if ((unsigned)Constants[i].getAlignment() < Alignment)
1067  Constants[i].Alignment = Alignment;
1068  return i;
1069  }
1070 
1071  Constants.push_back(MachineConstantPoolEntry(C, Alignment));
1072  return Constants.size()-1;
1073 }
1074 
1076  unsigned Alignment) {
1077  assert(Alignment && "Alignment must be specified!");
1078  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1079 
1080  // Check to see if we already have this constant.
1081  //
1082  // FIXME, this could be made much more efficient for large constant pools.
1083  int Idx = V->getExistingMachineCPValue(this, Alignment);
1084  if (Idx != -1) {
1085  MachineCPVsSharingEntries.insert(V);
1086  return (unsigned)Idx;
1087  }
1088 
1089  Constants.push_back(MachineConstantPoolEntry(V, Alignment));
1090  return Constants.size()-1;
1091 }
1092 
1094  if (Constants.empty()) return;
1095 
1096  OS << "Constant Pool:\n";
1097  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
1098  OS << " cp#" << i << ": ";
1099  if (Constants[i].isMachineConstantPoolEntry())
1100  Constants[i].Val.MachineCPVal->print(OS);
1101  else
1102  Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1103  OS << ", align=" << Constants[i].getAlignment();
1104  OS << "\n";
1105  }
1106 }
1107 
1108 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1110 #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
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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:343
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.
bool isCall(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:635
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:265
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:473
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:316
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
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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:211
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:164
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:732
static SectionKind getMergeableConst16()
Definition: SectionKind.h:193
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
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:627
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:296
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
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
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.
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:369
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:64
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.
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition: PointerUnion.h:185
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:314
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.
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
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:726
This class is a data container for one entry in a MachineConstantPool.
void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just after the instruction itself.
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.
void updateCallSiteInfo(const MachineInstr *Old, const MachineInstr *New=nullptr)
Update call sites info by deleting entry for Old call instruction.
const Value * getValue() const
Return the base address of the memory access.
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:176
MCContext & getContext() const
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:614
#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:432
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.
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
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:645
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:843
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:535
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.
Base class for types.
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:837
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:752
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
MachinePointerInfo getWithOffset(int64_t O) const
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:249
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.
void addCodeViewHeapAllocSite(MachineInstr *I, const MDNode *MD)
Record heapallocsites.
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:469
static const char * getPropertyName(MachineFunctionProperties::Property Prop)
Representation of each machine instruction.
Definition: MachineInstr.h:64
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachinePointerInfo & getPointerInfo() const
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.
void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:127
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
#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
iterator end()
Definition: DenseMap.h:108
SectionKind getSectionKind(const DataLayout *DL) const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
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.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
Definition: Compiler.h:128
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:575
LLVM Value Representation.
Definition: Value.h:72
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1384
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:444
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:1244
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...
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.