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/IR/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 "AsmWriter.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/DebugInfo.h"
23 #include "llvm/IR/AssemblyAnnotationWriter.h"
24 #include "llvm/IR/CallingConv.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DerivedTypes.h"
27 #include "llvm/IR/IRPrintingPasses.h"
28 #include "llvm/IR/InlineAsm.h"
29 #include "llvm/IR/IntrinsicInst.h"
30 #include "llvm/IR/LLVMContext.h"
31 #include "llvm/IR/Module.h"
32 #include "llvm/IR/Operator.h"
33 #include "llvm/IR/TypeFinder.h"
34 #include "llvm/IR/ValueSymbolTable.h"
35 #include "llvm/Support/CFG.h"
36 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/Dwarf.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/FormattedStream.h"
40 #include "llvm/Support/MathExtras.h"
45 // Make virtual table appear in this compilation unit.
46 AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {}
48 //===----------------------------------------------------------------------===//
50 //===----------------------------------------------------------------------===//
52 static const Module *getModuleFromVal(const Value *V) {
53 if (const Argument *MA = dyn_cast<Argument>(V))
54 return MA->getParent() ? MA->getParent()->getParent() : 0;
56 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
57 return BB->getParent() ? BB->getParent()->getParent() : 0;
59 if (const Instruction *I = dyn_cast<Instruction>(V)) {
60 const Function *M = I->getParent() ? I->getParent()->getParent() : 0;
61 return M ? M->getParent() : 0;
64 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
65 return GV->getParent();
69 static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
71 default: Out << "cc" << cc; break;
72 case CallingConv::Fast: Out << "fastcc"; break;
73 case CallingConv::Cold: Out << "coldcc"; break;
74 case CallingConv::WebKit_JS: Out << "webkit_jscc"; break;
75 case CallingConv::AnyReg: Out << "anyregcc"; break;
76 case CallingConv::X86_StdCall: Out << "x86_stdcallcc"; break;
77 case CallingConv::X86_FastCall: Out << "x86_fastcallcc"; break;
78 case CallingConv::X86_ThisCall: Out << "x86_thiscallcc"; break;
79 case CallingConv::Intel_OCL_BI: Out << "intel_ocl_bicc"; break;
80 case CallingConv::ARM_APCS: Out << "arm_apcscc"; break;
81 case CallingConv::ARM_AAPCS: Out << "arm_aapcscc"; break;
82 case CallingConv::ARM_AAPCS_VFP: Out << "arm_aapcs_vfpcc"; break;
83 case CallingConv::MSP430_INTR: Out << "msp430_intrcc"; break;
84 case CallingConv::PTX_Kernel: Out << "ptx_kernel"; break;
85 case CallingConv::PTX_Device: Out << "ptx_device"; break;
86 case CallingConv::X86_64_SysV: Out << "x86_64_sysvcc"; break;
87 case CallingConv::X86_64_Win64: Out << "x86_64_win64cc"; break;
88 case CallingConv::SPIR_FUNC: Out << "spir_func"; break;
89 case CallingConv::SPIR_KERNEL: Out << "spir_kernel"; break;
93 // PrintEscapedString - Print each character of the specified string, escaping
94 // it if it is not printable or if it is an escape char.
95 static void PrintEscapedString(StringRef Name, raw_ostream &Out) {
96 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
97 unsigned char C = Name[i];
98 if (isprint(C) && C != '\\' && C != '"')
101 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
112 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
113 /// prefixed with % (if the string only contains simple characters) or is
114 /// surrounded with ""'s (if it has special chars in it). Print it out.
115 static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
116 assert(!Name.empty() && "Cannot get empty name!");
118 case NoPrefix: break;
119 case GlobalPrefix: OS << '@'; break;
120 case LabelPrefix: break;
121 case LocalPrefix: OS << '%'; break;
124 // Scan the name to see if it needs quotes first.
125 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
127 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
128 // By making this unsigned, the value passed in to isalnum will always be
129 // in the range 0-255. This is important when building with MSVC because
130 // its implementation will assert. This situation can arise when dealing
131 // with UTF-8 multibyte characters.
132 unsigned char C = Name[i];
133 if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' &&
141 // If we didn't need any quotes, just write out the name in one blast.
147 // Okay, we need quotes. Output the quotes and escape any scary characters as
150 PrintEscapedString(Name, OS);
154 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
155 /// prefixed with % (if the string only contains simple characters) or is
156 /// surrounded with ""'s (if it has special chars in it). Print it out.
157 static void PrintLLVMName(raw_ostream &OS, const Value *V) {
158 PrintLLVMName(OS, V->getName(),
159 isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
165 void TypePrinting::incorporateTypes(const Module &M) {
166 NamedTypes.run(M, false);
168 // The list of struct types we got back includes all the struct types, split
169 // the unnamed ones out to a numbering and remove the anonymous structs.
170 unsigned NextNumber = 0;
172 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(), I, E;
173 for (I = NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I) {
174 StructType *STy = *I;
176 // Ignore anonymous types.
177 if (STy->isLiteral())
180 if (STy->getName().empty())
181 NumberedTypes[STy] = NextNumber++;
186 NamedTypes.erase(NextToUse, NamedTypes.end());
190 /// CalcTypeName - Write the specified type to the specified raw_ostream, making
191 /// use of type names or up references to shorten the type name where possible.
192 void TypePrinting::print(Type *Ty, raw_ostream &OS) {
193 switch (Ty->getTypeID()) {
194 case Type::VoidTyID: OS << "void"; return;
195 case Type::HalfTyID: OS << "half"; return;
196 case Type::FloatTyID: OS << "float"; return;
197 case Type::DoubleTyID: OS << "double"; return;
198 case Type::X86_FP80TyID: OS << "x86_fp80"; return;
199 case Type::FP128TyID: OS << "fp128"; return;
200 case Type::PPC_FP128TyID: OS << "ppc_fp128"; return;
201 case Type::LabelTyID: OS << "label"; return;
202 case Type::MetadataTyID: OS << "metadata"; return;
203 case Type::X86_MMXTyID: OS << "x86_mmx"; return;
204 case Type::IntegerTyID:
205 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
208 case Type::FunctionTyID: {
209 FunctionType *FTy = cast<FunctionType>(Ty);
210 print(FTy->getReturnType(), OS);
212 for (FunctionType::param_iterator I = FTy->param_begin(),
213 E = FTy->param_end(); I != E; ++I) {
214 if (I != FTy->param_begin())
218 if (FTy->isVarArg()) {
219 if (FTy->getNumParams()) OS << ", ";
225 case Type::StructTyID: {
226 StructType *STy = cast<StructType>(Ty);
228 if (STy->isLiteral())
229 return printStructBody(STy, OS);
231 if (!STy->getName().empty())
232 return PrintLLVMName(OS, STy->getName(), LocalPrefix);
234 DenseMap<StructType*, unsigned>::iterator I = NumberedTypes.find(STy);
235 if (I != NumberedTypes.end())
236 OS << '%' << I->second;
237 else // Not enumerated, print the hex address.
238 OS << "%\"type " << STy << '\"';
241 case Type::PointerTyID: {
242 PointerType *PTy = cast<PointerType>(Ty);
243 print(PTy->getElementType(), OS);
244 if (unsigned AddressSpace = PTy->getAddressSpace())
245 OS << " addrspace(" << AddressSpace << ')';
249 case Type::ArrayTyID: {
250 ArrayType *ATy = cast<ArrayType>(Ty);
251 OS << '[' << ATy->getNumElements() << " x ";
252 print(ATy->getElementType(), OS);
256 case Type::VectorTyID: {
257 VectorType *PTy = cast<VectorType>(Ty);
258 OS << "<" << PTy->getNumElements() << " x ";
259 print(PTy->getElementType(), OS);
264 llvm_unreachable("Invalid TypeID");
267 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
268 if (STy->isOpaque()) {
276 if (STy->getNumElements() == 0) {
279 StructType::element_iterator I = STy->element_begin();
282 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
293 //===----------------------------------------------------------------------===//
294 // SlotTracker Class: Enumerate slot numbers for unnamed values
295 //===----------------------------------------------------------------------===//
296 /// This class provides computation of slot numbers for LLVM Assembly writing.
300 /// ValueMap - A mapping of Values to slot numbers.
301 typedef DenseMap<const Value*, unsigned> ValueMap;
304 /// TheModule - The module for which we are holding slot numbers.
305 const Module* TheModule;
307 /// TheFunction - The function for which we are holding slot numbers.
308 const Function* TheFunction;
309 bool FunctionProcessed;
311 /// mMap - The slot map for the module level data.
315 /// fMap - The slot map for the function level data.
319 /// mdnMap - Map for MDNodes.
320 DenseMap<const MDNode*, unsigned> mdnMap;
323 /// asMap - The slot map for attribute sets.
324 DenseMap<AttributeSet, unsigned> asMap;
327 /// Construct from a module
328 explicit SlotTracker(const Module *M);
329 /// Construct from a function, starting out in incorp state.
330 explicit SlotTracker(const Function *F);
332 /// Return the slot number of the specified value in it's type
333 /// plane. If something is not in the SlotTracker, return -1.
334 int getLocalSlot(const Value *V);
335 int getGlobalSlot(const GlobalValue *V);
336 int getMetadataSlot(const MDNode *N);
337 int getAttributeGroupSlot(AttributeSet AS);
339 /// If you'd like to deal with a function instead of just a module, use
340 /// this method to get its data into the SlotTracker.
341 void incorporateFunction(const Function *F) {
343 FunctionProcessed = false;
346 /// After calling incorporateFunction, use this method to remove the
347 /// most recently incorporated function from the SlotTracker. This
348 /// will reset the state of the machine back to just the module contents.
349 void purgeFunction();
351 /// MDNode map iterators.
352 typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator;
353 mdn_iterator mdn_begin() { return mdnMap.begin(); }
354 mdn_iterator mdn_end() { return mdnMap.end(); }
355 unsigned mdn_size() const { return mdnMap.size(); }
356 bool mdn_empty() const { return mdnMap.empty(); }
358 /// AttributeSet map iterators.
359 typedef DenseMap<AttributeSet, unsigned>::iterator as_iterator;
360 as_iterator as_begin() { return asMap.begin(); }
361 as_iterator as_end() { return asMap.end(); }
362 unsigned as_size() const { return asMap.size(); }
363 bool as_empty() const { return asMap.empty(); }
365 /// This function does the actual initialization.
366 inline void initialize();
368 // Implementation Details
370 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
371 void CreateModuleSlot(const GlobalValue *V);
373 /// CreateMetadataSlot - Insert the specified MDNode* into the slot table.
374 void CreateMetadataSlot(const MDNode *N);
376 /// CreateFunctionSlot - Insert the specified Value* into the slot table.
377 void CreateFunctionSlot(const Value *V);
379 /// \brief Insert the specified AttributeSet into the slot table.
380 void CreateAttributeSetSlot(AttributeSet AS);
382 /// Add all of the module level global variables (and their initializers)
383 /// and function declarations, but not the contents of those functions.
384 void processModule();
386 /// Add all of the functions arguments, basic blocks, and instructions.
387 void processFunction();
389 SlotTracker(const SlotTracker &) LLVM_DELETED_FUNCTION;
390 void operator=(const SlotTracker &) LLVM_DELETED_FUNCTION;
393 SlotTracker *createSlotTracker(const Module *M) {
394 return new SlotTracker(M);
397 static SlotTracker *createSlotTracker(const Value *V) {
398 if (const Argument *FA = dyn_cast<Argument>(V))
399 return new SlotTracker(FA->getParent());
401 if (const Instruction *I = dyn_cast<Instruction>(V))
403 return new SlotTracker(I->getParent()->getParent());
405 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
406 return new SlotTracker(BB->getParent());
408 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
409 return new SlotTracker(GV->getParent());
411 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
412 return new SlotTracker(GA->getParent());
414 if (const Function *Func = dyn_cast<Function>(V))
415 return new SlotTracker(Func);
417 if (const MDNode *MD = dyn_cast<MDNode>(V)) {
418 if (!MD->isFunctionLocal())
419 return new SlotTracker(MD->getFunction());
421 return new SlotTracker((Function *)0);
428 #define ST_DEBUG(X) dbgs() << X
433 // Module level constructor. Causes the contents of the Module (sans functions)
434 // to be added to the slot table.
435 SlotTracker::SlotTracker(const Module *M)
436 : TheModule(M), TheFunction(0), FunctionProcessed(false),
437 mNext(0), fNext(0), mdnNext(0), asNext(0) {
440 // Function level constructor. Causes the contents of the Module and the one
441 // function provided to be added to the slot table.
442 SlotTracker::SlotTracker(const Function *F)
443 : TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false),
444 mNext(0), fNext(0), mdnNext(0), asNext(0) {
447 inline void SlotTracker::initialize() {
450 TheModule = 0; ///< Prevent re-processing next time we're called.
453 if (TheFunction && !FunctionProcessed)
457 // Iterate through all the global variables, functions, and global
458 // variable initializers and create slots for them.
459 void SlotTracker::processModule() {
460 ST_DEBUG("begin processModule!\n");
462 // Add all of the unnamed global variables to the value table.
463 for (Module::const_global_iterator I = TheModule->global_begin(),
464 E = TheModule->global_end(); I != E; ++I) {
469 // Add metadata used by named metadata.
470 for (Module::const_named_metadata_iterator
471 I = TheModule->named_metadata_begin(),
472 E = TheModule->named_metadata_end(); I != E; ++I) {
473 const NamedMDNode *NMD = I;
474 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
475 CreateMetadataSlot(NMD->getOperand(i));
478 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
481 // Add all the unnamed functions to the table.
484 // Add all the function attributes to the table.
485 // FIXME: Add attributes of other objects?
486 AttributeSet FnAttrs = I->getAttributes().getFnAttributes();
487 if (FnAttrs.hasAttributes(AttributeSet::FunctionIndex))
488 CreateAttributeSetSlot(FnAttrs);
491 ST_DEBUG("end processModule!\n");
494 // Process the arguments, basic blocks, and instructions of a function.
495 void SlotTracker::processFunction() {
496 ST_DEBUG("begin processFunction!\n");
499 // Add all the function arguments with no names.
500 for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
501 AE = TheFunction->arg_end(); AI != AE; ++AI)
503 CreateFunctionSlot(AI);
505 ST_DEBUG("Inserting Instructions:\n");
507 SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
509 // Add all of the basic blocks and instructions with no names.
510 for (Function::const_iterator BB = TheFunction->begin(),
511 E = TheFunction->end(); BB != E; ++BB) {
513 CreateFunctionSlot(BB);
515 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
517 if (!I->getType()->isVoidTy() && !I->hasName())
518 CreateFunctionSlot(I);
520 // Intrinsics can directly use metadata. We allow direct calls to any
521 // llvm.foo function here, because the target may not be linked into the
523 if (const CallInst *CI = dyn_cast<CallInst>(I)) {
524 if (Function *F = CI->getCalledFunction())
525 if (F->isIntrinsic())
526 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
527 if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
528 CreateMetadataSlot(N);
530 // Add all the call attributes to the table.
531 AttributeSet Attrs = CI->getAttributes().getFnAttributes();
532 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
533 CreateAttributeSetSlot(Attrs);
534 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) {
535 // Add all the call attributes to the table.
536 AttributeSet Attrs = II->getAttributes().getFnAttributes();
537 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
538 CreateAttributeSetSlot(Attrs);
541 // Process metadata attached with this instruction.
542 I->getAllMetadata(MDForInst);
543 for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
544 CreateMetadataSlot(MDForInst[i].second);
549 FunctionProcessed = true;
551 ST_DEBUG("end processFunction!\n");
554 /// Clean up after incorporating a function. This is the only way to get out of
555 /// the function incorporation state that affects get*Slot/Create*Slot. Function
556 /// incorporation state is indicated by TheFunction != 0.
557 void SlotTracker::purgeFunction() {
558 ST_DEBUG("begin purgeFunction!\n");
559 fMap.clear(); // Simply discard the function level map
561 FunctionProcessed = false;
562 ST_DEBUG("end purgeFunction!\n");
565 /// getGlobalSlot - Get the slot number of a global value.
566 int SlotTracker::getGlobalSlot(const GlobalValue *V) {
567 // Check for uninitialized state and do lazy initialization.
570 // Find the value in the module map
571 ValueMap::iterator MI = mMap.find(V);
572 return MI == mMap.end() ? -1 : (int)MI->second;
575 /// getMetadataSlot - Get the slot number of a MDNode.
576 int SlotTracker::getMetadataSlot(const MDNode *N) {
577 // Check for uninitialized state and do lazy initialization.
580 // Find the MDNode in the module map
581 mdn_iterator MI = mdnMap.find(N);
582 return MI == mdnMap.end() ? -1 : (int)MI->second;
586 /// getLocalSlot - Get the slot number for a value that is local to a function.
587 int SlotTracker::getLocalSlot(const Value *V) {
588 assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!");
590 // Check for uninitialized state and do lazy initialization.
593 ValueMap::iterator FI = fMap.find(V);
594 return FI == fMap.end() ? -1 : (int)FI->second;
597 int SlotTracker::getAttributeGroupSlot(AttributeSet AS) {
598 // Check for uninitialized state and do lazy initialization.
601 // Find the AttributeSet in the module map.
602 as_iterator AI = asMap.find(AS);
603 return AI == asMap.end() ? -1 : (int)AI->second;
606 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
607 void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
608 assert(V && "Can't insert a null Value into SlotTracker!");
609 assert(!V->getType()->isVoidTy() && "Doesn't need a slot!");
610 assert(!V->hasName() && "Doesn't need a slot!");
612 unsigned DestSlot = mNext++;
615 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
617 // G = Global, F = Function, A = Alias, o = other
618 ST_DEBUG((isa<GlobalVariable>(V) ? 'G' :
619 (isa<Function>(V) ? 'F' :
620 (isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n");
623 /// CreateSlot - Create a new slot for the specified value if it has no name.
624 void SlotTracker::CreateFunctionSlot(const Value *V) {
625 assert(!V->getType()->isVoidTy() && !V->hasName() && "Doesn't need a slot!");
627 unsigned DestSlot = fNext++;
630 // G = Global, F = Function, o = other
631 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
632 DestSlot << " [o]\n");
635 /// CreateModuleSlot - Insert the specified MDNode* into the slot table.
636 void SlotTracker::CreateMetadataSlot(const MDNode *N) {
637 assert(N && "Can't insert a null Value into SlotTracker!");
639 // Don't insert if N is a function-local metadata, these are always printed
641 if (!N->isFunctionLocal()) {
642 mdn_iterator I = mdnMap.find(N);
643 if (I != mdnMap.end())
646 unsigned DestSlot = mdnNext++;
647 mdnMap[N] = DestSlot;
650 // Recursively add any MDNodes referenced by operands.
651 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
652 if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i)))
653 CreateMetadataSlot(Op);
656 void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) {
657 assert(AS.hasAttributes(AttributeSet::FunctionIndex) &&
658 "Doesn't need a slot!");
660 as_iterator I = asMap.find(AS);
661 if (I != asMap.end())
664 unsigned DestSlot = asNext++;
665 asMap[AS] = DestSlot;
668 //===----------------------------------------------------------------------===//
669 // AsmWriter Implementation
670 //===----------------------------------------------------------------------===//
672 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
673 TypePrinting *TypePrinter,
674 SlotTracker *Machine,
675 const Module *Context);
677 static const char *getPredicateText(unsigned predicate) {
678 const char * pred = "unknown";
680 case FCmpInst::FCMP_FALSE: pred = "false"; break;
681 case FCmpInst::FCMP_OEQ: pred = "oeq"; break;
682 case FCmpInst::FCMP_OGT: pred = "ogt"; break;
683 case FCmpInst::FCMP_OGE: pred = "oge"; break;
684 case FCmpInst::FCMP_OLT: pred = "olt"; break;
685 case FCmpInst::FCMP_OLE: pred = "ole"; break;
686 case FCmpInst::FCMP_ONE: pred = "one"; break;
687 case FCmpInst::FCMP_ORD: pred = "ord"; break;
688 case FCmpInst::FCMP_UNO: pred = "uno"; break;
689 case FCmpInst::FCMP_UEQ: pred = "ueq"; break;
690 case FCmpInst::FCMP_UGT: pred = "ugt"; break;
691 case FCmpInst::FCMP_UGE: pred = "uge"; break;
692 case FCmpInst::FCMP_ULT: pred = "ult"; break;
693 case FCmpInst::FCMP_ULE: pred = "ule"; break;
694 case FCmpInst::FCMP_UNE: pred = "une"; break;
695 case FCmpInst::FCMP_TRUE: pred = "true"; break;
696 case ICmpInst::ICMP_EQ: pred = "eq"; break;
697 case ICmpInst::ICMP_NE: pred = "ne"; break;
698 case ICmpInst::ICMP_SGT: pred = "sgt"; break;
699 case ICmpInst::ICMP_SGE: pred = "sge"; break;
700 case ICmpInst::ICMP_SLT: pred = "slt"; break;
701 case ICmpInst::ICMP_SLE: pred = "sle"; break;
702 case ICmpInst::ICMP_UGT: pred = "ugt"; break;
703 case ICmpInst::ICMP_UGE: pred = "uge"; break;
704 case ICmpInst::ICMP_ULT: pred = "ult"; break;
705 case ICmpInst::ICMP_ULE: pred = "ule"; break;
710 static void writeAtomicRMWOperation(raw_ostream &Out,
711 AtomicRMWInst::BinOp Op) {
713 default: Out << " <unknown operation " << Op << ">"; break;
714 case AtomicRMWInst::Xchg: Out << " xchg"; break;
715 case AtomicRMWInst::Add: Out << " add"; break;
716 case AtomicRMWInst::Sub: Out << " sub"; break;
717 case AtomicRMWInst::And: Out << " and"; break;
718 case AtomicRMWInst::Nand: Out << " nand"; break;
719 case AtomicRMWInst::Or: Out << " or"; break;
720 case AtomicRMWInst::Xor: Out << " xor"; break;
721 case AtomicRMWInst::Max: Out << " max"; break;
722 case AtomicRMWInst::Min: Out << " min"; break;
723 case AtomicRMWInst::UMax: Out << " umax"; break;
724 case AtomicRMWInst::UMin: Out << " umin"; break;
728 static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
729 if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
730 // Unsafe algebra implies all the others, no need to write them all out
731 if (FPO->hasUnsafeAlgebra())
734 if (FPO->hasNoNaNs())
736 if (FPO->hasNoInfs())
738 if (FPO->hasNoSignedZeros())
740 if (FPO->hasAllowReciprocal())
745 if (const OverflowingBinaryOperator *OBO =
746 dyn_cast<OverflowingBinaryOperator>(U)) {
747 if (OBO->hasNoUnsignedWrap())
749 if (OBO->hasNoSignedWrap())
751 } else if (const PossiblyExactOperator *Div =
752 dyn_cast<PossiblyExactOperator>(U)) {
755 } else if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
756 if (GEP->isInBounds())
761 static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
762 TypePrinting &TypePrinter,
763 SlotTracker *Machine,
764 const Module *Context) {
765 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
766 if (CI->getType()->isIntegerTy(1)) {
767 Out << (CI->getZExtValue() ? "true" : "false");
770 Out << CI->getValue();
774 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
775 if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle ||
776 &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble) {
777 // We would like to output the FP constant value in exponential notation,
778 // but we cannot do this if doing so will lose precision. Check here to
779 // make sure that we only output it in exponential format if we can parse
780 // the value back and get the same value.
783 bool isHalf = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEhalf;
784 bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
785 bool isInf = CFP->getValueAPF().isInfinity();
786 bool isNaN = CFP->getValueAPF().isNaN();
787 if (!isHalf && !isInf && !isNaN) {
788 double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
789 CFP->getValueAPF().convertToFloat();
790 SmallString<128> StrVal;
791 raw_svector_ostream(StrVal) << Val;
793 // Check to make sure that the stringized number is not some string like
794 // "Inf" or NaN, that atof will accept, but the lexer will not. Check
795 // that the string matches the "[-+]?[0-9]" regex.
797 if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
798 ((StrVal[0] == '-' || StrVal[0] == '+') &&
799 (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
800 // Reparse stringized version!
801 if (APFloat(APFloat::IEEEdouble, StrVal).convertToDouble() == Val) {
807 // Otherwise we could not reparse it to exactly the same value, so we must
808 // output the string in hexadecimal format! Note that loading and storing
809 // floating point types changes the bits of NaNs on some hosts, notably
810 // x86, so we must not use these types.
811 assert(sizeof(double) == sizeof(uint64_t) &&
812 "assuming that double is 64 bits!");
814 APFloat apf = CFP->getValueAPF();
815 // Halves and floats are represented in ASCII IR as double, convert.
817 apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
820 utohex_buffer(uint64_t(apf.bitcastToAPInt().getZExtValue()),
825 // Either half, or some form of long double.
826 // These appear as a magic letter identifying the type, then a
827 // fixed number of hex digits.
829 // Bit position, in the current word, of the next nibble to print.
832 if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) {
834 // api needed to prevent premature destruction
835 APInt api = CFP->getValueAPF().bitcastToAPInt();
836 const uint64_t* p = api.getRawData();
837 uint64_t word = p[1];
839 int width = api.getBitWidth();
840 for (int j=0; j<width; j+=4, shiftcount-=4) {
841 unsigned int nibble = (word>>shiftcount) & 15;
843 Out << (unsigned char)(nibble + '0');
845 Out << (unsigned char)(nibble - 10 + 'A');
846 if (shiftcount == 0 && j+4 < width) {
850 shiftcount = width-j-4;
854 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad) {
857 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble) {
860 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEhalf) {
864 llvm_unreachable("Unsupported floating point type");
865 // api needed to prevent premature destruction
866 APInt api = CFP->getValueAPF().bitcastToAPInt();
867 const uint64_t* p = api.getRawData();
869 int width = api.getBitWidth();
870 for (int j=0; j<width; j+=4, shiftcount-=4) {
871 unsigned int nibble = (word>>shiftcount) & 15;
873 Out << (unsigned char)(nibble + '0');
875 Out << (unsigned char)(nibble - 10 + 'A');
876 if (shiftcount == 0 && j+4 < width) {
880 shiftcount = width-j-4;
886 if (isa<ConstantAggregateZero>(CV)) {
887 Out << "zeroinitializer";
891 if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
892 Out << "blockaddress(";
893 WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine,
896 WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine,
902 if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
903 Type *ETy = CA->getType()->getElementType();
905 TypePrinter.print(ETy, Out);
907 WriteAsOperandInternal(Out, CA->getOperand(0),
908 &TypePrinter, Machine,
910 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
912 TypePrinter.print(ETy, Out);
914 WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine,
921 if (const ConstantDataArray *CA = dyn_cast<ConstantDataArray>(CV)) {
922 // As a special case, print the array as a string if it is an array of
923 // i8 with ConstantInt values.
924 if (CA->isString()) {
926 PrintEscapedString(CA->getAsString(), Out);
931 Type *ETy = CA->getType()->getElementType();
933 TypePrinter.print(ETy, Out);
935 WriteAsOperandInternal(Out, CA->getElementAsConstant(0),
936 &TypePrinter, Machine,
938 for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
940 TypePrinter.print(ETy, Out);
942 WriteAsOperandInternal(Out, CA->getElementAsConstant(i), &TypePrinter,
950 if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
951 if (CS->getType()->isPacked())
954 unsigned N = CS->getNumOperands();
957 TypePrinter.print(CS->getOperand(0)->getType(), Out);
960 WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine,
963 for (unsigned i = 1; i < N; i++) {
965 TypePrinter.print(CS->getOperand(i)->getType(), Out);
968 WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine,
975 if (CS->getType()->isPacked())
980 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
981 Type *ETy = CV->getType()->getVectorElementType();
983 TypePrinter.print(ETy, Out);
985 WriteAsOperandInternal(Out, CV->getAggregateElement(0U), &TypePrinter,
987 for (unsigned i = 1, e = CV->getType()->getVectorNumElements(); i != e;++i){
989 TypePrinter.print(ETy, Out);
991 WriteAsOperandInternal(Out, CV->getAggregateElement(i), &TypePrinter,
998 if (isa<ConstantPointerNull>(CV)) {
1003 if (isa<UndefValue>(CV)) {
1008 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1009 Out << CE->getOpcodeName();
1010 WriteOptimizationInfo(Out, CE);
1011 if (CE->isCompare())
1012 Out << ' ' << getPredicateText(CE->getPredicate());
1015 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1016 TypePrinter.print((*OI)->getType(), Out);
1018 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
1019 if (OI+1 != CE->op_end())
1023 if (CE->hasIndices()) {
1024 ArrayRef<unsigned> Indices = CE->getIndices();
1025 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1026 Out << ", " << Indices[i];
1031 TypePrinter.print(CE->getType(), Out);
1038 Out << "<placeholder or erroneous Constant>";
1041 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
1042 TypePrinting *TypePrinter,
1043 SlotTracker *Machine,
1044 const Module *Context) {
1046 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
1047 const Value *V = Node->getOperand(mi);
1051 TypePrinter->print(V->getType(), Out);
1053 WriteAsOperandInternal(Out, Node->getOperand(mi),
1054 TypePrinter, Machine, Context);
1063 // Full implementation of printing a Value as an operand with support for
1064 // TypePrinting, etc.
1065 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1066 TypePrinting *TypePrinter,
1067 SlotTracker *Machine,
1068 const Module *Context) {
1070 PrintLLVMName(Out, V);
1074 const Constant *CV = dyn_cast<Constant>(V);
1075 if (CV && !isa<GlobalValue>(CV)) {
1076 assert(TypePrinter && "Constants require TypePrinting!");
1077 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
1081 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1083 if (IA->hasSideEffects())
1084 Out << "sideeffect ";
1085 if (IA->isAlignStack())
1086 Out << "alignstack ";
1087 // We don't emit the AD_ATT dialect as it's the assumed default.
1088 if (IA->getDialect() == InlineAsm::AD_Intel)
1089 Out << "inteldialect ";
1091 PrintEscapedString(IA->getAsmString(), Out);
1093 PrintEscapedString(IA->getConstraintString(), Out);
1098 if (const MDNode *N = dyn_cast<MDNode>(V)) {
1099 if (N->isFunctionLocal()) {
1100 // Print metadata inline, not via slot reference number.
1101 WriteMDNodeBodyInternal(Out, N, TypePrinter, Machine, Context);
1106 if (N->isFunctionLocal())
1107 Machine = new SlotTracker(N->getFunction());
1109 Machine = new SlotTracker(Context);
1111 int Slot = Machine->getMetadataSlot(N);
1119 if (const MDString *MDS = dyn_cast<MDString>(V)) {
1121 PrintEscapedString(MDS->getString(), Out);
1126 if (V->getValueID() == Value::PseudoSourceValueVal ||
1127 V->getValueID() == Value::FixedStackPseudoSourceValueVal) {
1134 // If we have a SlotTracker, use it.
1136 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1137 Slot = Machine->getGlobalSlot(GV);
1140 Slot = Machine->getLocalSlot(V);
1142 // If the local value didn't succeed, then we may be referring to a value
1143 // from a different function. Translate it, as this can happen when using
1144 // address of blocks.
1146 if ((Machine = createSlotTracker(V))) {
1147 Slot = Machine->getLocalSlot(V);
1151 } else if ((Machine = createSlotTracker(V))) {
1152 // Otherwise, create one to get the # and then destroy it.
1153 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1154 Slot = Machine->getGlobalSlot(GV);
1157 Slot = Machine->getLocalSlot(V);
1166 Out << Prefix << Slot;
1171 void AssemblyWriter::init() {
1173 TypePrinter.incorporateTypes(*TheModule);
1177 AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
1179 AssemblyAnnotationWriter *AAW)
1180 : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW) {
1184 AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, const Module *M,
1185 AssemblyAnnotationWriter *AAW)
1186 : Out(o), TheModule(M), ModuleSlotTracker(createSlotTracker(M)),
1187 Machine(*ModuleSlotTracker), AnnotationWriter(AAW) {
1191 AssemblyWriter::~AssemblyWriter() { }
1193 void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
1195 Out << "<null operand!>";
1199 TypePrinter.print(Operand->getType(), Out);
1202 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
1205 void AssemblyWriter::writeAtomic(AtomicOrdering Ordering,
1206 SynchronizationScope SynchScope) {
1207 if (Ordering == NotAtomic)
1210 switch (SynchScope) {
1211 case SingleThread: Out << " singlethread"; break;
1212 case CrossThread: break;
1216 default: Out << " <bad ordering " << int(Ordering) << ">"; break;
1217 case Unordered: Out << " unordered"; break;
1218 case Monotonic: Out << " monotonic"; break;
1219 case Acquire: Out << " acquire"; break;
1220 case Release: Out << " release"; break;
1221 case AcquireRelease: Out << " acq_rel"; break;
1222 case SequentiallyConsistent: Out << " seq_cst"; break;
1226 void AssemblyWriter::writeParamOperand(const Value *Operand,
1227 AttributeSet Attrs, unsigned Idx) {
1229 Out << "<null operand!>";
1234 TypePrinter.print(Operand->getType(), Out);
1235 // Print parameter attributes list
1236 if (Attrs.hasAttributes(Idx))
1237 Out << ' ' << Attrs.getAsString(Idx);
1239 // Print the operand
1240 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
1243 void AssemblyWriter::printModule(const Module *M) {
1244 Machine.initialize();
1246 if (!M->getModuleIdentifier().empty() &&
1247 // Don't print the ID if it will start a new line (which would
1248 // require a comment char before it).
1249 M->getModuleIdentifier().find('\n') == std::string::npos)
1250 Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
1252 if (!M->getDataLayout().empty())
1253 Out << "target datalayout = \"" << M->getDataLayout() << "\"\n";
1254 if (!M->getTargetTriple().empty())
1255 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
1257 if (!M->getModuleInlineAsm().empty()) {
1258 // Split the string into lines, to make it easier to read the .ll file.
1259 std::string Asm = M->getModuleInlineAsm();
1261 size_t NewLine = Asm.find_first_of('\n', CurPos);
1263 while (NewLine != std::string::npos) {
1264 // We found a newline, print the portion of the asm string from the
1265 // last newline up to this newline.
1266 Out << "module asm \"";
1267 PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine),
1271 NewLine = Asm.find_first_of('\n', CurPos);
1273 std::string rest(Asm.begin()+CurPos, Asm.end());
1274 if (!rest.empty()) {
1275 Out << "module asm \"";
1276 PrintEscapedString(rest, Out);
1281 printTypeIdentities();
1283 // Output all globals.
1284 if (!M->global_empty()) Out << '\n';
1285 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
1287 printGlobal(I); Out << '\n';
1290 // Output all aliases.
1291 if (!M->alias_empty()) Out << "\n";
1292 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
1296 // Output all of the functions.
1297 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
1300 // Output all attribute groups.
1301 if (!Machine.as_empty()) {
1303 writeAllAttributeGroups();
1306 // Output named metadata.
1307 if (!M->named_metadata_empty()) Out << '\n';
1309 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
1310 E = M->named_metadata_end(); I != E; ++I)
1311 printNamedMDNode(I);
1314 if (!Machine.mdn_empty()) {
1320 void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
1322 StringRef Name = NMD->getName();
1324 Out << "<empty name> ";
1326 if (isalpha(static_cast<unsigned char>(Name[0])) ||
1327 Name[0] == '-' || Name[0] == '$' ||
1328 Name[0] == '.' || Name[0] == '_')
1331 Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F);
1332 for (unsigned i = 1, e = Name.size(); i != e; ++i) {
1333 unsigned char C = Name[i];
1334 if (isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' ||
1335 C == '.' || C == '_')
1338 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
1342 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1344 int Slot = Machine.getMetadataSlot(NMD->getOperand(i));
1354 static void PrintLinkage(GlobalValue::LinkageTypes LT,
1355 formatted_raw_ostream &Out) {
1357 case GlobalValue::ExternalLinkage: break;
1358 case GlobalValue::PrivateLinkage: Out << "private "; break;
1359 case GlobalValue::LinkerPrivateLinkage: Out << "linker_private "; break;
1360 case GlobalValue::LinkerPrivateWeakLinkage:
1361 Out << "linker_private_weak ";
1363 case GlobalValue::InternalLinkage: Out << "internal "; break;
1364 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
1365 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
1366 case GlobalValue::WeakAnyLinkage: Out << "weak "; break;
1367 case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break;
1368 case GlobalValue::CommonLinkage: Out << "common "; break;
1369 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1370 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
1371 case GlobalValue::AvailableExternallyLinkage:
1372 Out << "available_externally ";
1378 static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
1379 formatted_raw_ostream &Out) {
1381 case GlobalValue::DefaultVisibility: break;
1382 case GlobalValue::HiddenVisibility: Out << "hidden "; break;
1383 case GlobalValue::ProtectedVisibility: Out << "protected "; break;
1387 static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT,
1388 formatted_raw_ostream &Out) {
1390 case GlobalValue::DefaultStorageClass: break;
1391 case GlobalValue::DLLImportStorageClass: Out << "dllimport "; break;
1392 case GlobalValue::DLLExportStorageClass: Out << "dllexport "; break;
1396 static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM,
1397 formatted_raw_ostream &Out) {
1399 case GlobalVariable::NotThreadLocal:
1401 case GlobalVariable::GeneralDynamicTLSModel:
1402 Out << "thread_local ";
1404 case GlobalVariable::LocalDynamicTLSModel:
1405 Out << "thread_local(localdynamic) ";
1407 case GlobalVariable::InitialExecTLSModel:
1408 Out << "thread_local(initialexec) ";
1410 case GlobalVariable::LocalExecTLSModel:
1411 Out << "thread_local(localexec) ";
1416 void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
1417 if (GV->isMaterializable())
1418 Out << "; Materializable\n";
1420 WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine, GV->getParent());
1423 if (!GV->hasInitializer() && GV->hasExternalLinkage())
1426 PrintLinkage(GV->getLinkage(), Out);
1427 PrintVisibility(GV->getVisibility(), Out);
1428 PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
1429 PrintThreadLocalModel(GV->getThreadLocalMode(), Out);
1431 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
1432 Out << "addrspace(" << AddressSpace << ") ";
1433 if (GV->hasUnnamedAddr()) Out << "unnamed_addr ";
1434 if (GV->isExternallyInitialized()) Out << "externally_initialized ";
1435 Out << (GV->isConstant() ? "constant " : "global ");
1436 TypePrinter.print(GV->getType()->getElementType(), Out);
1438 if (GV->hasInitializer()) {
1440 writeOperand(GV->getInitializer(), false);
1443 if (GV->hasSection()) {
1444 Out << ", section \"";
1445 PrintEscapedString(GV->getSection(), Out);
1448 if (GV->getAlignment())
1449 Out << ", align " << GV->getAlignment();
1451 printInfoComment(*GV);
1454 void AssemblyWriter::printAlias(const GlobalAlias *GA) {
1455 if (GA->isMaterializable())
1456 Out << "; Materializable\n";
1458 // Don't crash when dumping partially built GA
1460 Out << "<<nameless>> = ";
1462 PrintLLVMName(Out, GA);
1465 PrintVisibility(GA->getVisibility(), Out);
1466 PrintDLLStorageClass(GA->getDLLStorageClass(), Out);
1470 PrintLinkage(GA->getLinkage(), Out);
1472 const Constant *Aliasee = GA->getAliasee();
1475 TypePrinter.print(GA->getType(), Out);
1476 Out << " <<NULL ALIASEE>>";
1478 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
1481 printInfoComment(*GA);
1485 void AssemblyWriter::printTypeIdentities() {
1486 if (TypePrinter.NumberedTypes.empty() &&
1487 TypePrinter.NamedTypes.empty())
1492 // We know all the numbers that each type is used and we know that it is a
1493 // dense assignment. Convert the map to an index table.
1494 std::vector<StructType*> NumberedTypes(TypePrinter.NumberedTypes.size());
1495 for (DenseMap<StructType*, unsigned>::iterator I =
1496 TypePrinter.NumberedTypes.begin(), E = TypePrinter.NumberedTypes.end();
1498 assert(I->second < NumberedTypes.size() && "Didn't get a dense numbering?");
1499 NumberedTypes[I->second] = I->first;
1502 // Emit all numbered types.
1503 for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
1504 Out << '%' << i << " = type ";
1506 // Make sure we print out at least one level of the type structure, so
1507 // that we do not get %2 = type %2
1508 TypePrinter.printStructBody(NumberedTypes[i], Out);
1512 for (unsigned i = 0, e = TypePrinter.NamedTypes.size(); i != e; ++i) {
1513 PrintLLVMName(Out, TypePrinter.NamedTypes[i]->getName(), LocalPrefix);
1516 // Make sure we print out at least one level of the type structure, so
1517 // that we do not get %FILE = type %FILE
1518 TypePrinter.printStructBody(TypePrinter.NamedTypes[i], Out);
1523 /// printFunction - Print all aspects of a function.
1525 void AssemblyWriter::printFunction(const Function *F) {
1526 // Print out the return type and name.
1529 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
1531 if (F->isMaterializable())
1532 Out << "; Materializable\n";
1534 const AttributeSet &Attrs = F->getAttributes();
1535 if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
1536 AttributeSet AS = Attrs.getFnAttributes();
1537 std::string AttrStr;
1540 for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx)
1541 if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex)
1544 for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx);
1546 Attribute Attr = *I;
1547 if (!Attr.isStringAttribute()) {
1548 if (!AttrStr.empty()) AttrStr += ' ';
1549 AttrStr += Attr.getAsString();
1553 if (!AttrStr.empty())
1554 Out << "; Function Attrs: " << AttrStr << '\n';
1557 if (F->isDeclaration())
1562 PrintLinkage(F->getLinkage(), Out);
1563 PrintVisibility(F->getVisibility(), Out);
1564 PrintDLLStorageClass(F->getDLLStorageClass(), Out);
1566 // Print the calling convention.
1567 if (F->getCallingConv() != CallingConv::C) {
1568 PrintCallingConv(F->getCallingConv(), Out);
1572 FunctionType *FT = F->getFunctionType();
1573 if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
1574 Out << Attrs.getAsString(AttributeSet::ReturnIndex) << ' ';
1575 TypePrinter.print(F->getReturnType(), Out);
1577 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
1579 Machine.incorporateFunction(F);
1581 // Loop over the arguments, printing them...
1584 if (!F->isDeclaration()) {
1585 // If this isn't a declaration, print the argument names as well.
1586 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
1588 // Insert commas as we go... the first arg doesn't get a comma
1589 if (I != F->arg_begin()) Out << ", ";
1590 printArgument(I, Attrs, Idx);
1594 // Otherwise, print the types from the function type.
1595 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
1596 // Insert commas as we go... the first arg doesn't get a comma
1600 TypePrinter.print(FT->getParamType(i), Out);
1602 if (Attrs.hasAttributes(i+1))
1603 Out << ' ' << Attrs.getAsString(i+1);
1607 // Finish printing arguments...
1608 if (FT->isVarArg()) {
1609 if (FT->getNumParams()) Out << ", ";
1610 Out << "..."; // Output varargs portion of signature!
1613 if (F->hasUnnamedAddr())
1614 Out << " unnamed_addr";
1615 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
1616 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
1617 if (F->hasSection()) {
1618 Out << " section \"";
1619 PrintEscapedString(F->getSection(), Out);
1622 if (F->getAlignment())
1623 Out << " align " << F->getAlignment();
1625 Out << " gc \"" << F->getGC() << '"';
1626 if (F->hasPrefixData()) {
1628 writeOperand(F->getPrefixData(), true);
1630 if (F->isDeclaration()) {
1634 // Output all of the function's basic blocks.
1635 for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
1641 Machine.purgeFunction();
1644 /// printArgument - This member is called for every argument that is passed into
1645 /// the function. Simply print it out
1647 void AssemblyWriter::printArgument(const Argument *Arg,
1648 AttributeSet Attrs, unsigned Idx) {
1650 TypePrinter.print(Arg->getType(), Out);
1652 // Output parameter attributes list
1653 if (Attrs.hasAttributes(Idx))
1654 Out << ' ' << Attrs.getAsString(Idx);
1656 // Output name, if available...
1657 if (Arg->hasName()) {
1659 PrintLLVMName(Out, Arg);
1663 /// printBasicBlock - This member is called for each basic block in a method.
1665 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
1666 if (BB->hasName()) { // Print out the label if it exists...
1668 PrintLLVMName(Out, BB->getName(), LabelPrefix);
1670 } else if (!BB->use_empty()) { // Don't print block # of no uses...
1671 Out << "\n; <label>:";
1672 int Slot = Machine.getLocalSlot(BB);
1679 if (BB->getParent() == 0) {
1680 Out.PadToColumn(50);
1681 Out << "; Error: Block without parent!";
1682 } else if (BB != &BB->getParent()->getEntryBlock()) { // Not the entry block?
1683 // Output predecessors for the block.
1684 Out.PadToColumn(50);
1686 const_pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
1689 Out << " No predecessors!";
1692 writeOperand(*PI, false);
1693 for (++PI; PI != PE; ++PI) {
1695 writeOperand(*PI, false);
1702 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
1704 // Output all of the instructions in the basic block...
1705 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
1706 printInstructionLine(*I);
1709 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
1712 /// printInstructionLine - Print an instruction and a newline character.
1713 void AssemblyWriter::printInstructionLine(const Instruction &I) {
1714 printInstruction(I);
1718 /// printInfoComment - Print a little comment after the instruction indicating
1719 /// which slot it occupies.
1721 void AssemblyWriter::printInfoComment(const Value &V) {
1722 if (AnnotationWriter)
1723 AnnotationWriter->printInfoComment(V, Out);
1726 // This member is called for each Instruction in a function..
1727 void AssemblyWriter::printInstruction(const Instruction &I) {
1728 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
1730 // Print out indentation for an instruction.
1733 // Print out name if it exists...
1735 PrintLLVMName(Out, &I);
1737 } else if (!I.getType()->isVoidTy()) {
1738 // Print out the def slot taken.
1739 int SlotNum = Machine.getLocalSlot(&I);
1741 Out << "<badref> = ";
1743 Out << '%' << SlotNum << " = ";
1746 if (isa<CallInst>(I) && cast<CallInst>(I).isTailCall())
1749 // Print out the opcode...
1750 Out << I.getOpcodeName();
1752 // If this is an atomic load or store, print out the atomic marker.
1753 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isAtomic()) ||
1754 (isa<StoreInst>(I) && cast<StoreInst>(I).isAtomic()))
1757 // If this is a volatile operation, print out the volatile marker.
1758 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) ||
1759 (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile()) ||
1760 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isVolatile()) ||
1761 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).isVolatile()))
1764 // Print out optimization information.
1765 WriteOptimizationInfo(Out, &I);
1767 // Print out the compare instruction predicates
1768 if (const CmpInst *CI = dyn_cast<CmpInst>(&I))
1769 Out << ' ' << getPredicateText(CI->getPredicate());
1771 // Print out the atomicrmw operation
1772 if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
1773 writeAtomicRMWOperation(Out, RMWI->getOperation());
1775 // Print out the type of the operands...
1776 const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0;
1778 // Special case conditional branches to swizzle the condition out to the front
1779 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
1780 const BranchInst &BI(cast<BranchInst>(I));
1782 writeOperand(BI.getCondition(), true);
1784 writeOperand(BI.getSuccessor(0), true);
1786 writeOperand(BI.getSuccessor(1), true);
1788 } else if (isa<SwitchInst>(I)) {
1789 const SwitchInst& SI(cast<SwitchInst>(I));
1790 // Special case switch instruction to get formatting nice and correct.
1792 writeOperand(SI.getCondition(), true);
1794 writeOperand(SI.getDefaultDest(), true);
1796 for (SwitchInst::ConstCaseIt i = SI.case_begin(), e = SI.case_end();
1799 writeOperand(i.getCaseValue(), true);
1801 writeOperand(i.getCaseSuccessor(), true);
1804 } else if (isa<IndirectBrInst>(I)) {
1805 // Special case indirectbr instruction to get formatting nice and correct.
1807 writeOperand(Operand, true);
1810 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
1813 writeOperand(I.getOperand(i), true);
1816 } else if (const PHINode *PN = dyn_cast<PHINode>(&I)) {
1818 TypePrinter.print(I.getType(), Out);
1821 for (unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) {
1822 if (op) Out << ", ";
1824 writeOperand(PN->getIncomingValue(op), false); Out << ", ";
1825 writeOperand(PN->getIncomingBlock(op), false); Out << " ]";
1827 } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) {
1829 writeOperand(I.getOperand(0), true);
1830 for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
1832 } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
1834 writeOperand(I.getOperand(0), true); Out << ", ";
1835 writeOperand(I.getOperand(1), true);
1836 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
1838 } else if (const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
1840 TypePrinter.print(I.getType(), Out);
1841 Out << " personality ";
1842 writeOperand(I.getOperand(0), true); Out << '\n';
1844 if (LPI->isCleanup())
1847 for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
1848 if (i != 0 || LPI->isCleanup()) Out << "\n";
1849 if (LPI->isCatch(i))
1854 writeOperand(LPI->getClause(i), true);
1856 } else if (isa<ReturnInst>(I) && !Operand) {
1858 } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
1859 // Print the calling convention being used.
1860 if (CI->getCallingConv() != CallingConv::C) {
1862 PrintCallingConv(CI->getCallingConv(), Out);
1865 Operand = CI->getCalledValue();
1866 PointerType *PTy = cast<PointerType>(Operand->getType());
1867 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1868 Type *RetTy = FTy->getReturnType();
1869 const AttributeSet &PAL = CI->getAttributes();
1871 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
1872 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
1874 // If possible, print out the short form of the call instruction. We can
1875 // only do this if the first argument is a pointer to a nonvararg function,
1876 // and if the return type is not a pointer to a function.
1879 if (!FTy->isVarArg() &&
1880 (!RetTy->isPointerTy() ||
1881 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1882 TypePrinter.print(RetTy, Out);
1884 writeOperand(Operand, false);
1886 writeOperand(Operand, true);
1889 for (unsigned op = 0, Eop = CI->getNumArgOperands(); op < Eop; ++op) {
1892 writeParamOperand(CI->getArgOperand(op), PAL, op + 1);
1895 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
1896 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
1897 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
1898 Operand = II->getCalledValue();
1899 PointerType *PTy = cast<PointerType>(Operand->getType());
1900 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1901 Type *RetTy = FTy->getReturnType();
1902 const AttributeSet &PAL = II->getAttributes();
1904 // Print the calling convention being used.
1905 if (II->getCallingConv() != CallingConv::C) {
1907 PrintCallingConv(II->getCallingConv(), Out);
1910 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
1911 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
1913 // If possible, print out the short form of the invoke instruction. We can
1914 // only do this if the first argument is a pointer to a nonvararg function,
1915 // and if the return type is not a pointer to a function.
1918 if (!FTy->isVarArg() &&
1919 (!RetTy->isPointerTy() ||
1920 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1921 TypePrinter.print(RetTy, Out);
1923 writeOperand(Operand, false);
1925 writeOperand(Operand, true);
1928 for (unsigned op = 0, Eop = II->getNumArgOperands(); op < Eop; ++op) {
1931 writeParamOperand(II->getArgOperand(op), PAL, op + 1);
1935 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
1936 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
1939 writeOperand(II->getNormalDest(), true);
1941 writeOperand(II->getUnwindDest(), true);
1943 } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
1945 TypePrinter.print(AI->getAllocatedType(), Out);
1946 if (!AI->getArraySize() || AI->isArrayAllocation()) {
1948 writeOperand(AI->getArraySize(), true);
1950 if (AI->getAlignment()) {
1951 Out << ", align " << AI->getAlignment();
1953 } else if (isa<CastInst>(I)) {
1956 writeOperand(Operand, true); // Work with broken code
1959 TypePrinter.print(I.getType(), Out);
1960 } else if (isa<VAArgInst>(I)) {
1963 writeOperand(Operand, true); // Work with broken code
1966 TypePrinter.print(I.getType(), Out);
1967 } else if (Operand) { // Print the normal way.
1969 // PrintAllTypes - Instructions who have operands of all the same type
1970 // omit the type from all but the first operand. If the instruction has
1971 // different type operands (for example br), then they are all printed.
1972 bool PrintAllTypes = false;
1973 Type *TheType = Operand->getType();
1975 // Select, Store and ShuffleVector always print all types.
1976 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
1977 || isa<ReturnInst>(I)) {
1978 PrintAllTypes = true;
1980 for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
1981 Operand = I.getOperand(i);
1982 // note that Operand shouldn't be null, but the test helps make dump()
1983 // more tolerant of malformed IR
1984 if (Operand && Operand->getType() != TheType) {
1985 PrintAllTypes = true; // We have differing types! Print them all!
1991 if (!PrintAllTypes) {
1993 TypePrinter.print(TheType, Out);
1997 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {
1999 writeOperand(I.getOperand(i), PrintAllTypes);
2003 // Print atomic ordering/alignment for memory operations
2004 if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
2006 writeAtomic(LI->getOrdering(), LI->getSynchScope());
2007 if (LI->getAlignment())
2008 Out << ", align " << LI->getAlignment();
2009 } else if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
2011 writeAtomic(SI->getOrdering(), SI->getSynchScope());
2012 if (SI->getAlignment())
2013 Out << ", align " << SI->getAlignment();
2014 } else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) {
2015 writeAtomic(CXI->getOrdering(), CXI->getSynchScope());
2016 } else if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
2017 writeAtomic(RMWI->getOrdering(), RMWI->getSynchScope());
2018 } else if (const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
2019 writeAtomic(FI->getOrdering(), FI->getSynchScope());
2022 // Print Metadata info.
2023 SmallVector<std::pair<unsigned, MDNode*>, 4> InstMD;
2024 I.getAllMetadata(InstMD);
2025 if (!InstMD.empty()) {
2026 SmallVector<StringRef, 8> MDNames;
2027 I.getType()->getContext().getMDKindNames(MDNames);
2028 for (unsigned i = 0, e = InstMD.size(); i != e; ++i) {
2029 unsigned Kind = InstMD[i].first;
2030 if (Kind < MDNames.size()) {
2031 Out << ", !" << MDNames[Kind];
2033 Out << ", !<unknown kind #" << Kind << ">";
2036 WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
2040 printInfoComment(I);
2043 static void WriteMDNodeComment(const MDNode *Node,
2044 formatted_raw_ostream &Out) {
2045 if (Node->getNumOperands() < 1)
2048 Value *Op = Node->getOperand(0);
2049 if (!Op || !isa<ConstantInt>(Op) || cast<ConstantInt>(Op)->getBitWidth() < 32)
2052 DIDescriptor Desc(Node);
2056 unsigned Tag = Desc.getTag();
2057 Out.PadToColumn(50);
2058 if (dwarf::TagString(Tag)) {
2061 } else if (Tag == dwarf::DW_TAG_user_base) {
2062 Out << "; [ DW_TAG_user_base ]";
2066 void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
2067 Out << '!' << Slot << " = metadata ";
2068 printMDNodeBody(Node);
2071 void AssemblyWriter::writeAllMDNodes() {
2072 SmallVector<const MDNode *, 16> Nodes;
2073 Nodes.resize(Machine.mdn_size());
2074 for (SlotTracker::mdn_iterator I = Machine.mdn_begin(), E = Machine.mdn_end();
2076 Nodes[I->second] = cast<MDNode>(I->first);
2078 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
2079 writeMDNode(i, Nodes[i]);
2083 void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
2084 WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule);
2085 WriteMDNodeComment(Node, Out);
2089 void AssemblyWriter::writeAllAttributeGroups() {
2090 std::vector<std::pair<AttributeSet, unsigned> > asVec;
2091 asVec.resize(Machine.as_size());
2093 for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end();
2095 asVec[I->second] = *I;
2097 for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
2098 I = asVec.begin(), E = asVec.end(); I != E; ++I)
2099 Out << "attributes #" << I->second << " = { "
2100 << I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
2105 //===----------------------------------------------------------------------===//
2106 // External Interface declarations
2107 //===----------------------------------------------------------------------===//
2109 void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2110 SlotTracker SlotTable(this);
2111 formatted_raw_ostream OS(ROS);
2112 AssemblyWriter W(OS, SlotTable, this, AAW);
2113 W.printModule(this);
2116 void NamedMDNode::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2117 SlotTracker SlotTable(getParent());
2118 formatted_raw_ostream OS(ROS);
2119 AssemblyWriter W(OS, SlotTable, getParent(), AAW);
2120 W.printNamedMDNode(this);
2123 void Type::print(raw_ostream &OS) const {
2125 OS << "<null Type>";
2129 TP.print(const_cast<Type*>(this), OS);
2131 // If the type is a named struct type, print the body as well.
2132 if (StructType *STy = dyn_cast<StructType>(const_cast<Type*>(this)))
2133 if (!STy->isLiteral()) {
2135 TP.printStructBody(STy, OS);
2139 void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2141 ROS << "printing a <null> value\n";
2144 formatted_raw_ostream OS(ROS);
2145 if (const Instruction *I = dyn_cast<Instruction>(this)) {
2146 const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
2147 SlotTracker SlotTable(F);
2148 AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), AAW);
2149 W.printInstruction(*I);
2150 } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
2151 SlotTracker SlotTable(BB->getParent());
2152 AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), AAW);
2153 W.printBasicBlock(BB);
2154 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
2155 SlotTracker SlotTable(GV->getParent());
2156 AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
2157 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
2159 else if (const Function *F = dyn_cast<Function>(GV))
2162 W.printAlias(cast<GlobalAlias>(GV));
2163 } else if (const MDNode *N = dyn_cast<MDNode>(this)) {
2164 const Function *F = N->getFunction();
2165 SlotTracker SlotTable(F);
2166 AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
2167 W.printMDNodeBody(N);
2168 } else if (const Constant *C = dyn_cast<Constant>(this)) {
2169 TypePrinting TypePrinter;
2170 TypePrinter.print(C->getType(), OS);
2172 WriteConstantInternal(OS, C, TypePrinter, 0, 0);
2173 } else if (isa<InlineAsm>(this) || isa<MDString>(this) ||
2174 isa<Argument>(this)) {
2175 this->printAsOperand(OS);
2177 // Otherwise we don't know what it is. Call the virtual function to
2178 // allow a subclass to print itself.
2183 void Value::printAsOperand(raw_ostream &O, bool PrintType, const Module *M) const {
2184 // Fast path: Don't construct and populate a TypePrinting object if we
2185 // won't be needing any types printed.
2187 ((!isa<Constant>(this) && !isa<MDNode>(this)) ||
2188 hasName() || isa<GlobalValue>(this))) {
2189 WriteAsOperandInternal(O, this, 0, 0, M);
2194 M = getModuleFromVal(this);
2196 TypePrinting TypePrinter;
2198 TypePrinter.incorporateTypes(*M);
2200 TypePrinter.print(getType(), O);
2204 WriteAsOperandInternal(O, this, &TypePrinter, 0, M);
2207 // Value::printCustom - subclasses should override this to implement printing.
2208 void Value::printCustom(raw_ostream &OS) const {
2209 llvm_unreachable("Unknown value to print out!");
2212 // Value::dump - allow easy printing of Values from the debugger.
2213 void Value::dump() const { print(dbgs()); dbgs() << '\n'; }
2215 // Type::dump - allow easy printing of Types from the debugger.
2216 void Type::dump() const { print(dbgs()); }
2218 // Module::dump() - Allow printing of Modules from the debugger.
2219 void Module::dump() const { print(dbgs(), 0); }
2221 // NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger.
2222 void NamedMDNode::dump() const { print(dbgs(), 0); }