LLVM  10.0.0
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 
82  "align-all-functions",
83  cl::desc("Force the alignment of all functions in log2 format (e.g. 4 "
84  "means align on 16B boundaries)."),
85  cl::init(0), cl::Hidden);
86 
89 
90  switch(Prop) {
91  case P::FailedISel: return "FailedISel";
92  case P::IsSSA: return "IsSSA";
93  case P::Legalized: return "Legalized";
94  case P::NoPHIs: return "NoPHIs";
95  case P::NoVRegs: return "NoVRegs";
96  case P::RegBankSelected: return "RegBankSelected";
97  case P::Selected: return "Selected";
98  case P::TracksLiveness: return "TracksLiveness";
99  }
100  llvm_unreachable("Invalid machine function property");
101 }
102 
103 // Pin the vtable to this file.
104 void MachineFunction::Delegate::anchor() {}
105 
107  const char *Separator = "";
108  for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
109  if (!Properties[I])
110  continue;
111  OS << Separator << getPropertyName(static_cast<Property>(I));
112  Separator = ", ";
113  }
114 }
115 
116 //===----------------------------------------------------------------------===//
117 // MachineFunction implementation
118 //===----------------------------------------------------------------------===//
119 
120 // Out-of-line virtual method.
122 
124  MBB->getParent()->DeleteMachineBasicBlock(MBB);
125 }
126 
127 static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
128  const Function &F) {
129  if (F.hasFnAttribute(Attribute::StackAlignment))
130  return F.getFnStackAlignment();
131  return STI->getFrameLowering()->getStackAlignment();
132 }
133 
135  const LLVMTargetMachine &Target,
136  const TargetSubtargetInfo &STI,
137  unsigned FunctionNum, MachineModuleInfo &mmi)
138  : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
139  FunctionNumber = FunctionNum;
140  init();
141 }
142 
143 void MachineFunction::handleInsertion(MachineInstr &MI) {
144  if (TheDelegate)
145  TheDelegate->MF_HandleInsertion(MI);
146 }
147 
148 void MachineFunction::handleRemoval(MachineInstr &MI) {
149  if (TheDelegate)
150  TheDelegate->MF_HandleRemoval(MI);
151 }
152 
153 void MachineFunction::init() {
154  // Assume the function starts in SSA form with correct liveness.
157  if (STI->getRegisterInfo())
158  RegInfo = new (Allocator) MachineRegisterInfo(this);
159  else
160  RegInfo = nullptr;
161 
162  MFInfo = nullptr;
163  // We can realign the stack if the target supports it and the user hasn't
164  // explicitly asked us not to.
165  bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
166  !F.hasFnAttribute("no-realign-stack");
167  FrameInfo = new (Allocator) MachineFrameInfo(
168  getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
169  /*ForcedRealign=*/CanRealignSP &&
170  F.hasFnAttribute(Attribute::StackAlignment));
171 
172  if (F.hasFnAttribute(Attribute::StackAlignment))
173  FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
174 
175  ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
176  Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
177 
178  // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
179  // FIXME: Use Function::hasOptSize().
180  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
181  Alignment = std::max(Alignment,
183 
184  if (AlignAllFunctions)
185  Alignment = Align(1ULL << AlignAllFunctions);
186 
187  JumpTableInfo = nullptr;
188 
190  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
191  WinEHInfo = new (Allocator) WinEHFuncInfo();
192  }
193 
195  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
196  WasmEHInfo = new (Allocator) WasmEHFuncInfo();
197  }
198 
199  assert(Target.isCompatibleDataLayout(getDataLayout()) &&
200  "Can't create a MachineFunction using a Module with a "
201  "Target-incompatible DataLayout attached\n");
202 
203  PSVManager =
204  std::make_unique<PseudoSourceValueManager>(*(getSubtarget().
205  getInstrInfo()));
206 }
207 
209  clear();
210 }
211 
212 void MachineFunction::clear() {
213  Properties.reset();
214  // Don't call destructors on MachineInstr and MachineOperand. All of their
215  // memory comes from the BumpPtrAllocator which is about to be purged.
216  //
217  // Do call MachineBasicBlock destructors, it contains std::vectors.
218  for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
219  I->Insts.clearAndLeakNodesUnsafely();
220  MBBNumbering.clear();
221 
222  InstructionRecycler.clear(Allocator);
223  OperandRecycler.clear(Allocator);
224  BasicBlockRecycler.clear(Allocator);
225  CodeViewAnnotations.clear();
227  if (RegInfo) {
228  RegInfo->~MachineRegisterInfo();
229  Allocator.Deallocate(RegInfo);
230  }
231  if (MFInfo) {
232  MFInfo->~MachineFunctionInfo();
233  Allocator.Deallocate(MFInfo);
234  }
235 
236  FrameInfo->~MachineFrameInfo();
237  Allocator.Deallocate(FrameInfo);
238 
239  ConstantPool->~MachineConstantPool();
240  Allocator.Deallocate(ConstantPool);
241 
242  if (JumpTableInfo) {
243  JumpTableInfo->~MachineJumpTableInfo();
244  Allocator.Deallocate(JumpTableInfo);
245  }
246 
247  if (WinEHInfo) {
248  WinEHInfo->~WinEHFuncInfo();
249  Allocator.Deallocate(WinEHInfo);
250  }
251 
252  if (WasmEHInfo) {
253  WasmEHInfo->~WasmEHFuncInfo();
254  Allocator.Deallocate(WasmEHInfo);
255  }
256 }
257 
259  return F.getParent()->getDataLayout();
260 }
261 
262 /// Get the JumpTableInfo for this function.
263 /// If it does not already exist, allocate one.
265 getOrCreateJumpTableInfo(unsigned EntryKind) {
266  if (JumpTableInfo) return JumpTableInfo;
267 
268  JumpTableInfo = new (Allocator)
270  return JumpTableInfo;
271 }
272 
274  // TODO: Should probably avoid the connection to the IR and store directly
275  // in the MachineFunction.
276  Attribute Attr = F.getFnAttribute("denormal-fp-math");
277 
278  // FIXME: This should assume IEEE behavior on an unspecified
279  // attribute. However, the one current user incorrectly assumes a non-IEEE
280  // target by default.
281  StringRef Val = Attr.getValueAsString();
282  if (Val.empty())
283  return DenormalMode::Invalid;
284 
285  return parseDenormalFPAttribute(Val);
286 }
287 
288 /// Should we be emitting segmented stack stuff for the function
290  return getFunction().hasFnAttribute("split-stack");
291 }
292 
293 LLVM_NODISCARD unsigned
295  FrameInstructions.push_back(Inst);
296  return FrameInstructions.size() - 1;
297 }
298 
299 /// This discards all of the MachineBasicBlock numbers and recomputes them.
300 /// This guarantees that the MBB numbers are sequential, dense, and match the
301 /// ordering of the blocks within the function. If a specific MachineBasicBlock
302 /// is specified, only that block and those after it are renumbered.
304  if (empty()) { MBBNumbering.clear(); return; }
305  MachineFunction::iterator MBBI, E = end();
306  if (MBB == nullptr)
307  MBBI = begin();
308  else
309  MBBI = MBB->getIterator();
310 
311  // Figure out the block number this should have.
312  unsigned BlockNo = 0;
313  if (MBBI != begin())
314  BlockNo = std::prev(MBBI)->getNumber() + 1;
315 
316  for (; MBBI != E; ++MBBI, ++BlockNo) {
317  if (MBBI->getNumber() != (int)BlockNo) {
318  // Remove use of the old number.
319  if (MBBI->getNumber() != -1) {
320  assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
321  "MBB number mismatch!");
322  MBBNumbering[MBBI->getNumber()] = nullptr;
323  }
324 
325  // If BlockNo is already taken, set that block's number to -1.
326  if (MBBNumbering[BlockNo])
327  MBBNumbering[BlockNo]->setNumber(-1);
328 
329  MBBNumbering[BlockNo] = &*MBBI;
330  MBBI->setNumber(BlockNo);
331  }
332  }
333 
334  // Okay, all the blocks are renumbered. If we have compactified the block
335  // numbering, shrink MBBNumbering now.
336  assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
337  MBBNumbering.resize(BlockNo);
338 }
339 
340 /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'.
342  const DebugLoc &DL,
343  bool NoImp) {
344  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
345  MachineInstr(*this, MCID, DL, NoImp);
346 }
347 
348 /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
349 /// identical in all ways except the instruction has no parent, prev, or next.
350 MachineInstr *
352  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
353  MachineInstr(*this, *Orig);
354 }
355 
357  MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
358  MachineInstr *FirstClone = nullptr;
360  while (true) {
361  MachineInstr *Cloned = CloneMachineInstr(&*I);
362  MBB.insert(InsertBefore, Cloned);
363  if (FirstClone == nullptr) {
364  FirstClone = Cloned;
365  } else {
366  Cloned->bundleWithPred();
367  }
368 
369  if (!I->isBundledWithSucc())
370  break;
371  ++I;
372  }
373  return *FirstClone;
374 }
375 
376 /// Delete the given MachineInstr.
377 ///
378 /// This function also serves as the MachineInstr destructor - the real
379 /// ~MachineInstr() destructor must be empty.
380 void
382  // Verify that a call site info is at valid state. This assertion should
383  // be triggered during the implementation of support for the
384  // call site info of a new architecture. If the assertion is triggered,
385  // back trace will tell where to insert a call to updateCallSiteInfo().
387  CallSitesInfo.find(MI) == CallSitesInfo.end()) &&
388  "Call site info was not updated!");
389  // Strip it for parts. The operand array and the MI object itself are
390  // independently recyclable.
391  if (MI->Operands)
392  deallocateOperandArray(MI->CapOperands, MI->Operands);
393  // Don't call ~MachineInstr() which must be trivial anyway because
394  // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
395  // destructors.
396  InstructionRecycler.Deallocate(Allocator, MI);
397 }
398 
399 /// Allocate a new MachineBasicBlock. Use this instead of
400 /// `new MachineBasicBlock'.
403  return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
404  MachineBasicBlock(*this, bb);
405 }
406 
407 /// Delete the given MachineBasicBlock.
408 void
410  assert(MBB->getParent() == this && "MBB parent mismatch!");
411  MBB->~MachineBasicBlock();
412  BasicBlockRecycler.Deallocate(Allocator, MBB);
413 }
414 
416  MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
417  unsigned base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
418  SyncScope::ID SSID, AtomicOrdering Ordering,
419  AtomicOrdering FailureOrdering) {
420  return new (Allocator)
421  MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges,
422  SSID, Ordering, FailureOrdering);
423 }
424 
427  int64_t Offset, uint64_t Size) {
428  const MachinePointerInfo &PtrInfo = MMO->getPointerInfo();
429 
430  // If there is no pointer value, the offset isn't tracked so we need to adjust
431  // the base alignment.
432  unsigned Align = PtrInfo.V.isNull()
433  ? MinAlign(MMO->getBaseAlignment(), Offset)
434  : MMO->getBaseAlignment();
435 
436  return new (Allocator)
437  MachineMemOperand(PtrInfo.getWithOffset(Offset), MMO->getFlags(), Size,
438  Align, AAMDNodes(), nullptr, MMO->getSyncScopeID(),
439  MMO->getOrdering(), MMO->getFailureOrdering());
440 }
441 
444  const AAMDNodes &AAInfo) {
445  MachinePointerInfo MPI = MMO->getValue() ?
446  MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
448 
449  return new (Allocator)
450  MachineMemOperand(MPI, MMO->getFlags(), MMO->getSize(),
451  MMO->getBaseAlignment(), AAInfo,
452  MMO->getRanges(), MMO->getSyncScopeID(),
453  MMO->getOrdering(), MMO->getFailureOrdering());
454 }
455 
458  MachineMemOperand::Flags Flags) {
459  return new (Allocator) MachineMemOperand(
460  MMO->getPointerInfo(), Flags, MMO->getSize(), MMO->getBaseAlignment(),
461  MMO->getAAInfo(), MMO->getRanges(), MMO->getSyncScopeID(),
462  MMO->getOrdering(), MMO->getFailureOrdering());
463 }
464 
465 MachineInstr::ExtraInfo *MachineFunction::createMIExtraInfo(
466  ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol,
467  MCSymbol *PostInstrSymbol, MDNode *HeapAllocMarker) {
468  return MachineInstr::ExtraInfo::create(Allocator, MMOs, PreInstrSymbol,
469  PostInstrSymbol, HeapAllocMarker);
470 }
471 
473  char *Dest = Allocator.Allocate<char>(Name.size() + 1);
474  llvm::copy(Name, Dest);
475  Dest[Name.size()] = 0;
476  return Dest;
477 }
478 
480  unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs();
481  unsigned Size = MachineOperand::getRegMaskSize(NumRegs);
482  uint32_t *Mask = Allocator.Allocate<uint32_t>(Size);
483  memset(Mask, 0, Size * sizeof(Mask[0]));
484  return Mask;
485 }
486 
488  int* AllocMask = Allocator.Allocate<int>(Mask.size());
489  copy(Mask, AllocMask);
490  return {AllocMask, Mask.size()};
491 }
492 
493 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
495  print(dbgs());
496 }
497 #endif
498 
500  return getFunction().getName();
501 }
502 
503 void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
504  OS << "# Machine code for function " << getName() << ": ";
505  getProperties().print(OS);
506  OS << '\n';
507 
508  // Print Frame Information
509  FrameInfo->print(*this, OS);
510 
511  // Print JumpTable Information
512  if (JumpTableInfo)
513  JumpTableInfo->print(OS);
514 
515  // Print Constant Pool
516  ConstantPool->print(OS);
517 
519 
520  if (RegInfo && !RegInfo->livein_empty()) {
521  OS << "Function Live Ins: ";
523  I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
524  OS << printReg(I->first, TRI);
525  if (I->second)
526  OS << " in " << printReg(I->second, TRI);
527  if (std::next(I) != E)
528  OS << ", ";
529  }
530  OS << '\n';
531  }
532 
535  for (const auto &BB : *this) {
536  OS << '\n';
537  // If we print the whole function, print it at its most verbose level.
538  BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
539  }
540 
541  OS << "\n# End machine code for function " << getName() << ".\n\n";
542 }
543 
544 /// True if this function needs frame moves for debug or exceptions.
546  return getMMI().hasDebugInfo() ||
549 }
550 
551 namespace llvm {
552 
553  template<>
556 
557  static std::string getGraphName(const MachineFunction *F) {
558  return ("CFG for '" + F->getName() + "' function").str();
559  }
560 
561  std::string getNodeLabel(const MachineBasicBlock *Node,
562  const MachineFunction *Graph) {
563  std::string OutStr;
564  {
565  raw_string_ostream OSS(OutStr);
566 
567  if (isSimple()) {
568  OSS << printMBBReference(*Node);
569  if (const BasicBlock *BB = Node->getBasicBlock())
570  OSS << ": " << BB->getName();
571  } else
572  Node->print(OSS);
573  }
574 
575  if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
576 
577  // Process string output to make it nicer...
578  for (unsigned i = 0; i != OutStr.length(); ++i)
579  if (OutStr[i] == '\n') { // Left justify
580  OutStr[i] = '\\';
581  OutStr.insert(OutStr.begin()+i+1, 'l');
582  }
583  return OutStr;
584  }
585  };
586 
587 } // end namespace llvm
588 
590 {
591 #ifndef NDEBUG
592  ViewGraph(this, "mf" + getName());
593 #else
594  errs() << "MachineFunction::viewCFG is only available in debug builds on "
595  << "systems with Graphviz or gv!\n";
596 #endif // NDEBUG
597 }
598 
600 {
601 #ifndef NDEBUG
602  ViewGraph(this, "mf" + getName(), true);
603 #else
604  errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
605  << "systems with Graphviz or gv!\n";
606 #endif // NDEBUG
607 }
608 
609 /// Add the specified physical register as a live-in value and
610 /// create a corresponding virtual register for it.
611 unsigned MachineFunction::addLiveIn(unsigned PReg,
612  const TargetRegisterClass *RC) {
614  unsigned VReg = MRI.getLiveInVirtReg(PReg);
615  if (VReg) {
616  const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
617  (void)VRegRC;
618  // A physical register can be added several times.
619  // Between two calls, the register class of the related virtual register
620  // may have been constrained to match some operation constraints.
621  // In that case, check that the current register class includes the
622  // physical register and is a sub class of the specified RC.
623  assert((VRegRC == RC || (VRegRC->contains(PReg) &&
624  RC->hasSubClassEq(VRegRC))) &&
625  "Register class mismatch!");
626  return VReg;
627  }
628  VReg = MRI.createVirtualRegister(RC);
629  MRI.addLiveIn(PReg, VReg);
630  return VReg;
631 }
632 
633 /// Return the MCSymbol for the specified non-empty jump table.
634 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
635 /// normal 'L' label is returned.
637  bool isLinkerPrivate) const {
638  const DataLayout &DL = getDataLayout();
639  assert(JumpTableInfo && "No jump tables");
640  assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
641 
642  StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
643  : DL.getPrivateGlobalPrefix();
645  raw_svector_ostream(Name)
646  << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
647  return Ctx.getOrCreateSymbol(Name);
648 }
649 
650 /// Return a function-local symbol to represent the PIC base.
652  const DataLayout &DL = getDataLayout();
653  return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
654  Twine(getFunctionNumber()) + "$pb");
655 }
656 
657 /// \name Exception Handling
658 /// \{
659 
662  unsigned N = LandingPads.size();
663  for (unsigned i = 0; i < N; ++i) {
664  LandingPadInfo &LP = LandingPads[i];
665  if (LP.LandingPadBlock == LandingPad)
666  return LP;
667  }
668 
669  LandingPads.push_back(LandingPadInfo(LandingPad));
670  return LandingPads[N];
671 }
672 
674  MCSymbol *BeginLabel, MCSymbol *EndLabel) {
675  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
676  LP.BeginLabels.push_back(BeginLabel);
677  LP.EndLabels.push_back(EndLabel);
678 }
679 
681  MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
682  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
683  LP.LandingPadLabel = LandingPadLabel;
684 
685  const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
686  if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
687  if (const auto *PF =
688  dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()))
689  getMMI().addPersonality(PF);
690 
691  if (LPI->isCleanup())
692  addCleanup(LandingPad);
693 
694  // FIXME: New EH - Add the clauses in reverse order. This isn't 100%
695  // correct, but we need to do it this way because of how the DWARF EH
696  // emitter processes the clauses.
697  for (unsigned I = LPI->getNumClauses(); I != 0; --I) {
698  Value *Val = LPI->getClause(I - 1);
699  if (LPI->isCatch(I - 1)) {
700  addCatchTypeInfo(LandingPad,
701  dyn_cast<GlobalValue>(Val->stripPointerCasts()));
702  } else {
703  // Add filters in a list.
704  auto *CVal = cast<Constant>(Val);
706  for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
707  II != IE; ++II)
708  FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
709 
710  addFilterTypeInfo(LandingPad, FilterList);
711  }
712  }
713 
714  } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) {
715  for (unsigned I = CPI->getNumArgOperands(); I != 0; --I) {
716  Value *TypeInfo = CPI->getArgOperand(I - 1)->stripPointerCasts();
717  addCatchTypeInfo(LandingPad, dyn_cast<GlobalValue>(TypeInfo));
718  }
719 
720  } else {
721  assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!");
722  }
723 
724  return LandingPadLabel;
725 }
726 
729  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
730  for (unsigned N = TyInfo.size(); N; --N)
731  LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
732 }
733 
736  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
737  std::vector<unsigned> IdsInFilter(TyInfo.size());
738  for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
739  IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
740  LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
741 }
742 
744  bool TidyIfNoBeginLabels) {
745  for (unsigned i = 0; i != LandingPads.size(); ) {
746  LandingPadInfo &LandingPad = LandingPads[i];
747  if (LandingPad.LandingPadLabel &&
748  !LandingPad.LandingPadLabel->isDefined() &&
749  (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
750  LandingPad.LandingPadLabel = nullptr;
751 
752  // Special case: we *should* emit LPs with null LP MBB. This indicates
753  // "nounwind" case.
754  if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
755  LandingPads.erase(LandingPads.begin() + i);
756  continue;
757  }
758 
759  if (TidyIfNoBeginLabels) {
760  for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
761  MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
762  MCSymbol *EndLabel = LandingPad.EndLabels[j];
763  if ((BeginLabel->isDefined() || (LPMap && (*LPMap)[BeginLabel] != 0)) &&
764  (EndLabel->isDefined() || (LPMap && (*LPMap)[EndLabel] != 0)))
765  continue;
766 
767  LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
768  LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
769  --j;
770  --e;
771  }
772 
773  // Remove landing pads with no try-ranges.
774  if (LandingPads[i].BeginLabels.empty()) {
775  LandingPads.erase(LandingPads.begin() + i);
776  continue;
777  }
778  }
779 
780  // If there is no landing pad, ensure that the list of typeids is empty.
781  // If the only typeid is a cleanup, this is the same as having no typeids.
782  if (!LandingPad.LandingPadBlock ||
783  (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
784  LandingPad.TypeIds.clear();
785  ++i;
786  }
787 }
788 
790  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
791  LP.TypeIds.push_back(0);
792 }
793 
795  const Function *Filter,
796  const BlockAddress *RecoverBA) {
797  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
798  SEHHandler Handler;
799  Handler.FilterOrFinally = Filter;
800  Handler.RecoverBA = RecoverBA;
801  LP.SEHHandlers.push_back(Handler);
802 }
803 
805  const Function *Cleanup) {
806  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
807  SEHHandler Handler;
808  Handler.FilterOrFinally = Cleanup;
809  Handler.RecoverBA = nullptr;
810  LP.SEHHandlers.push_back(Handler);
811 }
812 
814  ArrayRef<unsigned> Sites) {
815  LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
816 }
817 
819  for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
820  if (TypeInfos[i] == TI) return i + 1;
821 
822  TypeInfos.push_back(TI);
823  return TypeInfos.size();
824 }
825 
826 int MachineFunction::getFilterIDFor(std::vector<unsigned> &TyIds) {
827  // If the new filter coincides with the tail of an existing filter, then
828  // re-use the existing filter. Folding filters more than this requires
829  // re-ordering filters and/or their elements - probably not worth it.
830  for (std::vector<unsigned>::iterator I = FilterEnds.begin(),
831  E = FilterEnds.end(); I != E; ++I) {
832  unsigned i = *I, j = TyIds.size();
833 
834  while (i && j)
835  if (FilterIds[--i] != TyIds[--j])
836  goto try_next;
837 
838  if (!j)
839  // The new filter coincides with range [i, end) of the existing filter.
840  return -(1 + i);
841 
842 try_next:;
843  }
844 
845  // Add the new filter.
846  int FilterID = -(1 + FilterIds.size());
847  FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
848  FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
849  FilterEnds.push_back(FilterIds.size());
850  FilterIds.push_back(0); // terminator
851  return FilterID;
852 }
853 
855 MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
856  assert(MI->isCall() && "Call site info refers only to call instructions!");
857 
858  if (!Target.Options.EnableDebugEntryValues)
859  return CallSitesInfo.end();
860  return CallSitesInfo.find(MI);
861 }
862 
864  const MachineInstr *New) {
865  assert(New->isCall() && "Call site info refers only to call instructions!");
866 
867  CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
868  if (CSIt == CallSitesInfo.end())
869  return;
870 
871  CallSiteInfo CSInfo = std::move(CSIt->second);
872  CallSitesInfo.erase(CSIt);
873  CallSitesInfo[New] = CSInfo;
874 }
875 
877  CallSiteInfoMap::iterator CSIt = getCallSiteInfo(MI);
878  if (CSIt == CallSitesInfo.end())
879  return;
880  CallSitesInfo.erase(CSIt);
881 }
882 
884  const MachineInstr *New) {
885  assert(New->isCall() && "Call site info refers only to call instructions!");
886 
887  CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
888  if (CSIt == CallSitesInfo.end())
889  return;
890 
891  CallSiteInfo CSInfo = CSIt->second;
892  CallSitesInfo[New] = CSInfo;
893 }
894 
895 /// \}
896 
897 //===----------------------------------------------------------------------===//
898 // MachineJumpTableInfo implementation
899 //===----------------------------------------------------------------------===//
900 
901 /// Return the size of each entry in the jump table.
903  // The size of a jump table entry is 4 bytes unless the entry is just the
904  // address of a block, in which case it is the pointer size.
905  switch (getEntryKind()) {
907  return TD.getPointerSize();
909  return 8;
913  return 4;
915  return 0;
916  }
917  llvm_unreachable("Unknown jump table encoding!");
918 }
919 
920 /// Return the alignment of each entry in the jump table.
922  // The alignment of a jump table entry is the alignment of int32 unless the
923  // entry is just the address of a block, in which case it is the pointer
924  // alignment.
925  switch (getEntryKind()) {
927  return TD.getPointerABIAlignment(0).value();
929  return TD.getABIIntegerTypeAlignment(64).value();
933  return TD.getABIIntegerTypeAlignment(32).value();
935  return 1;
936  }
937  llvm_unreachable("Unknown jump table encoding!");
938 }
939 
940 /// Create a new jump table entry in the jump table info.
942  const std::vector<MachineBasicBlock*> &DestBBs) {
943  assert(!DestBBs.empty() && "Cannot create an empty jump table!");
944  JumpTables.push_back(MachineJumpTableEntry(DestBBs));
945  return JumpTables.size()-1;
946 }
947 
948 /// If Old is the target of any jump tables, update the jump tables to branch
949 /// to New instead.
951  MachineBasicBlock *New) {
952  assert(Old != New && "Not making a change?");
953  bool MadeChange = false;
954  for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
955  ReplaceMBBInJumpTable(i, Old, New);
956  return MadeChange;
957 }
958 
959 /// If Old is a target of the jump tables, update the jump table to branch to
960 /// New instead.
962  MachineBasicBlock *Old,
963  MachineBasicBlock *New) {
964  assert(Old != New && "Not making a change?");
965  bool MadeChange = false;
966  MachineJumpTableEntry &JTE = JumpTables[Idx];
967  for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
968  if (JTE.MBBs[j] == Old) {
969  JTE.MBBs[j] = New;
970  MadeChange = true;
971  }
972  return MadeChange;
973 }
974 
976  if (JumpTables.empty()) return;
977 
978  OS << "Jump Tables:\n";
979 
980  for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
981  OS << printJumpTableEntryReference(i) << ':';
982  for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
983  OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
984  if (i != e)
985  OS << '\n';
986  }
987 
988  OS << '\n';
989 }
990 
991 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
993 #endif
994 
996  return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
997 }
998 
999 //===----------------------------------------------------------------------===//
1000 // MachineConstantPool implementation
1001 //===----------------------------------------------------------------------===//
1002 
1003 void MachineConstantPoolValue::anchor() {}
1004 
1006  if (isMachineConstantPoolEntry())
1007  return Val.MachineCPVal->getType();
1008  return Val.ConstVal->getType();
1009 }
1010 
1012  if (isMachineConstantPoolEntry())
1013  return true;
1014  return Val.ConstVal->needsRelocation();
1015 }
1016 
1019  if (needsRelocation())
1021  switch (DL->getTypeAllocSize(getType())) {
1022  case 4:
1024  case 8:
1026  case 16:
1028  case 32:
1030  default:
1031  return SectionKind::getReadOnly();
1032  }
1033 }
1034 
1036  // A constant may be a member of both Constants and MachineCPVsSharingEntries,
1037  // so keep track of which we've deleted to avoid double deletions.
1039  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1040  if (Constants[i].isMachineConstantPoolEntry()) {
1041  Deleted.insert(Constants[i].Val.MachineCPVal);
1042  delete Constants[i].Val.MachineCPVal;
1043  }
1045  MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
1046  I != E; ++I) {
1047  if (Deleted.count(*I) == 0)
1048  delete *I;
1049  }
1050 }
1051 
1052 /// Test whether the given two constants can be allocated the same constant pool
1053 /// entry.
1054 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
1055  const DataLayout &DL) {
1056  // Handle the trivial case quickly.
1057  if (A == B) return true;
1058 
1059  // If they have the same type but weren't the same constant, quickly
1060  // reject them.
1061  if (A->getType() == B->getType()) return false;
1062 
1063  // We can't handle structs or arrays.
1064  if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
1065  isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
1066  return false;
1067 
1068  // For now, only support constants with the same size.
1069  uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
1070  if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
1071  return false;
1072 
1073  Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
1074 
1075  // Try constant folding a bitcast of both instructions to an integer. If we
1076  // get two identical ConstantInt's, then we are good to share them. We use
1077  // the constant folding APIs to do this so that we get the benefit of
1078  // DataLayout.
1079  if (isa<PointerType>(A->getType()))
1080  A = ConstantFoldCastOperand(Instruction::PtrToInt,
1081  const_cast<Constant *>(A), IntTy, DL);
1082  else if (A->getType() != IntTy)
1083  A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
1084  IntTy, DL);
1085  if (isa<PointerType>(B->getType()))
1086  B = ConstantFoldCastOperand(Instruction::PtrToInt,
1087  const_cast<Constant *>(B), IntTy, DL);
1088  else if (B->getType() != IntTy)
1089  B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
1090  IntTy, DL);
1091 
1092  return A == B;
1093 }
1094 
1095 /// Create a new entry in the constant pool or return an existing one.
1096 /// User must specify the log2 of the minimum required alignment for the object.
1098  unsigned Alignment) {
1099  assert(Alignment && "Alignment must be specified!");
1100  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1101 
1102  // Check to see if we already have this constant.
1103  //
1104  // FIXME, this could be made much more efficient for large constant pools.
1105  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1106  if (!Constants[i].isMachineConstantPoolEntry() &&
1107  CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1108  if ((unsigned)Constants[i].getAlignment() < Alignment)
1109  Constants[i].Alignment = Alignment;
1110  return i;
1111  }
1112 
1113  Constants.push_back(MachineConstantPoolEntry(C, Alignment));
1114  return Constants.size()-1;
1115 }
1116 
1118  unsigned Alignment) {
1119  assert(Alignment && "Alignment must be specified!");
1120  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1121 
1122  // Check to see if we already have this constant.
1123  //
1124  // FIXME, this could be made much more efficient for large constant pools.
1125  int Idx = V->getExistingMachineCPValue(this, Alignment);
1126  if (Idx != -1) {
1127  MachineCPVsSharingEntries.insert(V);
1128  return (unsigned)Idx;
1129  }
1130 
1131  Constants.push_back(MachineConstantPoolEntry(V, Alignment));
1132  return Constants.size()-1;
1133 }
1134 
1136  if (Constants.empty()) return;
1137 
1138  OS << "Constant Pool:\n";
1139  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
1140  OS << " cp#" << i << ": ";
1141  if (Constants[i].isMachineConstantPoolEntry())
1142  Constants[i].Val.MachineCPVal->print(OS);
1143  else
1144  Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1145  OS << ", align=" << Constants[i].getAlignment();
1146  OS << "\n";
1147  }
1148 }
1149 
1150 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1152 #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:111
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
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:682
bool hasDebugInfo() const
Returns true if valid debug info is present.
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:492
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:320
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:146
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
static void Cleanup(DenseMap< Instruction *, Instruction *> &NewPredicates, SetVector< Instruction *> &MaybeDead, Loop *L)
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:188
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
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
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:744
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:543
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:872
F(f)
MachineModuleInfo & getMMI() const
Manage lifetime of a slot tracker for printing IR.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
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.
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:300
static SectionKind getMergeableConst4()
Definition: SectionKind.h:191
Align getMinFunctionAlignment() const
Return the minimum function alignment.
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...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
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:840
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.
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:282
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.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
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:65
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:179
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:246
SlotIndexes pass.
Definition: SlotIndexes.h:314
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:454
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:151
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
void eraseCallSiteInfo(const MachineInstr *MI)
Erase the call site info for MI.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:743
This class is a data container for one entry in a MachineConstantPool.
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:86
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.
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
MCContext & getContext() const
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:661
#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:435
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:196
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:46
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)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:158
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:654
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
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.
DenormalMode parseDenormalFPAttribute(StringRef Str)
Parse the expected names from the denormal-fp-math attribute.
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
constexpr double e
Definition: MathExtras.h:57
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.
Align getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.cpp:761
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:848
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:530
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.
unsigned ForceDwarfFrameSection
Emit DWARF debug frame section.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
void copyCallSiteInfo(const MachineInstr *Old, const MachineInstr *New)
Copy the call site info from Old to \ New.
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...
Align getPointerABIAlignment(unsigned AS) const
Layout pointer alignment.
Definition: DataLayout.cpp:636
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:244
Align getPrefFunctionAlignment() const
Return the preferred function alignment.
Iterator for intrusive lists based on ilist_node.
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
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:147
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:644
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:202
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
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:605
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:241
Target - Wrapper for Target specific information.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
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.
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.
const MachinePointerInfo & getPointerInfo() const
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:130
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:220
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:215
TargetOptions Options
#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:82
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
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
MachineInstr::ExtraInfo * createMIExtraInfo(ArrayRef< MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol=nullptr, MCSymbol *PostInstrSymbol=nullptr, MDNode *HeapAllocMarker=nullptr)
Allocate and construct an extra info structure for a MachineInstr.
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
static cl::opt< unsigned > AlignAllFunctions("align-all-functions", cl::desc("Force the alignment of all functions in log2 format (e.g. 4 " "means align on 16B boundaries)."), cl::init(0), cl::Hidden)
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:159
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:516
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:74
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1484
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.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
void moveCallSiteInfo(const MachineInstr *Old, const MachineInstr *New)
Following functions update call site info.
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)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:333
DenormalMode
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
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:54
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:1234
VariableDbgInfoMapTy VariableDbgInfos
static SectionKind getReadOnly()
Definition: SectionKind.h:181
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function. ...
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.
ArrayRef< int > allocateShuffleMask(ArrayRef< int > Mask)