LLVM  7.0.0svn
MachineFunction.cpp
Go to the documentation of this file.
1 //===- MachineFunction.cpp ------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Collect native machine code information for a function. This allows
11 // target-specific information about the generated code to be stored with each
12 // function.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/ADT/BitVector.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Twine.h"
42 #include "llvm/Config/llvm-config.h"
43 #include "llvm/IR/Attributes.h"
44 #include "llvm/IR/BasicBlock.h"
45 #include "llvm/IR/Constant.h"
46 #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 
103  const char *Separator = "";
104  for (BitVector::size_type I = 0; I < Properties.size(); ++I) {
105  if (!Properties[I])
106  continue;
107  OS << Separator << getPropertyName(static_cast<Property>(I));
108  Separator = ", ";
109  }
110 }
111 
112 //===----------------------------------------------------------------------===//
113 // MachineFunction implementation
114 //===----------------------------------------------------------------------===//
115 
116 // Out-of-line virtual method.
118 
120  MBB->getParent()->DeleteMachineBasicBlock(MBB);
121 }
122 
123 static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
124  const Function &F) {
125  if (F.hasFnAttribute(Attribute::StackAlignment))
126  return F.getFnStackAlignment();
127  return STI->getFrameLowering()->getStackAlignment();
128 }
129 
131  const TargetSubtargetInfo &STI,
132  unsigned FunctionNum, MachineModuleInfo &mmi)
133  : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
134  FunctionNumber = FunctionNum;
135  init();
136 }
137 
138 void MachineFunction::init() {
139  // Assume the function starts in SSA form with correct liveness.
142  if (STI->getRegisterInfo())
143  RegInfo = new (Allocator) MachineRegisterInfo(this);
144  else
145  RegInfo = nullptr;
146 
147  MFInfo = nullptr;
148  // We can realign the stack if the target supports it and the user hasn't
149  // explicitly asked us not to.
150  bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
151  !F.hasFnAttribute("no-realign-stack");
152  FrameInfo = new (Allocator) MachineFrameInfo(
153  getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
154  /*ForceRealign=*/CanRealignSP &&
155  F.hasFnAttribute(Attribute::StackAlignment));
156 
157  if (F.hasFnAttribute(Attribute::StackAlignment))
158  FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
159 
160  ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
161  Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
162 
163  // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
164  // FIXME: Use Function::optForSize().
165  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
166  Alignment = std::max(Alignment,
168 
169  if (AlignAllFunctions)
170  Alignment = AlignAllFunctions;
171 
172  JumpTableInfo = nullptr;
173 
175  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
176  WinEHInfo = new (Allocator) WinEHFuncInfo();
177  }
178 
180  F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
181  WasmEHInfo = new (Allocator) WasmEHFuncInfo();
182  }
183 
184  assert(Target.isCompatibleDataLayout(getDataLayout()) &&
185  "Can't create a MachineFunction using a Module with a "
186  "Target-incompatible DataLayout attached\n");
187 
188  PSVManager =
189  llvm::make_unique<PseudoSourceValueManager>(*(getSubtarget().
190  getInstrInfo()));
191 }
192 
194  clear();
195 }
196 
197 void MachineFunction::clear() {
198  Properties.reset();
199  // Don't call destructors on MachineInstr and MachineOperand. All of their
200  // memory comes from the BumpPtrAllocator which is about to be purged.
201  //
202  // Do call MachineBasicBlock destructors, it contains std::vectors.
203  for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
204  I->Insts.clearAndLeakNodesUnsafely();
205  MBBNumbering.clear();
206 
207  InstructionRecycler.clear(Allocator);
208  OperandRecycler.clear(Allocator);
209  BasicBlockRecycler.clear(Allocator);
210  CodeViewAnnotations.clear();
212  if (RegInfo) {
213  RegInfo->~MachineRegisterInfo();
214  Allocator.Deallocate(RegInfo);
215  }
216  if (MFInfo) {
217  MFInfo->~MachineFunctionInfo();
218  Allocator.Deallocate(MFInfo);
219  }
220 
221  FrameInfo->~MachineFrameInfo();
222  Allocator.Deallocate(FrameInfo);
223 
224  ConstantPool->~MachineConstantPool();
225  Allocator.Deallocate(ConstantPool);
226 
227  if (JumpTableInfo) {
228  JumpTableInfo->~MachineJumpTableInfo();
229  Allocator.Deallocate(JumpTableInfo);
230  }
231 
232  if (WinEHInfo) {
233  WinEHInfo->~WinEHFuncInfo();
234  Allocator.Deallocate(WinEHInfo);
235  }
236 }
237 
239  return F.getParent()->getDataLayout();
240 }
241 
242 /// Get the JumpTableInfo for this function.
243 /// If it does not already exist, allocate one.
245 getOrCreateJumpTableInfo(unsigned EntryKind) {
246  if (JumpTableInfo) return JumpTableInfo;
247 
248  JumpTableInfo = new (Allocator)
250  return JumpTableInfo;
251 }
252 
253 /// Should we be emitting segmented stack stuff for the function
255  return getFunction().hasFnAttribute("split-stack");
256 }
257 
258 /// This discards all of the MachineBasicBlock numbers and recomputes them.
259 /// This guarantees that the MBB numbers are sequential, dense, and match the
260 /// ordering of the blocks within the function. If a specific MachineBasicBlock
261 /// is specified, only that block and those after it are renumbered.
263  if (empty()) { MBBNumbering.clear(); return; }
264  MachineFunction::iterator MBBI, E = end();
265  if (MBB == nullptr)
266  MBBI = begin();
267  else
268  MBBI = MBB->getIterator();
269 
270  // Figure out the block number this should have.
271  unsigned BlockNo = 0;
272  if (MBBI != begin())
273  BlockNo = std::prev(MBBI)->getNumber() + 1;
274 
275  for (; MBBI != E; ++MBBI, ++BlockNo) {
276  if (MBBI->getNumber() != (int)BlockNo) {
277  // Remove use of the old number.
278  if (MBBI->getNumber() != -1) {
279  assert(MBBNumbering[MBBI->getNumber()] == &*MBBI &&
280  "MBB number mismatch!");
281  MBBNumbering[MBBI->getNumber()] = nullptr;
282  }
283 
284  // If BlockNo is already taken, set that block's number to -1.
285  if (MBBNumbering[BlockNo])
286  MBBNumbering[BlockNo]->setNumber(-1);
287 
288  MBBNumbering[BlockNo] = &*MBBI;
289  MBBI->setNumber(BlockNo);
290  }
291  }
292 
293  // Okay, all the blocks are renumbered. If we have compactified the block
294  // numbering, shrink MBBNumbering now.
295  assert(BlockNo <= MBBNumbering.size() && "Mismatch!");
296  MBBNumbering.resize(BlockNo);
297 }
298 
299 /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'.
301  const DebugLoc &DL,
302  bool NoImp) {
303  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
304  MachineInstr(*this, MCID, DL, NoImp);
305 }
306 
307 /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
308 /// identical in all ways except the instruction has no parent, prev, or next.
309 MachineInstr *
311  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
312  MachineInstr(*this, *Orig);
313 }
314 
316  MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
317  MachineInstr *FirstClone = nullptr;
319  while (true) {
320  MachineInstr *Cloned = CloneMachineInstr(&*I);
321  MBB.insert(InsertBefore, Cloned);
322  if (FirstClone == nullptr) {
323  FirstClone = Cloned;
324  } else {
325  Cloned->bundleWithPred();
326  }
327 
328  if (!I->isBundledWithSucc())
329  break;
330  ++I;
331  }
332  return *FirstClone;
333 }
334 
335 /// Delete the given MachineInstr.
336 ///
337 /// This function also serves as the MachineInstr destructor - the real
338 /// ~MachineInstr() destructor must be empty.
339 void
341  // Strip it for parts. The operand array and the MI object itself are
342  // independently recyclable.
343  if (MI->Operands)
344  deallocateOperandArray(MI->CapOperands, MI->Operands);
345  // Don't call ~MachineInstr() which must be trivial anyway because
346  // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
347  // destructors.
348  InstructionRecycler.Deallocate(Allocator, MI);
349 }
350 
351 /// Allocate a new MachineBasicBlock. Use this instead of
352 /// `new MachineBasicBlock'.
355  return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
356  MachineBasicBlock(*this, bb);
357 }
358 
359 /// Delete the given MachineBasicBlock.
360 void
362  assert(MBB->getParent() == this && "MBB parent mismatch!");
363  MBB->~MachineBasicBlock();
364  BasicBlockRecycler.Deallocate(Allocator, MBB);
365 }
366 
368  MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
369  unsigned base_alignment, const AAMDNodes &AAInfo, const MDNode *Ranges,
370  SyncScope::ID SSID, AtomicOrdering Ordering,
371  AtomicOrdering FailureOrdering) {
372  return new (Allocator)
373  MachineMemOperand(PtrInfo, f, s, base_alignment, AAInfo, Ranges,
374  SSID, Ordering, FailureOrdering);
375 }
376 
379  int64_t Offset, uint64_t Size) {
380  if (MMO->getValue())
381  return new (Allocator)
383  MMO->getOffset()+Offset),
384  MMO->getFlags(), Size, MMO->getBaseAlignment(),
385  AAMDNodes(), nullptr, MMO->getSyncScopeID(),
386  MMO->getOrdering(), MMO->getFailureOrdering());
387  return new (Allocator)
389  MMO->getOffset()+Offset),
390  MMO->getFlags(), Size, MMO->getBaseAlignment(),
391  AAMDNodes(), nullptr, MMO->getSyncScopeID(),
392  MMO->getOrdering(), MMO->getFailureOrdering());
393 }
394 
397  const AAMDNodes &AAInfo) {
398  MachinePointerInfo MPI = MMO->getValue() ?
399  MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
401 
402  return new (Allocator)
403  MachineMemOperand(MPI, MMO->getFlags(), MMO->getSize(),
404  MMO->getBaseAlignment(), AAInfo,
405  MMO->getRanges(), MMO->getSyncScopeID(),
406  MMO->getOrdering(), MMO->getFailureOrdering());
407 }
408 
411  return Allocator.Allocate<MachineMemOperand *>(Num);
412 }
413 
414 std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
417  // Count the number of load mem refs.
418  unsigned Num = 0;
419  for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
420  if ((*I)->isLoad())
421  ++Num;
422 
423  // Allocate a new array and populate it with the load information.
425  unsigned Index = 0;
426  for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
427  if ((*I)->isLoad()) {
428  if (!(*I)->isStore())
429  // Reuse the MMO.
430  Result[Index] = *I;
431  else {
432  // Clone the MMO and unset the store flag.
433  MachineMemOperand *JustLoad =
434  getMachineMemOperand((*I)->getPointerInfo(),
435  (*I)->getFlags() & ~MachineMemOperand::MOStore,
436  (*I)->getSize(), (*I)->getBaseAlignment(),
437  (*I)->getAAInfo(), nullptr,
438  (*I)->getSyncScopeID(), (*I)->getOrdering(),
439  (*I)->getFailureOrdering());
440  Result[Index] = JustLoad;
441  }
442  ++Index;
443  }
444  }
445  return std::make_pair(Result, Result + Num);
446 }
447 
448 std::pair<MachineInstr::mmo_iterator, MachineInstr::mmo_iterator>
451  // Count the number of load mem refs.
452  unsigned Num = 0;
453  for (MachineInstr::mmo_iterator I = Begin; I != End; ++I)
454  if ((*I)->isStore())
455  ++Num;
456 
457  // Allocate a new array and populate it with the store information.
459  unsigned Index = 0;
460  for (MachineInstr::mmo_iterator I = Begin; I != End; ++I) {
461  if ((*I)->isStore()) {
462  if (!(*I)->isLoad())
463  // Reuse the MMO.
464  Result[Index] = *I;
465  else {
466  // Clone the MMO and unset the load flag.
467  MachineMemOperand *JustStore =
468  getMachineMemOperand((*I)->getPointerInfo(),
469  (*I)->getFlags() & ~MachineMemOperand::MOLoad,
470  (*I)->getSize(), (*I)->getBaseAlignment(),
471  (*I)->getAAInfo(), nullptr,
472  (*I)->getSyncScopeID(), (*I)->getOrdering(),
473  (*I)->getFailureOrdering());
474  Result[Index] = JustStore;
475  }
476  ++Index;
477  }
478  }
479  return std::make_pair(Result, Result + Num);
480 }
481 
483  char *Dest = Allocator.Allocate<char>(Name.size() + 1);
484  std::copy(Name.begin(), Name.end(), Dest);
485  Dest[Name.size()] = 0;
486  return Dest;
487 }
488 
489 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
491  print(dbgs());
492 }
493 #endif
494 
496  return getFunction().getName();
497 }
498 
499 void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
500  OS << "# Machine code for function " << getName() << ": ";
501  getProperties().print(OS);
502  OS << '\n';
503 
504  // Print Frame Information
505  FrameInfo->print(*this, OS);
506 
507  // Print JumpTable Information
508  if (JumpTableInfo)
509  JumpTableInfo->print(OS);
510 
511  // Print Constant Pool
512  ConstantPool->print(OS);
513 
515 
516  if (RegInfo && !RegInfo->livein_empty()) {
517  OS << "Function Live Ins: ";
519  I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
520  OS << printReg(I->first, TRI);
521  if (I->second)
522  OS << " in " << printReg(I->second, TRI);
523  if (std::next(I) != E)
524  OS << ", ";
525  }
526  OS << '\n';
527  }
528 
531  for (const auto &BB : *this) {
532  OS << '\n';
533  // If we print the whole function, print it at its most verbose level.
534  BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
535  }
536 
537  OS << "\n# End machine code for function " << getName() << ".\n\n";
538 }
539 
540 namespace llvm {
541 
542  template<>
545 
546  static std::string getGraphName(const MachineFunction *F) {
547  return ("CFG for '" + F->getName() + "' function").str();
548  }
549 
550  std::string getNodeLabel(const MachineBasicBlock *Node,
551  const MachineFunction *Graph) {
552  std::string OutStr;
553  {
554  raw_string_ostream OSS(OutStr);
555 
556  if (isSimple()) {
557  OSS << printMBBReference(*Node);
558  if (const BasicBlock *BB = Node->getBasicBlock())
559  OSS << ": " << BB->getName();
560  } else
561  Node->print(OSS);
562  }
563 
564  if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
565 
566  // Process string output to make it nicer...
567  for (unsigned i = 0; i != OutStr.length(); ++i)
568  if (OutStr[i] == '\n') { // Left justify
569  OutStr[i] = '\\';
570  OutStr.insert(OutStr.begin()+i+1, 'l');
571  }
572  return OutStr;
573  }
574  };
575 
576 } // end namespace llvm
577 
579 {
580 #ifndef NDEBUG
581  ViewGraph(this, "mf" + getName());
582 #else
583  errs() << "MachineFunction::viewCFG is only available in debug builds on "
584  << "systems with Graphviz or gv!\n";
585 #endif // NDEBUG
586 }
587 
589 {
590 #ifndef NDEBUG
591  ViewGraph(this, "mf" + getName(), true);
592 #else
593  errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
594  << "systems with Graphviz or gv!\n";
595 #endif // NDEBUG
596 }
597 
598 /// Add the specified physical register as a live-in value and
599 /// create a corresponding virtual register for it.
600 unsigned MachineFunction::addLiveIn(unsigned PReg,
601  const TargetRegisterClass *RC) {
603  unsigned VReg = MRI.getLiveInVirtReg(PReg);
604  if (VReg) {
605  const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
606  (void)VRegRC;
607  // A physical register can be added several times.
608  // Between two calls, the register class of the related virtual register
609  // may have been constrained to match some operation constraints.
610  // In that case, check that the current register class includes the
611  // physical register and is a sub class of the specified RC.
612  assert((VRegRC == RC || (VRegRC->contains(PReg) &&
613  RC->hasSubClassEq(VRegRC))) &&
614  "Register class mismatch!");
615  return VReg;
616  }
617  VReg = MRI.createVirtualRegister(RC);
618  MRI.addLiveIn(PReg, VReg);
619  return VReg;
620 }
621 
622 /// Return the MCSymbol for the specified non-empty jump table.
623 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
624 /// normal 'L' label is returned.
626  bool isLinkerPrivate) const {
627  const DataLayout &DL = getDataLayout();
628  assert(JumpTableInfo && "No jump tables");
629  assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
630 
631  StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
632  : DL.getPrivateGlobalPrefix();
634  raw_svector_ostream(Name)
635  << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
636  return Ctx.getOrCreateSymbol(Name);
637 }
638 
639 /// Return a function-local symbol to represent the PIC base.
641  const DataLayout &DL = getDataLayout();
642  return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
643  Twine(getFunctionNumber()) + "$pb");
644 }
645 
646 /// \name Exception Handling
647 /// \{
648 
651  unsigned N = LandingPads.size();
652  for (unsigned i = 0; i < N; ++i) {
653  LandingPadInfo &LP = LandingPads[i];
654  if (LP.LandingPadBlock == LandingPad)
655  return LP;
656  }
657 
658  LandingPads.push_back(LandingPadInfo(LandingPad));
659  return LandingPads[N];
660 }
661 
663  MCSymbol *BeginLabel, MCSymbol *EndLabel) {
664  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
665  LP.BeginLabels.push_back(BeginLabel);
666  LP.EndLabels.push_back(EndLabel);
667 }
668 
670  MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
671  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
672  LP.LandingPadLabel = LandingPadLabel;
673  return LandingPadLabel;
674 }
675 
678  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
679  for (unsigned N = TyInfo.size(); N; --N)
680  LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
681 }
682 
685  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
686  std::vector<unsigned> IdsInFilter(TyInfo.size());
687  for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
688  IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
689  LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
690 }
691 
693  for (unsigned i = 0; i != LandingPads.size(); ) {
694  LandingPadInfo &LandingPad = LandingPads[i];
695  if (LandingPad.LandingPadLabel &&
696  !LandingPad.LandingPadLabel->isDefined() &&
697  (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
698  LandingPad.LandingPadLabel = nullptr;
699 
700  // Special case: we *should* emit LPs with null LP MBB. This indicates
701  // "nounwind" case.
702  if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
703  LandingPads.erase(LandingPads.begin() + i);
704  continue;
705  }
706 
707  for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
708  MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
709  MCSymbol *EndLabel = LandingPad.EndLabels[j];
710  if ((BeginLabel->isDefined() ||
711  (LPMap && (*LPMap)[BeginLabel] != 0)) &&
712  (EndLabel->isDefined() ||
713  (LPMap && (*LPMap)[EndLabel] != 0))) continue;
714 
715  LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
716  LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
717  --j;
718  --e;
719  }
720 
721  // Remove landing pads with no try-ranges.
722  if (LandingPads[i].BeginLabels.empty()) {
723  LandingPads.erase(LandingPads.begin() + i);
724  continue;
725  }
726 
727  // If there is no landing pad, ensure that the list of typeids is empty.
728  // If the only typeid is a cleanup, this is the same as having no typeids.
729  if (!LandingPad.LandingPadBlock ||
730  (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
731  LandingPad.TypeIds.clear();
732  ++i;
733  }
734 }
735 
737  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
738  LP.TypeIds.push_back(0);
739 }
740 
742  const Function *Filter,
743  const BlockAddress *RecoverBA) {
744  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
745  SEHHandler Handler;
746  Handler.FilterOrFinally = Filter;
747  Handler.RecoverBA = RecoverBA;
748  LP.SEHHandlers.push_back(Handler);
749 }
750 
752  const Function *Cleanup) {
753  LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
754  SEHHandler Handler;
755  Handler.FilterOrFinally = Cleanup;
756  Handler.RecoverBA = nullptr;
757  LP.SEHHandlers.push_back(Handler);
758 }
759 
761  ArrayRef<unsigned> Sites) {
762  LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
763 }
764 
766  for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
767  if (TypeInfos[i] == TI) return i + 1;
768 
769  TypeInfos.push_back(TI);
770  return TypeInfos.size();
771 }
772 
773 int MachineFunction::getFilterIDFor(std::vector<unsigned> &TyIds) {
774  // If the new filter coincides with the tail of an existing filter, then
775  // re-use the existing filter. Folding filters more than this requires
776  // re-ordering filters and/or their elements - probably not worth it.
777  for (std::vector<unsigned>::iterator I = FilterEnds.begin(),
778  E = FilterEnds.end(); I != E; ++I) {
779  unsigned i = *I, j = TyIds.size();
780 
781  while (i && j)
782  if (FilterIds[--i] != TyIds[--j])
783  goto try_next;
784 
785  if (!j)
786  // The new filter coincides with range [i, end) of the existing filter.
787  return -(1 + i);
788 
789 try_next:;
790  }
791 
792  // Add the new filter.
793  int FilterID = -(1 + FilterIds.size());
794  FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
795  FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
796  FilterEnds.push_back(FilterIds.size());
797  FilterIds.push_back(0); // terminator
798  return FilterID;
799 }
800 
802  MachineFunction &MF = *MBB.getParent();
803  if (const auto *PF = dyn_cast<Function>(
805  MF.getMMI().addPersonality(PF);
806 
807  if (I.isCleanup())
808  MF.addCleanup(&MBB);
809 
810  // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct,
811  // but we need to do it this way because of how the DWARF EH emitter
812  // processes the clauses.
813  for (unsigned i = I.getNumClauses(); i != 0; --i) {
814  Value *Val = I.getClause(i - 1);
815  if (I.isCatch(i - 1)) {
816  MF.addCatchTypeInfo(&MBB,
817  dyn_cast<GlobalValue>(Val->stripPointerCasts()));
818  } else {
819  // Add filters in a list.
820  Constant *CVal = cast<Constant>(Val);
822  for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
823  II != IE; ++II)
824  FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
825 
826  MF.addFilterTypeInfo(&MBB, FilterList);
827  }
828  }
829 }
830 
831 /// \}
832 
833 //===----------------------------------------------------------------------===//
834 // MachineJumpTableInfo implementation
835 //===----------------------------------------------------------------------===//
836 
837 /// Return the size of each entry in the jump table.
839  // The size of a jump table entry is 4 bytes unless the entry is just the
840  // address of a block, in which case it is the pointer size.
841  switch (getEntryKind()) {
843  return TD.getPointerSize();
845  return 8;
849  return 4;
851  return 0;
852  }
853  llvm_unreachable("Unknown jump table encoding!");
854 }
855 
856 /// Return the alignment of each entry in the jump table.
858  // The alignment of a jump table entry is the alignment of int32 unless the
859  // entry is just the address of a block, in which case it is the pointer
860  // alignment.
861  switch (getEntryKind()) {
863  return TD.getPointerABIAlignment(0);
865  return TD.getABIIntegerTypeAlignment(64);
869  return TD.getABIIntegerTypeAlignment(32);
871  return 1;
872  }
873  llvm_unreachable("Unknown jump table encoding!");
874 }
875 
876 /// Create a new jump table entry in the jump table info.
878  const std::vector<MachineBasicBlock*> &DestBBs) {
879  assert(!DestBBs.empty() && "Cannot create an empty jump table!");
880  JumpTables.push_back(MachineJumpTableEntry(DestBBs));
881  return JumpTables.size()-1;
882 }
883 
884 /// If Old is the target of any jump tables, update the jump tables to branch
885 /// to New instead.
887  MachineBasicBlock *New) {
888  assert(Old != New && "Not making a change?");
889  bool MadeChange = false;
890  for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
891  ReplaceMBBInJumpTable(i, Old, New);
892  return MadeChange;
893 }
894 
895 /// If Old is a target of the jump tables, update the jump table to branch to
896 /// New instead.
898  MachineBasicBlock *Old,
899  MachineBasicBlock *New) {
900  assert(Old != New && "Not making a change?");
901  bool MadeChange = false;
902  MachineJumpTableEntry &JTE = JumpTables[Idx];
903  for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
904  if (JTE.MBBs[j] == Old) {
905  JTE.MBBs[j] = New;
906  MadeChange = true;
907  }
908  return MadeChange;
909 }
910 
912  if (JumpTables.empty()) return;
913 
914  OS << "Jump Tables:\n";
915 
916  for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
917  OS << printJumpTableEntryReference(i) << ": ";
918  for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
919  OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
920  }
921 
922  OS << '\n';
923 }
924 
925 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
927 #endif
928 
930  return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
931 }
932 
933 //===----------------------------------------------------------------------===//
934 // MachineConstantPool implementation
935 //===----------------------------------------------------------------------===//
936 
937 void MachineConstantPoolValue::anchor() {}
938 
940  if (isMachineConstantPoolEntry())
941  return Val.MachineCPVal->getType();
942  return Val.ConstVal->getType();
943 }
944 
946  if (isMachineConstantPoolEntry())
947  return true;
948  return Val.ConstVal->needsRelocation();
949 }
950 
953  if (needsRelocation())
955  switch (DL->getTypeAllocSize(getType())) {
956  case 4:
958  case 8:
960  case 16:
962  case 32:
964  default:
965  return SectionKind::getReadOnly();
966  }
967 }
968 
970  // A constant may be a member of both Constants and MachineCPVsSharingEntries,
971  // so keep track of which we've deleted to avoid double deletions.
973  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
974  if (Constants[i].isMachineConstantPoolEntry()) {
975  Deleted.insert(Constants[i].Val.MachineCPVal);
976  delete Constants[i].Val.MachineCPVal;
977  }
979  MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
980  I != E; ++I) {
981  if (Deleted.count(*I) == 0)
982  delete *I;
983  }
984 }
985 
986 /// Test whether the given two constants can be allocated the same constant pool
987 /// entry.
988 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
989  const DataLayout &DL) {
990  // Handle the trivial case quickly.
991  if (A == B) return true;
992 
993  // If they have the same type but weren't the same constant, quickly
994  // reject them.
995  if (A->getType() == B->getType()) return false;
996 
997  // We can't handle structs or arrays.
998  if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
999  isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
1000  return false;
1001 
1002  // For now, only support constants with the same size.
1003  uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
1004  if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
1005  return false;
1006 
1007  Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
1008 
1009  // Try constant folding a bitcast of both instructions to an integer. If we
1010  // get two identical ConstantInt's, then we are good to share them. We use
1011  // the constant folding APIs to do this so that we get the benefit of
1012  // DataLayout.
1013  if (isa<PointerType>(A->getType()))
1014  A = ConstantFoldCastOperand(Instruction::PtrToInt,
1015  const_cast<Constant *>(A), IntTy, DL);
1016  else if (A->getType() != IntTy)
1017  A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
1018  IntTy, DL);
1019  if (isa<PointerType>(B->getType()))
1020  B = ConstantFoldCastOperand(Instruction::PtrToInt,
1021  const_cast<Constant *>(B), IntTy, DL);
1022  else if (B->getType() != IntTy)
1023  B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
1024  IntTy, DL);
1025 
1026  return A == B;
1027 }
1028 
1029 /// Create a new entry in the constant pool or return an existing one.
1030 /// User must specify the log2 of the minimum required alignment for the object.
1032  unsigned Alignment) {
1033  assert(Alignment && "Alignment must be specified!");
1034  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1035 
1036  // Check to see if we already have this constant.
1037  //
1038  // FIXME, this could be made much more efficient for large constant pools.
1039  for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1040  if (!Constants[i].isMachineConstantPoolEntry() &&
1041  CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1042  if ((unsigned)Constants[i].getAlignment() < Alignment)
1043  Constants[i].Alignment = Alignment;
1044  return i;
1045  }
1046 
1047  Constants.push_back(MachineConstantPoolEntry(C, Alignment));
1048  return Constants.size()-1;
1049 }
1050 
1052  unsigned Alignment) {
1053  assert(Alignment && "Alignment must be specified!");
1054  if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1055 
1056  // Check to see if we already have this constant.
1057  //
1058  // FIXME, this could be made much more efficient for large constant pools.
1059  int Idx = V->getExistingMachineCPValue(this, Alignment);
1060  if (Idx != -1) {
1061  MachineCPVsSharingEntries.insert(V);
1062  return (unsigned)Idx;
1063  }
1064 
1065  Constants.push_back(MachineConstantPoolEntry(V, Alignment));
1066  return Constants.size()-1;
1067 }
1068 
1070  if (Constants.empty()) return;
1071 
1072  OS << "Constant Pool:\n";
1073  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
1074  OS << " cp#" << i << ": ";
1075  if (Constants[i].isMachineConstantPoolEntry())
1076  Constants[i].Val.MachineCPVal->print(OS);
1077  else
1078  Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1079  OS << ", align=" << Constants[i].getAlignment();
1080  OS << "\n";
1081  }
1082 }
1083 
1084 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1086 #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.
void push_back(const T &Elt)
Definition: SmallVector.h:213
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
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:327
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
livein_iterator livein_begin() const
static SectionKind getMergeableConst32()
Definition: SectionKind.h:195
iterator erase(iterator where)
Definition: ilist.h:267
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MachineFunctionProperties & reset(Property P)
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. Returns the label ID for the landing pad entry.
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:294
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
iterator begin() const
Definition: ArrayRef.h:137
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:221
void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB)
Extract the exception handling information from the landingpad instruction and add them to the specif...
unsigned size() const
AtomicOrdering getFailureOrdering() const
For cmpxchg atomic operations, return the atomic ordering requirements when store does not occur...
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:162
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
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:193
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:714
static SectionKind getMergeableConst16()
Definition: SectionKind.h:194
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:307
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:504
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
F(f)
MachineModuleInfo & getMMI() const
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:452
Manage lifetime of a slot tracker for printing IR.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
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:611
StringRef getLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:274
static SectionKind getMergeableConst4()
Definition: SectionKind.h:192
op_iterator op_begin()
Definition: User.h:230
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...
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:836
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:361
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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:56
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...
std::pair< MachineInstr::mmo_iterator, MachineInstr::mmo_iterator > extractLoadMemRefs(MachineInstr::mmo_iterator Begin, MachineInstr::mmo_iterator End)
extractLoadMemRefs - Allocate an array and populate it with just the load information from the given ...
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.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
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:63
unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
This structure is used to retain landing pad info for the current function.
AtomicOrdering getOrdering() const
Return the atomic ordering requirements for this memory operation.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
SlotIndexes pass.
Definition: SlotIndexes.h:331
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:33
EK_BlockAddress - Each entry is a plain address of block, e.g.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
unsigned getPrefFunctionAlignment() const
Return the preferred function alignment.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:688
This class is a data container for one entry in a MachineConstantPool.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineFunction(const Function &F, const TargetMachine &Target, const TargetSubtargetInfo &STI, unsigned FunctionNum, MachineModuleInfo &MMI)
const Value * getValue() const
Return the base address of the memory access.
#define P(N)
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:410
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about constant pool objects...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
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:59
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)
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:149
void addPersonality(const Function *Personality)
Provide the personality function for the exception information.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
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:629
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.
op_iterator op_end()
Definition: User.h:232
std::vector< int > TypeIds
const PseudoSourceValue * getPseudoValue() const
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:23
self_iterator getIterator()
Definition: ilist_node.h:82
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run &#39;dot&#39;, run gv on the postscript file, then cleanup.
Definition: GraphWriter.h:348
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:835
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
const Constant * stripPointerCasts() const
Definition: Constant.h:173
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:539
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:240
Iterator for intrusive lists based on ilist_node.
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
Module.h This file contains the declarations for the Module class.
iterator end() const
Definition: ArrayRef.h:138
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:642
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:203
unsigned getABIIntegerTypeAlignment(unsigned BitWidth) const
Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.
Definition: DataLayout.cpp:728
void addCatchTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue *> TyInfo)
Provide the catch typeinfo for a landing pad.
void clear(AllocatorType &Allocator)
Release all the tracked allocations to the allocator.
static void deleteNode(NodeTy *V)
Definition: ilist.h:42
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:133
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:248
Target - Wrapper for Target specific information.
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
bool isCleanup() const
Return &#39;true&#39; if this landingpad instruction is a cleanup.
MachineJumpTableEntry - One jump table in the jump table info.
iterator begin() const
Definition: StringRef.h:106
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:428
static const char * getPropertyName(MachineFunctionProperties::Property Prop)
Representation of each machine instruction.
Definition: MachineInstr.h:60
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isCatch(unsigned Idx) const
Return &#39;true&#39; if the clause and index Idx is a catch clause.
Flags getFlags() const
Return the raw flags of the source value,.
virtual const TargetFrameLowering * getFrameLowering() const
SectionKind getSectionKind(const DataLayout *DL) const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
size_type size() const
size - Returns the number of bits in this bitvector.
Definition: BitVector.h:170
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
void dump() const
dump - Call print(cerr) to be called from the debugger.
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
std::pair< MachineInstr::mmo_iterator, MachineInstr::mmo_iterator > extractStoreMemRefs(MachineInstr::mmo_iterator Begin, MachineInstr::mmo_iterator End)
extractStoreMemRefs - Allocate an array and populate it with just the store information from the give...
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:477
aarch64 promote const
LandingPadInfo & getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad)
Find or create an LandingPadInfo for the specified MachineBasicBlock.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
LLVM Value Representation.
Definition: Value.h:73
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1288
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:411
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID for this memory operation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
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:46
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
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:49
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:38
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:973
iterator end() const
Definition: StringRef.h:108
VariableDbgInfoMapTy VariableDbgInfos
static SectionKind getReadOnly()
Definition: SectionKind.h:182
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry...
This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
void addFilterTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue *> TyInfo)
Provide the filter typeinfo for a landing pad.
const BasicBlock * getParent() const
Definition: Instruction.h:67
void tidyLandingPads(DenseMap< MCSymbol *, uintptr_t > *LPMap=nullptr)
Remap landing pad labels and remove any deleted landing pads.