1 //===-- AsmWriter.cpp - Printing LLVM as an assembly file -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This library implements the functionality defined in llvm/Assembly/Writer.h
12 // Note that these routines must be extremely tolerant of various errors in the
13 // LLVM code, because it can be used for debugging transformations.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/Assembly/Writer.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/Assembly/AssemblyAnnotationWriter.h"
23 #include "llvm/Assembly/PrintModulePass.h"
24 #include "llvm/DebugInfo.h"
25 #include "llvm/IR/AsmWriter.h"
26 #include "llvm/IR/CallingConv.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/InlineAsm.h"
30 #include "llvm/IR/IntrinsicInst.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/Module.h"
33 #include "llvm/IR/Operator.h"
34 #include "llvm/IR/TypeFinder.h"
35 #include "llvm/IR/ValueSymbolTable.h"
36 #include "llvm/Support/CFG.h"
37 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/Dwarf.h"
39 #include "llvm/Support/ErrorHandling.h"
40 #include "llvm/Support/FormattedStream.h"
41 #include "llvm/Support/MathExtras.h"
46 // Make virtual table appear in this compilation unit.
47 AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {}
49 //===----------------------------------------------------------------------===//
51 //===----------------------------------------------------------------------===//
53 static const Module *getModuleFromVal(const Value *V) {
54 if (const Argument *MA = dyn_cast<Argument>(V))
55 return MA->getParent() ? MA->getParent()->getParent() : 0;
57 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
58 return BB->getParent() ? BB->getParent()->getParent() : 0;
60 if (const Instruction *I = dyn_cast<Instruction>(V)) {
61 const Function *M = I->getParent() ? I->getParent()->getParent() : 0;
62 return M ? M->getParent() : 0;
65 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
66 return GV->getParent();
70 static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
72 default: Out << "cc" << cc; break;
73 case CallingConv::Fast: Out << "fastcc"; break;
74 case CallingConv::Cold: Out << "coldcc"; break;
75 case CallingConv::X86_StdCall: Out << "x86_stdcallcc"; break;
76 case CallingConv::X86_FastCall: Out << "x86_fastcallcc"; break;
77 case CallingConv::X86_ThisCall: Out << "x86_thiscallcc"; break;
78 case CallingConv::Intel_OCL_BI: Out << "intel_ocl_bicc"; break;
79 case CallingConv::ARM_APCS: Out << "arm_apcscc"; break;
80 case CallingConv::ARM_AAPCS: Out << "arm_aapcscc"; break;
81 case CallingConv::ARM_AAPCS_VFP: Out << "arm_aapcs_vfpcc"; break;
82 case CallingConv::MSP430_INTR: Out << "msp430_intrcc"; break;
83 case CallingConv::PTX_Kernel: Out << "ptx_kernel"; break;
84 case CallingConv::PTX_Device: Out << "ptx_device"; break;
88 // PrintEscapedString - Print each character of the specified string, escaping
89 // it if it is not printable or if it is an escape char.
90 static void PrintEscapedString(StringRef Name, raw_ostream &Out) {
91 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
92 unsigned char C = Name[i];
93 if (isprint(C) && C != '\\' && C != '"')
96 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
107 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
108 /// prefixed with % (if the string only contains simple characters) or is
109 /// surrounded with ""'s (if it has special chars in it). Print it out.
110 static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
111 assert(!Name.empty() && "Cannot get empty name!");
113 case NoPrefix: break;
114 case GlobalPrefix: OS << '@'; break;
115 case LabelPrefix: break;
116 case LocalPrefix: OS << '%'; break;
119 // Scan the name to see if it needs quotes first.
120 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
122 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
123 // By making this unsigned, the value passed in to isalnum will always be
124 // in the range 0-255. This is important when building with MSVC because
125 // its implementation will assert. This situation can arise when dealing
126 // with UTF-8 multibyte characters.
127 unsigned char C = Name[i];
128 if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' &&
136 // If we didn't need any quotes, just write out the name in one blast.
142 // Okay, we need quotes. Output the quotes and escape any scary characters as
145 PrintEscapedString(Name, OS);
149 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
150 /// prefixed with % (if the string only contains simple characters) or is
151 /// surrounded with ""'s (if it has special chars in it). Print it out.
152 static void PrintLLVMName(raw_ostream &OS, const Value *V) {
153 PrintLLVMName(OS, V->getName(),
154 isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
160 void TypePrinting::incorporateTypes(const Module &M) {
161 NamedTypes.run(M, false);
163 // The list of struct types we got back includes all the struct types, split
164 // the unnamed ones out to a numbering and remove the anonymous structs.
165 unsigned NextNumber = 0;
167 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(), I, E;
168 for (I = NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I) {
169 StructType *STy = *I;
171 // Ignore anonymous types.
172 if (STy->isLiteral())
175 if (STy->getName().empty())
176 NumberedTypes[STy] = NextNumber++;
181 NamedTypes.erase(NextToUse, NamedTypes.end());
185 /// CalcTypeName - Write the specified type to the specified raw_ostream, making
186 /// use of type names or up references to shorten the type name where possible.
187 void TypePrinting::print(Type *Ty, raw_ostream &OS) {
188 switch (Ty->getTypeID()) {
189 case Type::VoidTyID: OS << "void"; break;
190 case Type::HalfTyID: OS << "half"; break;
191 case Type::FloatTyID: OS << "float"; break;
192 case Type::DoubleTyID: OS << "double"; break;
193 case Type::X86_FP80TyID: OS << "x86_fp80"; break;
194 case Type::FP128TyID: OS << "fp128"; break;
195 case Type::PPC_FP128TyID: OS << "ppc_fp128"; break;
196 case Type::LabelTyID: OS << "label"; break;
197 case Type::MetadataTyID: OS << "metadata"; break;
198 case Type::X86_MMXTyID: OS << "x86_mmx"; break;
199 case Type::IntegerTyID:
200 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
203 case Type::FunctionTyID: {
204 FunctionType *FTy = cast<FunctionType>(Ty);
205 print(FTy->getReturnType(), OS);
207 for (FunctionType::param_iterator I = FTy->param_begin(),
208 E = FTy->param_end(); I != E; ++I) {
209 if (I != FTy->param_begin())
213 if (FTy->isVarArg()) {
214 if (FTy->getNumParams()) OS << ", ";
220 case Type::StructTyID: {
221 StructType *STy = cast<StructType>(Ty);
223 if (STy->isLiteral())
224 return printStructBody(STy, OS);
226 if (!STy->getName().empty())
227 return PrintLLVMName(OS, STy->getName(), LocalPrefix);
229 DenseMap<StructType*, unsigned>::iterator I = NumberedTypes.find(STy);
230 if (I != NumberedTypes.end())
231 OS << '%' << I->second;
232 else // Not enumerated, print the hex address.
233 OS << "%\"type " << STy << '\"';
236 case Type::PointerTyID: {
237 PointerType *PTy = cast<PointerType>(Ty);
238 print(PTy->getElementType(), OS);
239 if (unsigned AddressSpace = PTy->getAddressSpace())
240 OS << " addrspace(" << AddressSpace << ')';
244 case Type::ArrayTyID: {
245 ArrayType *ATy = cast<ArrayType>(Ty);
246 OS << '[' << ATy->getNumElements() << " x ";
247 print(ATy->getElementType(), OS);
251 case Type::VectorTyID: {
252 VectorType *PTy = cast<VectorType>(Ty);
253 OS << "<" << PTy->getNumElements() << " x ";
254 print(PTy->getElementType(), OS);
259 OS << "<unrecognized-type>";
264 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
265 if (STy->isOpaque()) {
273 if (STy->getNumElements() == 0) {
276 StructType::element_iterator I = STy->element_begin();
279 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
290 //===----------------------------------------------------------------------===//
291 // SlotTracker Class: Enumerate slot numbers for unnamed values
292 //===----------------------------------------------------------------------===//
293 /// This class provides computation of slot numbers for LLVM Assembly writing.
297 /// ValueMap - A mapping of Values to slot numbers.
298 typedef DenseMap<const Value*, unsigned> ValueMap;
301 /// TheModule - The module for which we are holding slot numbers.
302 const Module* TheModule;
304 /// TheFunction - The function for which we are holding slot numbers.
305 const Function* TheFunction;
306 bool FunctionProcessed;
308 /// mMap - The slot map for the module level data.
312 /// fMap - The slot map for the function level data.
316 /// mdnMap - Map for MDNodes.
317 DenseMap<const MDNode*, unsigned> mdnMap;
320 /// asMap - The slot map for attribute sets.
321 DenseMap<AttributeSet, unsigned> asMap;
324 /// Construct from a module
325 explicit SlotTracker(const Module *M);
326 /// Construct from a function, starting out in incorp state.
327 explicit SlotTracker(const Function *F);
329 /// Return the slot number of the specified value in it's type
330 /// plane. If something is not in the SlotTracker, return -1.
331 int getLocalSlot(const Value *V);
332 int getGlobalSlot(const GlobalValue *V);
333 int getMetadataSlot(const MDNode *N);
334 int getAttributeGroupSlot(AttributeSet AS);
336 /// If you'd like to deal with a function instead of just a module, use
337 /// this method to get its data into the SlotTracker.
338 void incorporateFunction(const Function *F) {
340 FunctionProcessed = false;
343 /// After calling incorporateFunction, use this method to remove the
344 /// most recently incorporated function from the SlotTracker. This
345 /// will reset the state of the machine back to just the module contents.
346 void purgeFunction();
348 /// MDNode map iterators.
349 typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator;
350 mdn_iterator mdn_begin() { return mdnMap.begin(); }
351 mdn_iterator mdn_end() { return mdnMap.end(); }
352 unsigned mdn_size() const { return mdnMap.size(); }
353 bool mdn_empty() const { return mdnMap.empty(); }
355 /// AttributeSet map iterators.
356 typedef DenseMap<AttributeSet, unsigned>::iterator as_iterator;
357 as_iterator as_begin() { return asMap.begin(); }
358 as_iterator as_end() { return asMap.end(); }
359 unsigned as_size() const { return asMap.size(); }
360 bool as_empty() const { return asMap.empty(); }
362 /// This function does the actual initialization.
363 inline void initialize();
365 // Implementation Details
367 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
368 void CreateModuleSlot(const GlobalValue *V);
370 /// CreateMetadataSlot - Insert the specified MDNode* into the slot table.
371 void CreateMetadataSlot(const MDNode *N);
373 /// CreateFunctionSlot - Insert the specified Value* into the slot table.
374 void CreateFunctionSlot(const Value *V);
376 /// \brief Insert the specified AttributeSet into the slot table.
377 void CreateAttributeSetSlot(AttributeSet AS);
379 /// Add all of the module level global variables (and their initializers)
380 /// and function declarations, but not the contents of those functions.
381 void processModule();
383 /// Add all of the functions arguments, basic blocks, and instructions.
384 void processFunction();
386 SlotTracker(const SlotTracker &) LLVM_DELETED_FUNCTION;
387 void operator=(const SlotTracker &) LLVM_DELETED_FUNCTION;
390 SlotTracker *createSlotTracker(const Module *M) {
391 return new SlotTracker(M);
394 static SlotTracker *createSlotTracker(const Value *V) {
395 if (const Argument *FA = dyn_cast<Argument>(V))
396 return new SlotTracker(FA->getParent());
398 if (const Instruction *I = dyn_cast<Instruction>(V))
400 return new SlotTracker(I->getParent()->getParent());
402 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
403 return new SlotTracker(BB->getParent());
405 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
406 return new SlotTracker(GV->getParent());
408 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
409 return new SlotTracker(GA->getParent());
411 if (const Function *Func = dyn_cast<Function>(V))
412 return new SlotTracker(Func);
414 if (const MDNode *MD = dyn_cast<MDNode>(V)) {
415 if (!MD->isFunctionLocal())
416 return new SlotTracker(MD->getFunction());
418 return new SlotTracker((Function *)0);
425 #define ST_DEBUG(X) dbgs() << X
430 // Module level constructor. Causes the contents of the Module (sans functions)
431 // to be added to the slot table.
432 SlotTracker::SlotTracker(const Module *M)
433 : TheModule(M), TheFunction(0), FunctionProcessed(false),
434 mNext(0), fNext(0), mdnNext(0), asNext(0) {
437 // Function level constructor. Causes the contents of the Module and the one
438 // function provided to be added to the slot table.
439 SlotTracker::SlotTracker(const Function *F)
440 : TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false),
441 mNext(0), fNext(0), mdnNext(0), asNext(0) {
444 inline void SlotTracker::initialize() {
447 TheModule = 0; ///< Prevent re-processing next time we're called.
450 if (TheFunction && !FunctionProcessed)
454 // Iterate through all the global variables, functions, and global
455 // variable initializers and create slots for them.
456 void SlotTracker::processModule() {
457 ST_DEBUG("begin processModule!\n");
459 // Add all of the unnamed global variables to the value table.
460 for (Module::const_global_iterator I = TheModule->global_begin(),
461 E = TheModule->global_end(); I != E; ++I) {
466 // Add metadata used by named metadata.
467 for (Module::const_named_metadata_iterator
468 I = TheModule->named_metadata_begin(),
469 E = TheModule->named_metadata_end(); I != E; ++I) {
470 const NamedMDNode *NMD = I;
471 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
472 CreateMetadataSlot(NMD->getOperand(i));
475 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
478 // Add all the unnamed functions to the table.
481 // Add all the function attributes to the table.
482 // FIXME: Add attributes of other objects?
483 AttributeSet FnAttrs = I->getAttributes().getFnAttributes();
484 if (FnAttrs.hasAttributes(AttributeSet::FunctionIndex))
485 CreateAttributeSetSlot(FnAttrs);
488 ST_DEBUG("end processModule!\n");
491 // Process the arguments, basic blocks, and instructions of a function.
492 void SlotTracker::processFunction() {
493 ST_DEBUG("begin processFunction!\n");
496 // Add all the function arguments with no names.
497 for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
498 AE = TheFunction->arg_end(); AI != AE; ++AI)
500 CreateFunctionSlot(AI);
502 ST_DEBUG("Inserting Instructions:\n");
504 SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
506 // Add all of the basic blocks and instructions with no names.
507 for (Function::const_iterator BB = TheFunction->begin(),
508 E = TheFunction->end(); BB != E; ++BB) {
510 CreateFunctionSlot(BB);
512 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
514 if (!I->getType()->isVoidTy() && !I->hasName())
515 CreateFunctionSlot(I);
517 // Intrinsics can directly use metadata. We allow direct calls to any
518 // llvm.foo function here, because the target may not be linked into the
520 if (const CallInst *CI = dyn_cast<CallInst>(I)) {
521 if (Function *F = CI->getCalledFunction())
522 if (F->getName().startswith("llvm."))
523 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
524 if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
525 CreateMetadataSlot(N);
527 // Add all the call attributes to the table.
528 AttributeSet Attrs = CI->getAttributes().getFnAttributes();
529 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
530 CreateAttributeSetSlot(Attrs);
531 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) {
532 // Add all the call attributes to the table.
533 AttributeSet Attrs = II->getAttributes().getFnAttributes();
534 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
535 CreateAttributeSetSlot(Attrs);
538 // Process metadata attached with this instruction.
539 I->getAllMetadata(MDForInst);
540 for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
541 CreateMetadataSlot(MDForInst[i].second);
546 FunctionProcessed = true;
548 ST_DEBUG("end processFunction!\n");
551 /// Clean up after incorporating a function. This is the only way to get out of
552 /// the function incorporation state that affects get*Slot/Create*Slot. Function
553 /// incorporation state is indicated by TheFunction != 0.
554 void SlotTracker::purgeFunction() {
555 ST_DEBUG("begin purgeFunction!\n");
556 fMap.clear(); // Simply discard the function level map
558 FunctionProcessed = false;
559 ST_DEBUG("end purgeFunction!\n");
562 /// getGlobalSlot - Get the slot number of a global value.
563 int SlotTracker::getGlobalSlot(const GlobalValue *V) {
564 // Check for uninitialized state and do lazy initialization.
567 // Find the value in the module map
568 ValueMap::iterator MI = mMap.find(V);
569 return MI == mMap.end() ? -1 : (int)MI->second;
572 /// getMetadataSlot - Get the slot number of a MDNode.
573 int SlotTracker::getMetadataSlot(const MDNode *N) {
574 // Check for uninitialized state and do lazy initialization.
577 // Find the MDNode in the module map
578 mdn_iterator MI = mdnMap.find(N);
579 return MI == mdnMap.end() ? -1 : (int)MI->second;
583 /// getLocalSlot - Get the slot number for a value that is local to a function.
584 int SlotTracker::getLocalSlot(const Value *V) {
585 assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!");
587 // Check for uninitialized state and do lazy initialization.
590 ValueMap::iterator FI = fMap.find(V);
591 return FI == fMap.end() ? -1 : (int)FI->second;
594 int SlotTracker::getAttributeGroupSlot(AttributeSet AS) {
595 // Check for uninitialized state and do lazy initialization.
598 // Find the AttributeSet in the module map.
599 as_iterator AI = asMap.find(AS);
600 return AI == asMap.end() ? -1 : (int)AI->second;
603 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
604 void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
605 assert(V && "Can't insert a null Value into SlotTracker!");
606 assert(!V->getType()->isVoidTy() && "Doesn't need a slot!");
607 assert(!V->hasName() && "Doesn't need a slot!");
609 unsigned DestSlot = mNext++;
612 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
614 // G = Global, F = Function, A = Alias, o = other
615 ST_DEBUG((isa<GlobalVariable>(V) ? 'G' :
616 (isa<Function>(V) ? 'F' :
617 (isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n");
620 /// CreateSlot - Create a new slot for the specified value if it has no name.
621 void SlotTracker::CreateFunctionSlot(const Value *V) {
622 assert(!V->getType()->isVoidTy() && !V->hasName() && "Doesn't need a slot!");
624 unsigned DestSlot = fNext++;
627 // G = Global, F = Function, o = other
628 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
629 DestSlot << " [o]\n");
632 /// CreateModuleSlot - Insert the specified MDNode* into the slot table.
633 void SlotTracker::CreateMetadataSlot(const MDNode *N) {
634 assert(N && "Can't insert a null Value into SlotTracker!");
636 // Don't insert if N is a function-local metadata, these are always printed
638 if (!N->isFunctionLocal()) {
639 mdn_iterator I = mdnMap.find(N);
640 if (I != mdnMap.end())
643 unsigned DestSlot = mdnNext++;
644 mdnMap[N] = DestSlot;
647 // Recursively add any MDNodes referenced by operands.
648 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
649 if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i)))
650 CreateMetadataSlot(Op);
653 void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) {
654 assert(AS.hasAttributes(AttributeSet::FunctionIndex) &&
655 "Doesn't need a slot!");
657 as_iterator I = asMap.find(AS);
658 if (I != asMap.end())
661 unsigned DestSlot = asNext++;
662 asMap[AS] = DestSlot;
665 //===----------------------------------------------------------------------===//
666 // AsmWriter Implementation
667 //===----------------------------------------------------------------------===//
669 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
670 TypePrinting *TypePrinter,
671 SlotTracker *Machine,
672 const Module *Context);
676 static const char *getPredicateText(unsigned predicate) {
677 const char * pred = "unknown";
679 case FCmpInst::FCMP_FALSE: pred = "false"; break;
680 case FCmpInst::FCMP_OEQ: pred = "oeq"; break;
681 case FCmpInst::FCMP_OGT: pred = "ogt"; break;
682 case FCmpInst::FCMP_OGE: pred = "oge"; break;
683 case FCmpInst::FCMP_OLT: pred = "olt"; break;
684 case FCmpInst::FCMP_OLE: pred = "ole"; break;
685 case FCmpInst::FCMP_ONE: pred = "one"; break;
686 case FCmpInst::FCMP_ORD: pred = "ord"; break;
687 case FCmpInst::FCMP_UNO: pred = "uno"; break;
688 case FCmpInst::FCMP_UEQ: pred = "ueq"; break;
689 case FCmpInst::FCMP_UGT: pred = "ugt"; break;
690 case FCmpInst::FCMP_UGE: pred = "uge"; break;
691 case FCmpInst::FCMP_ULT: pred = "ult"; break;
692 case FCmpInst::FCMP_ULE: pred = "ule"; break;
693 case FCmpInst::FCMP_UNE: pred = "une"; break;
694 case FCmpInst::FCMP_TRUE: pred = "true"; break;
695 case ICmpInst::ICMP_EQ: pred = "eq"; break;
696 case ICmpInst::ICMP_NE: pred = "ne"; break;
697 case ICmpInst::ICMP_SGT: pred = "sgt"; break;
698 case ICmpInst::ICMP_SGE: pred = "sge"; break;
699 case ICmpInst::ICMP_SLT: pred = "slt"; break;
700 case ICmpInst::ICMP_SLE: pred = "sle"; break;
701 case ICmpInst::ICMP_UGT: pred = "ugt"; break;
702 case ICmpInst::ICMP_UGE: pred = "uge"; break;
703 case ICmpInst::ICMP_ULT: pred = "ult"; break;
704 case ICmpInst::ICMP_ULE: pred = "ule"; break;
709 static void writeAtomicRMWOperation(raw_ostream &Out,
710 AtomicRMWInst::BinOp Op) {
712 default: Out << " <unknown operation " << Op << ">"; break;
713 case AtomicRMWInst::Xchg: Out << " xchg"; break;
714 case AtomicRMWInst::Add: Out << " add"; break;
715 case AtomicRMWInst::Sub: Out << " sub"; break;
716 case AtomicRMWInst::And: Out << " and"; break;
717 case AtomicRMWInst::Nand: Out << " nand"; break;
718 case AtomicRMWInst::Or: Out << " or"; break;
719 case AtomicRMWInst::Xor: Out << " xor"; break;
720 case AtomicRMWInst::Max: Out << " max"; break;
721 case AtomicRMWInst::Min: Out << " min"; break;
722 case AtomicRMWInst::UMax: Out << " umax"; break;
723 case AtomicRMWInst::UMin: Out << " umin"; break;
727 static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
728 if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
729 // Unsafe algebra implies all the others, no need to write them all out
730 if (FPO->hasUnsafeAlgebra())
733 if (FPO->hasNoNaNs())
735 if (FPO->hasNoInfs())
737 if (FPO->hasNoSignedZeros())
739 if (FPO->hasAllowReciprocal())
744 if (const OverflowingBinaryOperator *OBO =
745 dyn_cast<OverflowingBinaryOperator>(U)) {
746 if (OBO->hasNoUnsignedWrap())
748 if (OBO->hasNoSignedWrap())
750 } else if (const PossiblyExactOperator *Div =
751 dyn_cast<PossiblyExactOperator>(U)) {
754 } else if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
755 if (GEP->isInBounds())
760 static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
761 TypePrinting &TypePrinter,
762 SlotTracker *Machine,
763 const Module *Context) {
764 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
765 if (CI->getType()->isIntegerTy(1)) {
766 Out << (CI->getZExtValue() ? "true" : "false");
769 Out << CI->getValue();
773 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
774 if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle ||
775 &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble) {
776 // We would like to output the FP constant value in exponential notation,
777 // but we cannot do this if doing so will lose precision. Check here to
778 // make sure that we only output it in exponential format if we can parse
779 // the value back and get the same value.
782 bool isHalf = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEhalf;
783 bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
784 bool isInf = CFP->getValueAPF().isInfinity();
785 bool isNaN = CFP->getValueAPF().isNaN();
786 if (!isHalf && !isInf && !isNaN) {
787 double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
788 CFP->getValueAPF().convertToFloat();
789 SmallString<128> StrVal;
790 raw_svector_ostream(StrVal) << Val;
792 // Check to make sure that the stringized number is not some string like
793 // "Inf" or NaN, that atof will accept, but the lexer will not. Check
794 // that the string matches the "[-+]?[0-9]" regex.
796 if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
797 ((StrVal[0] == '-' || StrVal[0] == '+') &&
798 (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
799 // Reparse stringized version!
800 if (APFloat(APFloat::IEEEdouble, StrVal).convertToDouble() == Val) {
806 // Otherwise we could not reparse it to exactly the same value, so we must
807 // output the string in hexadecimal format! Note that loading and storing
808 // floating point types changes the bits of NaNs on some hosts, notably
809 // x86, so we must not use these types.
810 assert(sizeof(double) == sizeof(uint64_t) &&
811 "assuming that double is 64 bits!");
813 APFloat apf = CFP->getValueAPF();
814 // Halves and floats are represented in ASCII IR as double, convert.
816 apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
819 utohex_buffer(uint64_t(apf.bitcastToAPInt().getZExtValue()),
824 // Either half, or some form of long double.
825 // These appear as a magic letter identifying the type, then a
826 // fixed number of hex digits.
828 // Bit position, in the current word, of the next nibble to print.
831 if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) {
833 // api needed to prevent premature destruction
834 APInt api = CFP->getValueAPF().bitcastToAPInt();
835 const uint64_t* p = api.getRawData();
836 uint64_t word = p[1];
838 int width = api.getBitWidth();
839 for (int j=0; j<width; j+=4, shiftcount-=4) {
840 unsigned int nibble = (word>>shiftcount) & 15;
842 Out << (unsigned char)(nibble + '0');
844 Out << (unsigned char)(nibble - 10 + 'A');
845 if (shiftcount == 0 && j+4 < width) {
849 shiftcount = width-j-4;
853 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad) {
856 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble) {
859 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEhalf) {
863 llvm_unreachable("Unsupported floating point type");
864 // api needed to prevent premature destruction
865 APInt api = CFP->getValueAPF().bitcastToAPInt();
866 const uint64_t* p = api.getRawData();
868 int width = api.getBitWidth();
869 for (int j=0; j<width; j+=4, shiftcount-=4) {
870 unsigned int nibble = (word>>shiftcount) & 15;
872 Out << (unsigned char)(nibble + '0');
874 Out << (unsigned char)(nibble - 10 + 'A');
875 if (shiftcount == 0 && j+4 < width) {
879 shiftcount = width-j-4;
885 if (isa<ConstantAggregateZero>(CV)) {
886 Out << "zeroinitializer";
890 if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
891 Out << "blockaddress(";
892 WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine,
895 WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine,
901 if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
902 Type *ETy = CA->getType()->getElementType();
904 TypePrinter.print(ETy, Out);
906 WriteAsOperandInternal(Out, CA->getOperand(0),
907 &TypePrinter, Machine,
909 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
911 TypePrinter.print(ETy, Out);
913 WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine,
920 if (const ConstantDataArray *CA = dyn_cast<ConstantDataArray>(CV)) {
921 // As a special case, print the array as a string if it is an array of
922 // i8 with ConstantInt values.
923 if (CA->isString()) {
925 PrintEscapedString(CA->getAsString(), Out);
930 Type *ETy = CA->getType()->getElementType();
932 TypePrinter.print(ETy, Out);
934 WriteAsOperandInternal(Out, CA->getElementAsConstant(0),
935 &TypePrinter, Machine,
937 for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
939 TypePrinter.print(ETy, Out);
941 WriteAsOperandInternal(Out, CA->getElementAsConstant(i), &TypePrinter,
949 if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
950 if (CS->getType()->isPacked())
953 unsigned N = CS->getNumOperands();
956 TypePrinter.print(CS->getOperand(0)->getType(), Out);
959 WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine,
962 for (unsigned i = 1; i < N; i++) {
964 TypePrinter.print(CS->getOperand(i)->getType(), Out);
967 WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine,
974 if (CS->getType()->isPacked())
979 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
980 Type *ETy = CV->getType()->getVectorElementType();
982 TypePrinter.print(ETy, Out);
984 WriteAsOperandInternal(Out, CV->getAggregateElement(0U), &TypePrinter,
986 for (unsigned i = 1, e = CV->getType()->getVectorNumElements(); i != e;++i){
988 TypePrinter.print(ETy, Out);
990 WriteAsOperandInternal(Out, CV->getAggregateElement(i), &TypePrinter,
997 if (isa<ConstantPointerNull>(CV)) {
1002 if (isa<UndefValue>(CV)) {
1007 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1008 Out << CE->getOpcodeName();
1009 WriteOptimizationInfo(Out, CE);
1010 if (CE->isCompare())
1011 Out << ' ' << getPredicateText(CE->getPredicate());
1014 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1015 TypePrinter.print((*OI)->getType(), Out);
1017 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
1018 if (OI+1 != CE->op_end())
1022 if (CE->hasIndices()) {
1023 ArrayRef<unsigned> Indices = CE->getIndices();
1024 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1025 Out << ", " << Indices[i];
1030 TypePrinter.print(CE->getType(), Out);
1037 Out << "<placeholder or erroneous Constant>";
1040 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
1041 TypePrinting *TypePrinter,
1042 SlotTracker *Machine,
1043 const Module *Context) {
1045 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
1046 const Value *V = Node->getOperand(mi);
1050 TypePrinter->print(V->getType(), Out);
1052 WriteAsOperandInternal(Out, Node->getOperand(mi),
1053 TypePrinter, Machine, Context);
1063 /// WriteAsOperand - Write the name of the specified value out to the specified
1064 /// ostream. This can be useful when you just want to print int %reg126, not
1065 /// the whole instruction that generated it.
1067 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1068 TypePrinting *TypePrinter,
1069 SlotTracker *Machine,
1070 const Module *Context) {
1072 PrintLLVMName(Out, V);
1076 const Constant *CV = dyn_cast<Constant>(V);
1077 if (CV && !isa<GlobalValue>(CV)) {
1078 assert(TypePrinter && "Constants require TypePrinting!");
1079 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
1083 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1085 if (IA->hasSideEffects())
1086 Out << "sideeffect ";
1087 if (IA->isAlignStack())
1088 Out << "alignstack ";
1089 // We don't emit the AD_ATT dialect as it's the assumed default.
1090 if (IA->getDialect() == InlineAsm::AD_Intel)
1091 Out << "inteldialect ";
1093 PrintEscapedString(IA->getAsmString(), Out);
1095 PrintEscapedString(IA->getConstraintString(), Out);
1100 if (const MDNode *N = dyn_cast<MDNode>(V)) {
1101 if (N->isFunctionLocal()) {
1102 // Print metadata inline, not via slot reference number.
1103 WriteMDNodeBodyInternal(Out, N, TypePrinter, Machine, Context);
1108 if (N->isFunctionLocal())
1109 Machine = new SlotTracker(N->getFunction());
1111 Machine = new SlotTracker(Context);
1113 int Slot = Machine->getMetadataSlot(N);
1121 if (const MDString *MDS = dyn_cast<MDString>(V)) {
1123 PrintEscapedString(MDS->getString(), Out);
1128 if (V->getValueID() == Value::PseudoSourceValueVal ||
1129 V->getValueID() == Value::FixedStackPseudoSourceValueVal) {
1136 // If we have a SlotTracker, use it.
1138 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1139 Slot = Machine->getGlobalSlot(GV);
1142 Slot = Machine->getLocalSlot(V);
1144 // If the local value didn't succeed, then we may be referring to a value
1145 // from a different function. Translate it, as this can happen when using
1146 // address of blocks.
1148 if ((Machine = createSlotTracker(V))) {
1149 Slot = Machine->getLocalSlot(V);
1153 } else if ((Machine = createSlotTracker(V))) {
1154 // Otherwise, create one to get the # and then destroy it.
1155 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1156 Slot = Machine->getGlobalSlot(GV);
1159 Slot = Machine->getLocalSlot(V);
1168 Out << Prefix << Slot;
1173 void WriteAsOperand(raw_ostream &Out, const Value *V,
1174 bool PrintType, const Module *Context) {
1176 // Fast path: Don't construct and populate a TypePrinting object if we
1177 // won't be needing any types printed.
1179 ((!isa<Constant>(V) && !isa<MDNode>(V)) ||
1180 V->hasName() || isa<GlobalValue>(V))) {
1181 WriteAsOperandInternal(Out, V, 0, 0, Context);
1185 if (Context == 0) Context = getModuleFromVal(V);
1187 TypePrinting TypePrinter;
1189 TypePrinter.incorporateTypes(*Context);
1191 TypePrinter.print(V->getType(), Out);
1195 WriteAsOperandInternal(Out, V, &TypePrinter, 0, Context);
1198 void AssemblyWriter::init() {
1200 TypePrinter.incorporateTypes(*TheModule);
1204 AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
1206 AssemblyAnnotationWriter *AAW)
1207 : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW) {
1211 AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, const Module *M,
1212 AssemblyAnnotationWriter *AAW)
1213 : Out(o), TheModule(M), ModuleSlotTracker(createSlotTracker(M)),
1214 Machine(*ModuleSlotTracker), AnnotationWriter(AAW) {
1218 AssemblyWriter::~AssemblyWriter() { }
1220 void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
1222 Out << "<null operand!>";
1226 TypePrinter.print(Operand->getType(), Out);
1229 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
1232 void AssemblyWriter::writeAtomic(AtomicOrdering Ordering,
1233 SynchronizationScope SynchScope) {
1234 if (Ordering == NotAtomic)
1237 switch (SynchScope) {
1238 case SingleThread: Out << " singlethread"; break;
1239 case CrossThread: break;
1243 default: Out << " <bad ordering " << int(Ordering) << ">"; break;
1244 case Unordered: Out << " unordered"; break;
1245 case Monotonic: Out << " monotonic"; break;
1246 case Acquire: Out << " acquire"; break;
1247 case Release: Out << " release"; break;
1248 case AcquireRelease: Out << " acq_rel"; break;
1249 case SequentiallyConsistent: Out << " seq_cst"; break;
1253 void AssemblyWriter::writeParamOperand(const Value *Operand,
1254 AttributeSet Attrs, unsigned Idx) {
1256 Out << "<null operand!>";
1261 TypePrinter.print(Operand->getType(), Out);
1262 // Print parameter attributes list
1263 if (Attrs.hasAttributes(Idx))
1264 Out << ' ' << Attrs.getAsString(Idx);
1266 // Print the operand
1267 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
1270 void AssemblyWriter::printModule(const Module *M) {
1271 Machine.initialize();
1273 if (!M->getModuleIdentifier().empty() &&
1274 // Don't print the ID if it will start a new line (which would
1275 // require a comment char before it).
1276 M->getModuleIdentifier().find('\n') == std::string::npos)
1277 Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
1279 if (!M->getDataLayout().empty())
1280 Out << "target datalayout = \"" << M->getDataLayout() << "\"\n";
1281 if (!M->getTargetTriple().empty())
1282 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
1284 if (!M->getModuleInlineAsm().empty()) {
1285 // Split the string into lines, to make it easier to read the .ll file.
1286 std::string Asm = M->getModuleInlineAsm();
1288 size_t NewLine = Asm.find_first_of('\n', CurPos);
1290 while (NewLine != std::string::npos) {
1291 // We found a newline, print the portion of the asm string from the
1292 // last newline up to this newline.
1293 Out << "module asm \"";
1294 PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine),
1298 NewLine = Asm.find_first_of('\n', CurPos);
1300 std::string rest(Asm.begin()+CurPos, Asm.end());
1301 if (!rest.empty()) {
1302 Out << "module asm \"";
1303 PrintEscapedString(rest, Out);
1308 printTypeIdentities();
1310 // Output all globals.
1311 if (!M->global_empty()) Out << '\n';
1312 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
1314 printGlobal(I); Out << '\n';
1317 // Output all aliases.
1318 if (!M->alias_empty()) Out << "\n";
1319 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
1323 // Output all of the functions.
1324 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
1327 // Output all attribute groups.
1328 if (!Machine.as_empty()) {
1330 writeAllAttributeGroups();
1333 // Output named metadata.
1334 if (!M->named_metadata_empty()) Out << '\n';
1336 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
1337 E = M->named_metadata_end(); I != E; ++I)
1338 printNamedMDNode(I);
1341 if (!Machine.mdn_empty()) {
1347 void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
1349 StringRef Name = NMD->getName();
1351 Out << "<empty name> ";
1353 if (isalpha(static_cast<unsigned char>(Name[0])) ||
1354 Name[0] == '-' || Name[0] == '$' ||
1355 Name[0] == '.' || Name[0] == '_')
1358 Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F);
1359 for (unsigned i = 1, e = Name.size(); i != e; ++i) {
1360 unsigned char C = Name[i];
1361 if (isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' ||
1362 C == '.' || C == '_')
1365 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
1369 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1371 int Slot = Machine.getMetadataSlot(NMD->getOperand(i));
1381 static void PrintLinkage(GlobalValue::LinkageTypes LT,
1382 formatted_raw_ostream &Out) {
1384 case GlobalValue::ExternalLinkage: break;
1385 case GlobalValue::PrivateLinkage: Out << "private "; break;
1386 case GlobalValue::LinkerPrivateLinkage: Out << "linker_private "; break;
1387 case GlobalValue::LinkerPrivateWeakLinkage:
1388 Out << "linker_private_weak ";
1390 case GlobalValue::InternalLinkage: Out << "internal "; break;
1391 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
1392 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
1393 case GlobalValue::LinkOnceODRAutoHideLinkage:
1394 Out << "linkonce_odr_auto_hide ";
1396 case GlobalValue::WeakAnyLinkage: Out << "weak "; break;
1397 case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break;
1398 case GlobalValue::CommonLinkage: Out << "common "; break;
1399 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1400 case GlobalValue::DLLImportLinkage: Out << "dllimport "; break;
1401 case GlobalValue::DLLExportLinkage: Out << "dllexport "; break;
1402 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
1403 case GlobalValue::AvailableExternallyLinkage:
1404 Out << "available_externally ";
1410 static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
1411 formatted_raw_ostream &Out) {
1413 case GlobalValue::DefaultVisibility: break;
1414 case GlobalValue::HiddenVisibility: Out << "hidden "; break;
1415 case GlobalValue::ProtectedVisibility: Out << "protected "; break;
1419 static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM,
1420 formatted_raw_ostream &Out) {
1422 case GlobalVariable::NotThreadLocal:
1424 case GlobalVariable::GeneralDynamicTLSModel:
1425 Out << "thread_local ";
1427 case GlobalVariable::LocalDynamicTLSModel:
1428 Out << "thread_local(localdynamic) ";
1430 case GlobalVariable::InitialExecTLSModel:
1431 Out << "thread_local(initialexec) ";
1433 case GlobalVariable::LocalExecTLSModel:
1434 Out << "thread_local(localexec) ";
1439 void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
1440 if (GV->isMaterializable())
1441 Out << "; Materializable\n";
1443 WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine, GV->getParent());
1446 if (!GV->hasInitializer() && GV->hasExternalLinkage())
1449 PrintLinkage(GV->getLinkage(), Out);
1450 PrintVisibility(GV->getVisibility(), Out);
1451 PrintThreadLocalModel(GV->getThreadLocalMode(), Out);
1453 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
1454 Out << "addrspace(" << AddressSpace << ") ";
1455 if (GV->hasUnnamedAddr()) Out << "unnamed_addr ";
1456 if (GV->isExternallyInitialized()) Out << "externally_initialized ";
1457 Out << (GV->isConstant() ? "constant " : "global ");
1458 TypePrinter.print(GV->getType()->getElementType(), Out);
1460 if (GV->hasInitializer()) {
1462 writeOperand(GV->getInitializer(), false);
1465 if (GV->hasSection()) {
1466 Out << ", section \"";
1467 PrintEscapedString(GV->getSection(), Out);
1470 if (GV->getAlignment())
1471 Out << ", align " << GV->getAlignment();
1473 printInfoComment(*GV);
1476 void AssemblyWriter::printAlias(const GlobalAlias *GA) {
1477 if (GA->isMaterializable())
1478 Out << "; Materializable\n";
1480 // Don't crash when dumping partially built GA
1482 Out << "<<nameless>> = ";
1484 PrintLLVMName(Out, GA);
1487 PrintVisibility(GA->getVisibility(), Out);
1491 PrintLinkage(GA->getLinkage(), Out);
1493 const Constant *Aliasee = GA->getAliasee();
1496 TypePrinter.print(GA->getType(), Out);
1497 Out << " <<NULL ALIASEE>>";
1499 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
1502 printInfoComment(*GA);
1506 void AssemblyWriter::printTypeIdentities() {
1507 if (TypePrinter.NumberedTypes.empty() &&
1508 TypePrinter.NamedTypes.empty())
1513 // We know all the numbers that each type is used and we know that it is a
1514 // dense assignment. Convert the map to an index table.
1515 std::vector<StructType*> NumberedTypes(TypePrinter.NumberedTypes.size());
1516 for (DenseMap<StructType*, unsigned>::iterator I =
1517 TypePrinter.NumberedTypes.begin(), E = TypePrinter.NumberedTypes.end();
1519 assert(I->second < NumberedTypes.size() && "Didn't get a dense numbering?");
1520 NumberedTypes[I->second] = I->first;
1523 // Emit all numbered types.
1524 for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
1525 Out << '%' << i << " = type ";
1527 // Make sure we print out at least one level of the type structure, so
1528 // that we do not get %2 = type %2
1529 TypePrinter.printStructBody(NumberedTypes[i], Out);
1533 for (unsigned i = 0, e = TypePrinter.NamedTypes.size(); i != e; ++i) {
1534 PrintLLVMName(Out, TypePrinter.NamedTypes[i]->getName(), LocalPrefix);
1537 // Make sure we print out at least one level of the type structure, so
1538 // that we do not get %FILE = type %FILE
1539 TypePrinter.printStructBody(TypePrinter.NamedTypes[i], Out);
1544 /// printFunction - Print all aspects of a function.
1546 void AssemblyWriter::printFunction(const Function *F) {
1547 // Print out the return type and name.
1550 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
1552 if (F->isMaterializable())
1553 Out << "; Materializable\n";
1555 const AttributeSet &Attrs = F->getAttributes();
1556 if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
1557 AttributeSet AS = Attrs.getFnAttributes();
1558 std::string AttrStr;
1561 for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx)
1562 if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex)
1565 for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx);
1567 Attribute Attr = *I;
1568 if (!Attr.isStringAttribute()) {
1569 if (!AttrStr.empty()) AttrStr += ' ';
1570 AttrStr += Attr.getAsString();
1574 if (!AttrStr.empty())
1575 Out << "; Function Attrs: " << AttrStr << '\n';
1578 if (F->isDeclaration())
1583 PrintLinkage(F->getLinkage(), Out);
1584 PrintVisibility(F->getVisibility(), Out);
1586 // Print the calling convention.
1587 if (F->getCallingConv() != CallingConv::C) {
1588 PrintCallingConv(F->getCallingConv(), Out);
1592 FunctionType *FT = F->getFunctionType();
1593 if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
1594 Out << Attrs.getAsString(AttributeSet::ReturnIndex) << ' ';
1595 TypePrinter.print(F->getReturnType(), Out);
1597 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
1599 Machine.incorporateFunction(F);
1601 // Loop over the arguments, printing them...
1604 if (!F->isDeclaration()) {
1605 // If this isn't a declaration, print the argument names as well.
1606 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
1608 // Insert commas as we go... the first arg doesn't get a comma
1609 if (I != F->arg_begin()) Out << ", ";
1610 printArgument(I, Attrs, Idx);
1614 // Otherwise, print the types from the function type.
1615 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
1616 // Insert commas as we go... the first arg doesn't get a comma
1620 TypePrinter.print(FT->getParamType(i), Out);
1622 if (Attrs.hasAttributes(i+1))
1623 Out << ' ' << Attrs.getAsString(i+1);
1627 // Finish printing arguments...
1628 if (FT->isVarArg()) {
1629 if (FT->getNumParams()) Out << ", ";
1630 Out << "..."; // Output varargs portion of signature!
1633 if (F->hasUnnamedAddr())
1634 Out << " unnamed_addr";
1635 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
1636 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
1637 if (F->hasSection()) {
1638 Out << " section \"";
1639 PrintEscapedString(F->getSection(), Out);
1642 if (F->getAlignment())
1643 Out << " align " << F->getAlignment();
1645 Out << " gc \"" << F->getGC() << '"';
1646 if (F->isDeclaration()) {
1650 // Output all of the function's basic blocks.
1651 for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
1657 Machine.purgeFunction();
1660 /// printArgument - This member is called for every argument that is passed into
1661 /// the function. Simply print it out
1663 void AssemblyWriter::printArgument(const Argument *Arg,
1664 AttributeSet Attrs, unsigned Idx) {
1666 TypePrinter.print(Arg->getType(), Out);
1668 // Output parameter attributes list
1669 if (Attrs.hasAttributes(Idx))
1670 Out << ' ' << Attrs.getAsString(Idx);
1672 // Output name, if available...
1673 if (Arg->hasName()) {
1675 PrintLLVMName(Out, Arg);
1679 /// printBasicBlock - This member is called for each basic block in a method.
1681 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
1682 if (BB->hasName()) { // Print out the label if it exists...
1684 PrintLLVMName(Out, BB->getName(), LabelPrefix);
1686 } else if (!BB->use_empty()) { // Don't print block # of no uses...
1687 Out << "\n; <label>:";
1688 int Slot = Machine.getLocalSlot(BB);
1695 if (BB->getParent() == 0) {
1696 Out.PadToColumn(50);
1697 Out << "; Error: Block without parent!";
1698 } else if (BB != &BB->getParent()->getEntryBlock()) { // Not the entry block?
1699 // Output predecessors for the block.
1700 Out.PadToColumn(50);
1702 const_pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
1705 Out << " No predecessors!";
1708 writeOperand(*PI, false);
1709 for (++PI; PI != PE; ++PI) {
1711 writeOperand(*PI, false);
1718 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
1720 // Output all of the instructions in the basic block...
1721 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
1722 printInstructionLine(*I);
1725 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
1728 /// printInstructionLine - Print an instruction and a newline character.
1729 void AssemblyWriter::printInstructionLine(const Instruction &I) {
1730 printInstruction(I);
1734 /// printInfoComment - Print a little comment after the instruction indicating
1735 /// which slot it occupies.
1737 void AssemblyWriter::printInfoComment(const Value &V) {
1738 if (AnnotationWriter)
1739 AnnotationWriter->printInfoComment(V, Out);
1742 // This member is called for each Instruction in a function..
1743 void AssemblyWriter::printInstruction(const Instruction &I) {
1744 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
1746 // Print out indentation for an instruction.
1749 // Print out name if it exists...
1751 PrintLLVMName(Out, &I);
1753 } else if (!I.getType()->isVoidTy()) {
1754 // Print out the def slot taken.
1755 int SlotNum = Machine.getLocalSlot(&I);
1757 Out << "<badref> = ";
1759 Out << '%' << SlotNum << " = ";
1762 if (isa<CallInst>(I) && cast<CallInst>(I).isTailCall())
1765 // Print out the opcode...
1766 Out << I.getOpcodeName();
1768 // If this is an atomic load or store, print out the atomic marker.
1769 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isAtomic()) ||
1770 (isa<StoreInst>(I) && cast<StoreInst>(I).isAtomic()))
1773 // If this is a volatile operation, print out the volatile marker.
1774 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) ||
1775 (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile()) ||
1776 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isVolatile()) ||
1777 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).isVolatile()))
1780 // Print out optimization information.
1781 WriteOptimizationInfo(Out, &I);
1783 // Print out the compare instruction predicates
1784 if (const CmpInst *CI = dyn_cast<CmpInst>(&I))
1785 Out << ' ' << getPredicateText(CI->getPredicate());
1787 // Print out the atomicrmw operation
1788 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
1789 writeAtomicRMWOperation(Out, RMWI->getOperation());
1791 // Print out the type of the operands...
1792 const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0;
1794 // Special case conditional branches to swizzle the condition out to the front
1795 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
1796 const BranchInst &BI(cast<BranchInst>(I));
1798 writeOperand(BI.getCondition(), true);
1800 writeOperand(BI.getSuccessor(0), true);
1802 writeOperand(BI.getSuccessor(1), true);
1804 } else if (isa<SwitchInst>(I)) {
1805 const SwitchInst& SI(cast<SwitchInst>(I));
1806 // Special case switch instruction to get formatting nice and correct.
1808 writeOperand(SI.getCondition(), true);
1810 writeOperand(SI.getDefaultDest(), true);
1812 for (SwitchInst::ConstCaseIt i = SI.case_begin(), e = SI.case_end();
1815 writeOperand(i.getCaseValue(), true);
1817 writeOperand(i.getCaseSuccessor(), true);
1820 } else if (isa<IndirectBrInst>(I)) {
1821 // Special case indirectbr instruction to get formatting nice and correct.
1823 writeOperand(Operand, true);
1826 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
1829 writeOperand(I.getOperand(i), true);
1832 } else if (const PHINode *PN = dyn_cast<PHINode>(&I)) {
1834 TypePrinter.print(I.getType(), Out);
1837 for (unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) {
1838 if (op) Out << ", ";
1840 writeOperand(PN->getIncomingValue(op), false); Out << ", ";
1841 writeOperand(PN->getIncomingBlock(op), false); Out << " ]";
1843 } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) {
1845 writeOperand(I.getOperand(0), true);
1846 for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
1848 } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
1850 writeOperand(I.getOperand(0), true); Out << ", ";
1851 writeOperand(I.getOperand(1), true);
1852 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
1854 } else if (const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
1856 TypePrinter.print(I.getType(), Out);
1857 Out << " personality ";
1858 writeOperand(I.getOperand(0), true); Out << '\n';
1860 if (LPI->isCleanup())
1863 for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
1864 if (i != 0 || LPI->isCleanup()) Out << "\n";
1865 if (LPI->isCatch(i))
1870 writeOperand(LPI->getClause(i), true);
1872 } else if (isa<ReturnInst>(I) && !Operand) {
1874 } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
1875 // Print the calling convention being used.
1876 if (CI->getCallingConv() != CallingConv::C) {
1878 PrintCallingConv(CI->getCallingConv(), Out);
1881 Operand = CI->getCalledValue();
1882 PointerType *PTy = cast<PointerType>(Operand->getType());
1883 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1884 Type *RetTy = FTy->getReturnType();
1885 const AttributeSet &PAL = CI->getAttributes();
1887 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
1888 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
1890 // If possible, print out the short form of the call instruction. We can
1891 // only do this if the first argument is a pointer to a nonvararg function,
1892 // and if the return type is not a pointer to a function.
1895 if (!FTy->isVarArg() &&
1896 (!RetTy->isPointerTy() ||
1897 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1898 TypePrinter.print(RetTy, Out);
1900 writeOperand(Operand, false);
1902 writeOperand(Operand, true);
1905 for (unsigned op = 0, Eop = CI->getNumArgOperands(); op < Eop; ++op) {
1908 writeParamOperand(CI->getArgOperand(op), PAL, op + 1);
1911 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
1912 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
1913 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
1914 Operand = II->getCalledValue();
1915 PointerType *PTy = cast<PointerType>(Operand->getType());
1916 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1917 Type *RetTy = FTy->getReturnType();
1918 const AttributeSet &PAL = II->getAttributes();
1920 // Print the calling convention being used.
1921 if (II->getCallingConv() != CallingConv::C) {
1923 PrintCallingConv(II->getCallingConv(), Out);
1926 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
1927 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
1929 // If possible, print out the short form of the invoke instruction. We can
1930 // only do this if the first argument is a pointer to a nonvararg function,
1931 // and if the return type is not a pointer to a function.
1934 if (!FTy->isVarArg() &&
1935 (!RetTy->isPointerTy() ||
1936 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1937 TypePrinter.print(RetTy, Out);
1939 writeOperand(Operand, false);
1941 writeOperand(Operand, true);
1944 for (unsigned op = 0, Eop = II->getNumArgOperands(); op < Eop; ++op) {
1947 writeParamOperand(II->getArgOperand(op), PAL, op + 1);
1951 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
1952 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
1955 writeOperand(II->getNormalDest(), true);
1957 writeOperand(II->getUnwindDest(), true);
1959 } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
1961 TypePrinter.print(AI->getAllocatedType(), Out);
1962 if (!AI->getArraySize() || AI->isArrayAllocation()) {
1964 writeOperand(AI->getArraySize(), true);
1966 if (AI->getAlignment()) {
1967 Out << ", align " << AI->getAlignment();
1969 } else if (isa<CastInst>(I)) {
1972 writeOperand(Operand, true); // Work with broken code
1975 TypePrinter.print(I.getType(), Out);
1976 } else if (isa<VAArgInst>(I)) {
1979 writeOperand(Operand, true); // Work with broken code
1982 TypePrinter.print(I.getType(), Out);
1983 } else if (Operand) { // Print the normal way.
1985 // PrintAllTypes - Instructions who have operands of all the same type
1986 // omit the type from all but the first operand. If the instruction has
1987 // different type operands (for example br), then they are all printed.
1988 bool PrintAllTypes = false;
1989 Type *TheType = Operand->getType();
1991 // Select, Store and ShuffleVector always print all types.
1992 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
1993 || isa<ReturnInst>(I)) {
1994 PrintAllTypes = true;
1996 for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
1997 Operand = I.getOperand(i);
1998 // note that Operand shouldn't be null, but the test helps make dump()
1999 // more tolerant of malformed IR
2000 if (Operand && Operand->getType() != TheType) {
2001 PrintAllTypes = true; // We have differing types! Print them all!
2007 if (!PrintAllTypes) {
2009 TypePrinter.print(TheType, Out);
2013 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {
2015 writeOperand(I.getOperand(i), PrintAllTypes);
2019 // Print atomic ordering/alignment for memory operations
2020 if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
2022 writeAtomic(LI->getOrdering(), LI->getSynchScope());
2023 if (LI->getAlignment())
2024 Out << ", align " << LI->getAlignment();
2025 } else if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
2027 writeAtomic(SI->getOrdering(), SI->getSynchScope());
2028 if (SI->getAlignment())
2029 Out << ", align " << SI->getAlignment();
2030 } else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) {
2031 writeAtomic(CXI->getOrdering(), CXI->getSynchScope());
2032 } else if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
2033 writeAtomic(RMWI->getOrdering(), RMWI->getSynchScope());
2034 } else if (const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
2035 writeAtomic(FI->getOrdering(), FI->getSynchScope());
2038 // Print Metadata info.
2039 SmallVector<std::pair<unsigned, MDNode*>, 4> InstMD;
2040 I.getAllMetadata(InstMD);
2041 if (!InstMD.empty()) {
2042 SmallVector<StringRef, 8> MDNames;
2043 I.getType()->getContext().getMDKindNames(MDNames);
2044 for (unsigned i = 0, e = InstMD.size(); i != e; ++i) {
2045 unsigned Kind = InstMD[i].first;
2046 if (Kind < MDNames.size()) {
2047 Out << ", !" << MDNames[Kind];
2049 Out << ", !<unknown kind #" << Kind << ">";
2052 WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
2056 printInfoComment(I);
2059 static void WriteMDNodeComment(const MDNode *Node,
2060 formatted_raw_ostream &Out) {
2061 if (Node->getNumOperands() < 1)
2064 Value *Op = Node->getOperand(0);
2065 if (!Op || !isa<ConstantInt>(Op) || cast<ConstantInt>(Op)->getBitWidth() < 32)
2068 DIDescriptor Desc(Node);
2072 unsigned Tag = Desc.getTag();
2073 Out.PadToColumn(50);
2074 if (dwarf::TagString(Tag)) {
2077 } else if (Tag == dwarf::DW_TAG_user_base) {
2078 Out << "; [ DW_TAG_user_base ]";
2082 void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
2083 Out << '!' << Slot << " = metadata ";
2084 printMDNodeBody(Node);
2087 void AssemblyWriter::writeAllMDNodes() {
2088 SmallVector<const MDNode *, 16> Nodes;
2089 Nodes.resize(Machine.mdn_size());
2090 for (SlotTracker::mdn_iterator I = Machine.mdn_begin(), E = Machine.mdn_end();
2092 Nodes[I->second] = cast<MDNode>(I->first);
2094 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
2095 writeMDNode(i, Nodes[i]);
2099 void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
2100 WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule);
2101 WriteMDNodeComment(Node, Out);
2105 void AssemblyWriter::writeAllAttributeGroups() {
2106 std::vector<std::pair<AttributeSet, unsigned> > asVec;
2107 asVec.resize(Machine.as_size());
2109 for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end();
2111 asVec[I->second] = *I;
2113 for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
2114 I = asVec.begin(), E = asVec.end(); I != E; ++I)
2115 Out << "attributes #" << I->second << " = { "
2116 << I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
2121 //===----------------------------------------------------------------------===//
2122 // External Interface declarations
2123 //===----------------------------------------------------------------------===//
2125 void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2126 SlotTracker SlotTable(this);
2127 formatted_raw_ostream OS(ROS);
2128 AssemblyWriter W(OS, SlotTable, this, AAW);
2129 W.printModule(this);
2132 void NamedMDNode::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2133 SlotTracker SlotTable(getParent());
2134 formatted_raw_ostream OS(ROS);
2135 AssemblyWriter W(OS, SlotTable, getParent(), AAW);
2136 W.printNamedMDNode(this);
2139 void Type::print(raw_ostream &OS) const {
2141 OS << "<null Type>";
2145 TP.print(const_cast<Type*>(this), OS);
2147 // If the type is a named struct type, print the body as well.
2148 if (StructType *STy = dyn_cast<StructType>(const_cast<Type*>(this)))
2149 if (!STy->isLiteral()) {
2151 TP.printStructBody(STy, OS);
2155 void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2157 ROS << "printing a <null> value\n";
2160 formatted_raw_ostream OS(ROS);
2161 if (const Instruction *I = dyn_cast<Instruction>(this)) {
2162 const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
2163 SlotTracker SlotTable(F);
2164 AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), AAW);
2165 W.printInstruction(*I);
2166 } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
2167 SlotTracker SlotTable(BB->getParent());
2168 AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), AAW);
2169 W.printBasicBlock(BB);
2170 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
2171 SlotTracker SlotTable(GV->getParent());
2172 AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
2173 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
2175 else if (const Function *F = dyn_cast<Function>(GV))
2178 W.printAlias(cast<GlobalAlias>(GV));
2179 } else if (const MDNode *N = dyn_cast<MDNode>(this)) {
2180 const Function *F = N->getFunction();
2181 SlotTracker SlotTable(F);
2182 AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
2183 W.printMDNodeBody(N);
2184 } else if (const Constant *C = dyn_cast<Constant>(this)) {
2185 TypePrinting TypePrinter;
2186 TypePrinter.print(C->getType(), OS);
2188 WriteConstantInternal(OS, C, TypePrinter, 0, 0);
2189 } else if (isa<InlineAsm>(this) || isa<MDString>(this) ||
2190 isa<Argument>(this)) {
2191 WriteAsOperand(OS, this, true, 0);
2193 // Otherwise we don't know what it is. Call the virtual function to
2194 // allow a subclass to print itself.
2199 // Value::printCustom - subclasses should override this to implement printing.
2200 void Value::printCustom(raw_ostream &OS) const {
2201 llvm_unreachable("Unknown value to print out!");
2204 // Value::dump - allow easy printing of Values from the debugger.
2205 void Value::dump() const { print(dbgs()); dbgs() << '\n'; }
2207 // Type::dump - allow easy printing of Types from the debugger.
2208 void Type::dump() const { print(dbgs()); }
2210 // Module::dump() - Allow printing of Modules from the debugger.
2211 void Module::dump() const { print(dbgs(), 0); }
2213 // NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger.
2214 void NamedMDNode::dump() const { print(dbgs(), 0); }