xref: /llvm-project/llvm/lib/CodeGen/MachineFunction.cpp (revision 7fe9435dc88050ee78eb1d4adec87610dce468f7)
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 
15 #include "llvm/CodeGen/MachineFunction.h"
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"
24 #include "llvm/Analysis/ConstantFolding.h"
25 #include "llvm/Analysis/EHPersonalities.h"
26 #include "llvm/CodeGen/MachineBasicBlock.h"
27 #include "llvm/CodeGen/MachineConstantPool.h"
28 #include "llvm/CodeGen/MachineFrameInfo.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/CodeGen/MachineJumpTableInfo.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/CodeGen/MachineModuleInfo.h"
33 #include "llvm/CodeGen/MachineRegisterInfo.h"
34 #include "llvm/CodeGen/PseudoSourceValue.h"
35 #include "llvm/CodeGen/TargetFrameLowering.h"
36 #include "llvm/CodeGen/TargetLowering.h"
37 #include "llvm/CodeGen/TargetRegisterInfo.h"
38 #include "llvm/CodeGen/TargetSubtargetInfo.h"
39 #include "llvm/CodeGen/WasmEHFuncInfo.h"
40 #include "llvm/CodeGen/WinEHFuncInfo.h"
41 #include "llvm/Config/llvm-config.h"
42 #include "llvm/IR/Attributes.h"
43 #include "llvm/IR/BasicBlock.h"
44 #include "llvm/IR/Constant.h"
45 #include "llvm/IR/DataLayout.h"
46 #include "llvm/IR/DebugInfoMetadata.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"
54 #include "llvm/IR/ModuleSlotTracker.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"
60 #include "llvm/Support/CommandLine.h"
61 #include "llvm/Support/Compiler.h"
62 #include "llvm/Support/DOTGraphTraits.h"
63 #include "llvm/Support/Debug.h"
64 #include "llvm/Support/ErrorHandling.h"
65 #include "llvm/Support/GraphWriter.h"
66 #include "llvm/Support/raw_ostream.h"
67 #include "llvm/Target/TargetMachine.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> AlignAllFunctions(
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 
87 static const char *getPropertyName(MachineFunctionProperties::Property Prop) {
88   using P = MachineFunctionProperties::Property;
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 
106 void MachineFunctionProperties::print(raw_ostream &OS) const {
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.
121 MachineFunctionInfo::~MachineFunctionInfo() = default;
122 
123 void ilist_alloc_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
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 
134 MachineFunction::MachineFunction(const Function &F,
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.
155   Properties.set(MachineFunctionProperties::Property::IsSSA);
156   Properties.set(MachineFunctionProperties::Property::TracksLiveness);
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,
182                          STI->getTargetLowering()->getPrefFunctionAlignment());
183 
184   if (AlignAllFunctions)
185     Alignment = Align(1ULL << AlignAllFunctions);
186 
187   JumpTableInfo = nullptr;
188 
189   if (isFuncletEHPersonality(classifyEHPersonality(
190           F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
191     WinEHInfo = new (Allocator) WinEHFuncInfo();
192   }
193 
194   if (isScopedEHPersonality(classifyEHPersonality(
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 
208 MachineFunction::~MachineFunction() {
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();
226   VariableDbgInfos.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 
258 const DataLayout &MachineFunction::getDataLayout() const {
259   return F.getParent()->getDataLayout();
260 }
261 
262 /// Get the JumpTableInfo for this function.
263 /// If it does not already exist, allocate one.
264 MachineJumpTableInfo *MachineFunction::
265 getOrCreateJumpTableInfo(unsigned EntryKind) {
266   if (JumpTableInfo) return JumpTableInfo;
267 
268   JumpTableInfo = new (Allocator)
269     MachineJumpTableInfo((MachineJumpTableInfo::JTEntryKind)EntryKind);
270   return JumpTableInfo;
271 }
272 
273 DenormalMode MachineFunction::getDenormalMode(const fltSemantics &FPType) const {
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
289 bool MachineFunction::shouldSplitStack() const {
290   return getFunction().hasFnAttribute("split-stack");
291 }
292 
293 LLVM_NODISCARD unsigned
294 MachineFunction::addFrameInst(const MCCFIInstruction &Inst) {
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.
303 void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) {
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'.
341 MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID,
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 *
351 MachineFunction::CloneMachineInstr(const MachineInstr *Orig) {
352   return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
353              MachineInstr(*this, *Orig);
354 }
355 
356 MachineInstr &MachineFunction::CloneMachineInstrBundle(MachineBasicBlock &MBB,
357     MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
358   MachineInstr *FirstClone = nullptr;
359   MachineBasicBlock::const_instr_iterator I = Orig.getIterator();
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
381 MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
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().
386   assert((!MI->isCall(MachineInstr::IgnoreBundle) ||
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'.
401 MachineBasicBlock *
402 MachineFunction::CreateMachineBasicBlock(const BasicBlock *bb) {
403   return new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
404              MachineBasicBlock(*this, bb);
405 }
406 
407 /// Delete the given MachineBasicBlock.
408 void
409 MachineFunction::DeleteMachineBasicBlock(MachineBasicBlock *MBB) {
410   assert(MBB->getParent() == this && "MBB parent mismatch!");
411   MBB->~MachineBasicBlock();
412   BasicBlockRecycler.Deallocate(Allocator, MBB);
413 }
414 
415 MachineMemOperand *MachineFunction::getMachineMemOperand(
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 
425 MachineMemOperand *
426 MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
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 
442 MachineMemOperand *
443 MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
444                                       const AAMDNodes &AAInfo) {
445   MachinePointerInfo MPI = MMO->getValue() ?
446              MachinePointerInfo(MMO->getValue(), MMO->getOffset()) :
447              MachinePointerInfo(MMO->getPseudoValue(), 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 
456 MachineMemOperand *
457 MachineFunction::getMachineMemOperand(const MachineMemOperand *MMO,
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 
472 const char *MachineFunction::createExternalSymbolName(StringRef Name) {
473   char *Dest = Allocator.Allocate<char>(Name.size() + 1);
474   llvm::copy(Name, Dest);
475   Dest[Name.size()] = 0;
476   return Dest;
477 }
478 
479 uint32_t *MachineFunction::allocateRegMask() {
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 
487 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
488 LLVM_DUMP_METHOD void MachineFunction::dump() const {
489   print(dbgs());
490 }
491 #endif
492 
493 StringRef MachineFunction::getName() const {
494   return getFunction().getName();
495 }
496 
497 void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {
498   OS << "# Machine code for function " << getName() << ": ";
499   getProperties().print(OS);
500   OS << '\n';
501 
502   // Print Frame Information
503   FrameInfo->print(*this, OS);
504 
505   // Print JumpTable Information
506   if (JumpTableInfo)
507     JumpTableInfo->print(OS);
508 
509   // Print Constant Pool
510   ConstantPool->print(OS);
511 
512   const TargetRegisterInfo *TRI = getSubtarget().getRegisterInfo();
513 
514   if (RegInfo && !RegInfo->livein_empty()) {
515     OS << "Function Live Ins: ";
516     for (MachineRegisterInfo::livein_iterator
517          I = RegInfo->livein_begin(), E = RegInfo->livein_end(); I != E; ++I) {
518       OS << printReg(I->first, TRI);
519       if (I->second)
520         OS << " in " << printReg(I->second, TRI);
521       if (std::next(I) != E)
522         OS << ", ";
523     }
524     OS << '\n';
525   }
526 
527   ModuleSlotTracker MST(getFunction().getParent());
528   MST.incorporateFunction(getFunction());
529   for (const auto &BB : *this) {
530     OS << '\n';
531     // If we print the whole function, print it at its most verbose level.
532     BB.print(OS, MST, Indexes, /*IsStandalone=*/true);
533   }
534 
535   OS << "\n# End machine code for function " << getName() << ".\n\n";
536 }
537 
538 /// True if this function needs frame moves for debug or exceptions.
539 bool MachineFunction::needsFrameMoves() const {
540   return getMMI().hasDebugInfo() ||
541          getTarget().Options.ForceDwarfFrameSection ||
542          F.needsUnwindTableEntry();
543 }
544 
545 namespace llvm {
546 
547   template<>
548   struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
549     DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
550 
551     static std::string getGraphName(const MachineFunction *F) {
552       return ("CFG for '" + F->getName() + "' function").str();
553     }
554 
555     std::string getNodeLabel(const MachineBasicBlock *Node,
556                              const MachineFunction *Graph) {
557       std::string OutStr;
558       {
559         raw_string_ostream OSS(OutStr);
560 
561         if (isSimple()) {
562           OSS << printMBBReference(*Node);
563           if (const BasicBlock *BB = Node->getBasicBlock())
564             OSS << ": " << BB->getName();
565         } else
566           Node->print(OSS);
567       }
568 
569       if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
570 
571       // Process string output to make it nicer...
572       for (unsigned i = 0; i != OutStr.length(); ++i)
573         if (OutStr[i] == '\n') {                            // Left justify
574           OutStr[i] = '\\';
575           OutStr.insert(OutStr.begin()+i+1, 'l');
576         }
577       return OutStr;
578     }
579   };
580 
581 } // end namespace llvm
582 
583 void MachineFunction::viewCFG() const
584 {
585 #ifndef NDEBUG
586   ViewGraph(this, "mf" + getName());
587 #else
588   errs() << "MachineFunction::viewCFG is only available in debug builds on "
589          << "systems with Graphviz or gv!\n";
590 #endif // NDEBUG
591 }
592 
593 void MachineFunction::viewCFGOnly() const
594 {
595 #ifndef NDEBUG
596   ViewGraph(this, "mf" + getName(), true);
597 #else
598   errs() << "MachineFunction::viewCFGOnly is only available in debug builds on "
599          << "systems with Graphviz or gv!\n";
600 #endif // NDEBUG
601 }
602 
603 /// Add the specified physical register as a live-in value and
604 /// create a corresponding virtual register for it.
605 unsigned MachineFunction::addLiveIn(unsigned PReg,
606                                     const TargetRegisterClass *RC) {
607   MachineRegisterInfo &MRI = getRegInfo();
608   unsigned VReg = MRI.getLiveInVirtReg(PReg);
609   if (VReg) {
610     const TargetRegisterClass *VRegRC = MRI.getRegClass(VReg);
611     (void)VRegRC;
612     // A physical register can be added several times.
613     // Between two calls, the register class of the related virtual register
614     // may have been constrained to match some operation constraints.
615     // In that case, check that the current register class includes the
616     // physical register and is a sub class of the specified RC.
617     assert((VRegRC == RC || (VRegRC->contains(PReg) &&
618                              RC->hasSubClassEq(VRegRC))) &&
619             "Register class mismatch!");
620     return VReg;
621   }
622   VReg = MRI.createVirtualRegister(RC);
623   MRI.addLiveIn(PReg, VReg);
624   return VReg;
625 }
626 
627 /// Return the MCSymbol for the specified non-empty jump table.
628 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
629 /// normal 'L' label is returned.
630 MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
631                                         bool isLinkerPrivate) const {
632   const DataLayout &DL = getDataLayout();
633   assert(JumpTableInfo && "No jump tables");
634   assert(JTI < JumpTableInfo->getJumpTables().size() && "Invalid JTI!");
635 
636   StringRef Prefix = isLinkerPrivate ? DL.getLinkerPrivateGlobalPrefix()
637                                      : DL.getPrivateGlobalPrefix();
638   SmallString<60> Name;
639   raw_svector_ostream(Name)
640     << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
641   return Ctx.getOrCreateSymbol(Name);
642 }
643 
644 /// Return a function-local symbol to represent the PIC base.
645 MCSymbol *MachineFunction::getPICBaseSymbol() const {
646   const DataLayout &DL = getDataLayout();
647   return Ctx.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
648                                Twine(getFunctionNumber()) + "$pb");
649 }
650 
651 /// \name Exception Handling
652 /// \{
653 
654 LandingPadInfo &
655 MachineFunction::getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad) {
656   unsigned N = LandingPads.size();
657   for (unsigned i = 0; i < N; ++i) {
658     LandingPadInfo &LP = LandingPads[i];
659     if (LP.LandingPadBlock == LandingPad)
660       return LP;
661   }
662 
663   LandingPads.push_back(LandingPadInfo(LandingPad));
664   return LandingPads[N];
665 }
666 
667 void MachineFunction::addInvoke(MachineBasicBlock *LandingPad,
668                                 MCSymbol *BeginLabel, MCSymbol *EndLabel) {
669   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
670   LP.BeginLabels.push_back(BeginLabel);
671   LP.EndLabels.push_back(EndLabel);
672 }
673 
674 MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) {
675   MCSymbol *LandingPadLabel = Ctx.createTempSymbol();
676   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
677   LP.LandingPadLabel = LandingPadLabel;
678 
679   const Instruction *FirstI = LandingPad->getBasicBlock()->getFirstNonPHI();
680   if (const auto *LPI = dyn_cast<LandingPadInst>(FirstI)) {
681     if (const auto *PF =
682             dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts()))
683       getMMI().addPersonality(PF);
684 
685     if (LPI->isCleanup())
686       addCleanup(LandingPad);
687 
688     // FIXME: New EH - Add the clauses in reverse order. This isn't 100%
689     //        correct, but we need to do it this way because of how the DWARF EH
690     //        emitter processes the clauses.
691     for (unsigned I = LPI->getNumClauses(); I != 0; --I) {
692       Value *Val = LPI->getClause(I - 1);
693       if (LPI->isCatch(I - 1)) {
694         addCatchTypeInfo(LandingPad,
695                          dyn_cast<GlobalValue>(Val->stripPointerCasts()));
696       } else {
697         // Add filters in a list.
698         auto *CVal = cast<Constant>(Val);
699         SmallVector<const GlobalValue *, 4> FilterList;
700         for (User::op_iterator II = CVal->op_begin(), IE = CVal->op_end();
701              II != IE; ++II)
702           FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
703 
704         addFilterTypeInfo(LandingPad, FilterList);
705       }
706     }
707 
708   } else if (const auto *CPI = dyn_cast<CatchPadInst>(FirstI)) {
709     for (unsigned I = CPI->getNumArgOperands(); I != 0; --I) {
710       Value *TypeInfo = CPI->getArgOperand(I - 1)->stripPointerCasts();
711       addCatchTypeInfo(LandingPad, dyn_cast<GlobalValue>(TypeInfo));
712     }
713 
714   } else {
715     assert(isa<CleanupPadInst>(FirstI) && "Invalid landingpad!");
716   }
717 
718   return LandingPadLabel;
719 }
720 
721 void MachineFunction::addCatchTypeInfo(MachineBasicBlock *LandingPad,
722                                        ArrayRef<const GlobalValue *> TyInfo) {
723   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
724   for (unsigned N = TyInfo.size(); N; --N)
725     LP.TypeIds.push_back(getTypeIDFor(TyInfo[N - 1]));
726 }
727 
728 void MachineFunction::addFilterTypeInfo(MachineBasicBlock *LandingPad,
729                                         ArrayRef<const GlobalValue *> TyInfo) {
730   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
731   std::vector<unsigned> IdsInFilter(TyInfo.size());
732   for (unsigned I = 0, E = TyInfo.size(); I != E; ++I)
733     IdsInFilter[I] = getTypeIDFor(TyInfo[I]);
734   LP.TypeIds.push_back(getFilterIDFor(IdsInFilter));
735 }
736 
737 void MachineFunction::tidyLandingPads(DenseMap<MCSymbol *, uintptr_t> *LPMap,
738                                       bool TidyIfNoBeginLabels) {
739   for (unsigned i = 0; i != LandingPads.size(); ) {
740     LandingPadInfo &LandingPad = LandingPads[i];
741     if (LandingPad.LandingPadLabel &&
742         !LandingPad.LandingPadLabel->isDefined() &&
743         (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0))
744       LandingPad.LandingPadLabel = nullptr;
745 
746     // Special case: we *should* emit LPs with null LP MBB. This indicates
747     // "nounwind" case.
748     if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
749       LandingPads.erase(LandingPads.begin() + i);
750       continue;
751     }
752 
753     if (TidyIfNoBeginLabels) {
754       for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
755         MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
756         MCSymbol *EndLabel = LandingPad.EndLabels[j];
757         if ((BeginLabel->isDefined() || (LPMap && (*LPMap)[BeginLabel] != 0)) &&
758             (EndLabel->isDefined() || (LPMap && (*LPMap)[EndLabel] != 0)))
759           continue;
760 
761         LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
762         LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
763         --j;
764         --e;
765       }
766 
767       // Remove landing pads with no try-ranges.
768       if (LandingPads[i].BeginLabels.empty()) {
769         LandingPads.erase(LandingPads.begin() + i);
770         continue;
771       }
772     }
773 
774     // If there is no landing pad, ensure that the list of typeids is empty.
775     // If the only typeid is a cleanup, this is the same as having no typeids.
776     if (!LandingPad.LandingPadBlock ||
777         (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
778       LandingPad.TypeIds.clear();
779     ++i;
780   }
781 }
782 
783 void MachineFunction::addCleanup(MachineBasicBlock *LandingPad) {
784   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
785   LP.TypeIds.push_back(0);
786 }
787 
788 void MachineFunction::addSEHCatchHandler(MachineBasicBlock *LandingPad,
789                                          const Function *Filter,
790                                          const BlockAddress *RecoverBA) {
791   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
792   SEHHandler Handler;
793   Handler.FilterOrFinally = Filter;
794   Handler.RecoverBA = RecoverBA;
795   LP.SEHHandlers.push_back(Handler);
796 }
797 
798 void MachineFunction::addSEHCleanupHandler(MachineBasicBlock *LandingPad,
799                                            const Function *Cleanup) {
800   LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
801   SEHHandler Handler;
802   Handler.FilterOrFinally = Cleanup;
803   Handler.RecoverBA = nullptr;
804   LP.SEHHandlers.push_back(Handler);
805 }
806 
807 void MachineFunction::setCallSiteLandingPad(MCSymbol *Sym,
808                                             ArrayRef<unsigned> Sites) {
809   LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end());
810 }
811 
812 unsigned MachineFunction::getTypeIDFor(const GlobalValue *TI) {
813   for (unsigned i = 0, N = TypeInfos.size(); i != N; ++i)
814     if (TypeInfos[i] == TI) return i + 1;
815 
816   TypeInfos.push_back(TI);
817   return TypeInfos.size();
818 }
819 
820 int MachineFunction::getFilterIDFor(std::vector<unsigned> &TyIds) {
821   // If the new filter coincides with the tail of an existing filter, then
822   // re-use the existing filter.  Folding filters more than this requires
823   // re-ordering filters and/or their elements - probably not worth it.
824   for (std::vector<unsigned>::iterator I = FilterEnds.begin(),
825        E = FilterEnds.end(); I != E; ++I) {
826     unsigned i = *I, j = TyIds.size();
827 
828     while (i && j)
829       if (FilterIds[--i] != TyIds[--j])
830         goto try_next;
831 
832     if (!j)
833       // The new filter coincides with range [i, end) of the existing filter.
834       return -(1 + i);
835 
836 try_next:;
837   }
838 
839   // Add the new filter.
840   int FilterID = -(1 + FilterIds.size());
841   FilterIds.reserve(FilterIds.size() + TyIds.size() + 1);
842   FilterIds.insert(FilterIds.end(), TyIds.begin(), TyIds.end());
843   FilterEnds.push_back(FilterIds.size());
844   FilterIds.push_back(0); // terminator
845   return FilterID;
846 }
847 
848 MachineFunction::CallSiteInfoMap::iterator
849 MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
850   assert(MI->isCall() && "Call site info refers only to call instructions!");
851 
852   if (!Target.Options.EnableDebugEntryValues)
853     return CallSitesInfo.end();
854   return CallSitesInfo.find(MI);
855 }
856 
857 void MachineFunction::moveCallSiteInfo(const MachineInstr *Old,
858                                        const MachineInstr *New) {
859   assert(New->isCall() && "Call site info refers only to call instructions!");
860 
861   CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
862   if (CSIt == CallSitesInfo.end())
863     return;
864 
865   CallSiteInfo CSInfo = std::move(CSIt->second);
866   CallSitesInfo.erase(CSIt);
867   CallSitesInfo[New] = CSInfo;
868 }
869 
870 void MachineFunction::eraseCallSiteInfo(const MachineInstr *MI) {
871   CallSiteInfoMap::iterator CSIt = getCallSiteInfo(MI);
872   if (CSIt == CallSitesInfo.end())
873     return;
874   CallSitesInfo.erase(CSIt);
875 }
876 
877 void MachineFunction::copyCallSiteInfo(const MachineInstr *Old,
878                                        const MachineInstr *New) {
879   assert(New->isCall() && "Call site info refers only to call instructions!");
880 
881   CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
882   if (CSIt == CallSitesInfo.end())
883     return;
884 
885   CallSiteInfo CSInfo = CSIt->second;
886   CallSitesInfo[New] = CSInfo;
887 }
888 
889 /// \}
890 
891 //===----------------------------------------------------------------------===//
892 //  MachineJumpTableInfo implementation
893 //===----------------------------------------------------------------------===//
894 
895 /// Return the size of each entry in the jump table.
896 unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
897   // The size of a jump table entry is 4 bytes unless the entry is just the
898   // address of a block, in which case it is the pointer size.
899   switch (getEntryKind()) {
900   case MachineJumpTableInfo::EK_BlockAddress:
901     return TD.getPointerSize();
902   case MachineJumpTableInfo::EK_GPRel64BlockAddress:
903     return 8;
904   case MachineJumpTableInfo::EK_GPRel32BlockAddress:
905   case MachineJumpTableInfo::EK_LabelDifference32:
906   case MachineJumpTableInfo::EK_Custom32:
907     return 4;
908   case MachineJumpTableInfo::EK_Inline:
909     return 0;
910   }
911   llvm_unreachable("Unknown jump table encoding!");
912 }
913 
914 /// Return the alignment of each entry in the jump table.
915 unsigned MachineJumpTableInfo::getEntryAlignment(const DataLayout &TD) const {
916   // The alignment of a jump table entry is the alignment of int32 unless the
917   // entry is just the address of a block, in which case it is the pointer
918   // alignment.
919   switch (getEntryKind()) {
920   case MachineJumpTableInfo::EK_BlockAddress:
921     return TD.getPointerABIAlignment(0).value();
922   case MachineJumpTableInfo::EK_GPRel64BlockAddress:
923     return TD.getABIIntegerTypeAlignment(64).value();
924   case MachineJumpTableInfo::EK_GPRel32BlockAddress:
925   case MachineJumpTableInfo::EK_LabelDifference32:
926   case MachineJumpTableInfo::EK_Custom32:
927     return TD.getABIIntegerTypeAlignment(32).value();
928   case MachineJumpTableInfo::EK_Inline:
929     return 1;
930   }
931   llvm_unreachable("Unknown jump table encoding!");
932 }
933 
934 /// Create a new jump table entry in the jump table info.
935 unsigned MachineJumpTableInfo::createJumpTableIndex(
936                                const std::vector<MachineBasicBlock*> &DestBBs) {
937   assert(!DestBBs.empty() && "Cannot create an empty jump table!");
938   JumpTables.push_back(MachineJumpTableEntry(DestBBs));
939   return JumpTables.size()-1;
940 }
941 
942 /// If Old is the target of any jump tables, update the jump tables to branch
943 /// to New instead.
944 bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,
945                                                   MachineBasicBlock *New) {
946   assert(Old != New && "Not making a change?");
947   bool MadeChange = false;
948   for (size_t i = 0, e = JumpTables.size(); i != e; ++i)
949     ReplaceMBBInJumpTable(i, Old, New);
950   return MadeChange;
951 }
952 
953 /// If Old is a target of the jump tables, update the jump table to branch to
954 /// New instead.
955 bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx,
956                                                  MachineBasicBlock *Old,
957                                                  MachineBasicBlock *New) {
958   assert(Old != New && "Not making a change?");
959   bool MadeChange = false;
960   MachineJumpTableEntry &JTE = JumpTables[Idx];
961   for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
962     if (JTE.MBBs[j] == Old) {
963       JTE.MBBs[j] = New;
964       MadeChange = true;
965     }
966   return MadeChange;
967 }
968 
969 void MachineJumpTableInfo::print(raw_ostream &OS) const {
970   if (JumpTables.empty()) return;
971 
972   OS << "Jump Tables:\n";
973 
974   for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
975     OS << printJumpTableEntryReference(i) << ':';
976     for (unsigned j = 0, f = JumpTables[i].MBBs.size(); j != f; ++j)
977       OS << ' ' << printMBBReference(*JumpTables[i].MBBs[j]);
978     if (i != e)
979       OS << '\n';
980   }
981 
982   OS << '\n';
983 }
984 
985 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
986 LLVM_DUMP_METHOD void MachineJumpTableInfo::dump() const { print(dbgs()); }
987 #endif
988 
989 Printable llvm::printJumpTableEntryReference(unsigned Idx) {
990   return Printable([Idx](raw_ostream &OS) { OS << "%jump-table." << Idx; });
991 }
992 
993 //===----------------------------------------------------------------------===//
994 //  MachineConstantPool implementation
995 //===----------------------------------------------------------------------===//
996 
997 void MachineConstantPoolValue::anchor() {}
998 
999 Type *MachineConstantPoolEntry::getType() const {
1000   if (isMachineConstantPoolEntry())
1001     return Val.MachineCPVal->getType();
1002   return Val.ConstVal->getType();
1003 }
1004 
1005 bool MachineConstantPoolEntry::needsRelocation() const {
1006   if (isMachineConstantPoolEntry())
1007     return true;
1008   return Val.ConstVal->needsRelocation();
1009 }
1010 
1011 SectionKind
1012 MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const {
1013   if (needsRelocation())
1014     return SectionKind::getReadOnlyWithRel();
1015   switch (DL->getTypeAllocSize(getType())) {
1016   case 4:
1017     return SectionKind::getMergeableConst4();
1018   case 8:
1019     return SectionKind::getMergeableConst8();
1020   case 16:
1021     return SectionKind::getMergeableConst16();
1022   case 32:
1023     return SectionKind::getMergeableConst32();
1024   default:
1025     return SectionKind::getReadOnly();
1026   }
1027 }
1028 
1029 MachineConstantPool::~MachineConstantPool() {
1030   // A constant may be a member of both Constants and MachineCPVsSharingEntries,
1031   // so keep track of which we've deleted to avoid double deletions.
1032   DenseSet<MachineConstantPoolValue*> Deleted;
1033   for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1034     if (Constants[i].isMachineConstantPoolEntry()) {
1035       Deleted.insert(Constants[i].Val.MachineCPVal);
1036       delete Constants[i].Val.MachineCPVal;
1037     }
1038   for (DenseSet<MachineConstantPoolValue*>::iterator I =
1039        MachineCPVsSharingEntries.begin(), E = MachineCPVsSharingEntries.end();
1040        I != E; ++I) {
1041     if (Deleted.count(*I) == 0)
1042       delete *I;
1043   }
1044 }
1045 
1046 /// Test whether the given two constants can be allocated the same constant pool
1047 /// entry.
1048 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
1049                                       const DataLayout &DL) {
1050   // Handle the trivial case quickly.
1051   if (A == B) return true;
1052 
1053   // If they have the same type but weren't the same constant, quickly
1054   // reject them.
1055   if (A->getType() == B->getType()) return false;
1056 
1057   // We can't handle structs or arrays.
1058   if (isa<StructType>(A->getType()) || isa<ArrayType>(A->getType()) ||
1059       isa<StructType>(B->getType()) || isa<ArrayType>(B->getType()))
1060     return false;
1061 
1062   // For now, only support constants with the same size.
1063   uint64_t StoreSize = DL.getTypeStoreSize(A->getType());
1064   if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128)
1065     return false;
1066 
1067   Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8);
1068 
1069   // Try constant folding a bitcast of both instructions to an integer.  If we
1070   // get two identical ConstantInt's, then we are good to share them.  We use
1071   // the constant folding APIs to do this so that we get the benefit of
1072   // DataLayout.
1073   if (isa<PointerType>(A->getType()))
1074     A = ConstantFoldCastOperand(Instruction::PtrToInt,
1075                                 const_cast<Constant *>(A), IntTy, DL);
1076   else if (A->getType() != IntTy)
1077     A = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(A),
1078                                 IntTy, DL);
1079   if (isa<PointerType>(B->getType()))
1080     B = ConstantFoldCastOperand(Instruction::PtrToInt,
1081                                 const_cast<Constant *>(B), IntTy, DL);
1082   else if (B->getType() != IntTy)
1083     B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B),
1084                                 IntTy, DL);
1085 
1086   return A == B;
1087 }
1088 
1089 /// Create a new entry in the constant pool or return an existing one.
1090 /// User must specify the log2 of the minimum required alignment for the object.
1091 unsigned MachineConstantPool::getConstantPoolIndex(const Constant *C,
1092                                                    unsigned Alignment) {
1093   assert(Alignment && "Alignment must be specified!");
1094   if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1095 
1096   // Check to see if we already have this constant.
1097   //
1098   // FIXME, this could be made much more efficient for large constant pools.
1099   for (unsigned i = 0, e = Constants.size(); i != e; ++i)
1100     if (!Constants[i].isMachineConstantPoolEntry() &&
1101         CanShareConstantPoolEntry(Constants[i].Val.ConstVal, C, DL)) {
1102       if ((unsigned)Constants[i].getAlignment() < Alignment)
1103         Constants[i].Alignment = Alignment;
1104       return i;
1105     }
1106 
1107   Constants.push_back(MachineConstantPoolEntry(C, Alignment));
1108   return Constants.size()-1;
1109 }
1110 
1111 unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
1112                                                    unsigned Alignment) {
1113   assert(Alignment && "Alignment must be specified!");
1114   if (Alignment > PoolAlignment) PoolAlignment = Alignment;
1115 
1116   // Check to see if we already have this constant.
1117   //
1118   // FIXME, this could be made much more efficient for large constant pools.
1119   int Idx = V->getExistingMachineCPValue(this, Alignment);
1120   if (Idx != -1) {
1121     MachineCPVsSharingEntries.insert(V);
1122     return (unsigned)Idx;
1123   }
1124 
1125   Constants.push_back(MachineConstantPoolEntry(V, Alignment));
1126   return Constants.size()-1;
1127 }
1128 
1129 void MachineConstantPool::print(raw_ostream &OS) const {
1130   if (Constants.empty()) return;
1131 
1132   OS << "Constant Pool:\n";
1133   for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
1134     OS << "  cp#" << i << ": ";
1135     if (Constants[i].isMachineConstantPoolEntry())
1136       Constants[i].Val.MachineCPVal->print(OS);
1137     else
1138       Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
1139     OS << ", align=" << Constants[i].getAlignment();
1140     OS << "\n";
1141   }
1142 }
1143 
1144 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1145 LLVM_DUMP_METHOD void MachineConstantPool::dump() const { print(dbgs()); }
1146 #endif
1147