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/Assembly/PrintModulePass.h"
19 #include "llvm/Assembly/AsmAnnotationWriter.h"
20 #include "llvm/CallingConv.h"
21 #include "llvm/Constants.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/InlineAsm.h"
24 #include "llvm/Instruction.h"
25 #include "llvm/Instructions.h"
26 #include "llvm/LLVMContext.h"
27 #include "llvm/Operator.h"
28 #include "llvm/Metadata.h"
29 #include "llvm/Module.h"
30 #include "llvm/ValueSymbolTable.h"
31 #include "llvm/TypeSymbolTable.h"
32 #include "llvm/ADT/DenseSet.h"
33 #include "llvm/ADT/StringExtras.h"
34 #include "llvm/ADT/STLExtras.h"
35 #include "llvm/Support/CFG.h"
36 #include "llvm/Support/Dwarf.h"
37 #include "llvm/Support/ErrorHandling.h"
38 #include "llvm/Support/MathExtras.h"
39 #include "llvm/Support/FormattedStream.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 // PrintEscapedString - Print each character of the specified string, escaping
70 // it if it is not printable or if it is an escape char.
71 static void PrintEscapedString(const StringRef &Name,
73 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
74 unsigned char C = Name[i];
75 if (isprint(C) && C != '\\' && C != '"')
78 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
89 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
90 /// prefixed with % (if the string only contains simple characters) or is
91 /// surrounded with ""'s (if it has special chars in it). Print it out.
92 static void PrintLLVMName(raw_ostream &OS, const StringRef &Name,
94 assert(Name.data() && "Cannot get empty name!");
96 default: llvm_unreachable("Bad prefix!");
98 case GlobalPrefix: OS << '@'; break;
99 case LabelPrefix: break;
100 case LocalPrefix: OS << '%'; break;
103 // Scan the name to see if it needs quotes first.
104 bool NeedsQuotes = isdigit(Name[0]);
106 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
108 if (!isalnum(C) && C != '-' && C != '.' && C != '_') {
115 // If we didn't need any quotes, just write out the name in one blast.
121 // Okay, we need quotes. Output the quotes and escape any scary characters as
124 PrintEscapedString(Name, OS);
128 /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
129 /// prefixed with % (if the string only contains simple characters) or is
130 /// surrounded with ""'s (if it has special chars in it). Print it out.
131 static void PrintLLVMName(raw_ostream &OS, const Value *V) {
132 PrintLLVMName(OS, V->getName(),
133 isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
136 //===----------------------------------------------------------------------===//
137 // TypePrinting Class: Type printing machinery
138 //===----------------------------------------------------------------------===//
140 static DenseMap<const Type *, std::string> &getTypeNamesMap(void *M) {
141 return *static_cast<DenseMap<const Type *, std::string>*>(M);
144 void TypePrinting::clear() {
145 getTypeNamesMap(TypeNames).clear();
148 bool TypePrinting::hasTypeName(const Type *Ty) const {
149 return getTypeNamesMap(TypeNames).count(Ty);
152 void TypePrinting::addTypeName(const Type *Ty, const std::string &N) {
153 getTypeNamesMap(TypeNames).insert(std::make_pair(Ty, N));
157 TypePrinting::TypePrinting() {
158 TypeNames = new DenseMap<const Type *, std::string>();
161 TypePrinting::~TypePrinting() {
162 delete &getTypeNamesMap(TypeNames);
165 /// CalcTypeName - Write the specified type to the specified raw_ostream, making
166 /// use of type names or up references to shorten the type name where possible.
167 void TypePrinting::CalcTypeName(const Type *Ty,
168 SmallVectorImpl<const Type *> &TypeStack,
169 raw_ostream &OS, bool IgnoreTopLevelName) {
170 // Check to see if the type is named.
171 if (!IgnoreTopLevelName) {
172 DenseMap<const Type *, std::string> &TM = getTypeNamesMap(TypeNames);
173 DenseMap<const Type *, std::string>::iterator I = TM.find(Ty);
180 // Check to see if the Type is already on the stack...
181 unsigned Slot = 0, CurSize = TypeStack.size();
182 while (Slot < CurSize && TypeStack[Slot] != Ty) ++Slot; // Scan for type
184 // This is another base case for the recursion. In this case, we know
185 // that we have looped back to a type that we have previously visited.
186 // Generate the appropriate upreference to handle this.
187 if (Slot < CurSize) {
188 OS << '\\' << unsigned(CurSize-Slot); // Here's the upreference
192 TypeStack.push_back(Ty); // Recursive case: Add us to the stack..
194 switch (Ty->getTypeID()) {
195 case Type::VoidTyID: OS << "void"; break;
196 case Type::FloatTyID: OS << "float"; break;
197 case Type::DoubleTyID: OS << "double"; break;
198 case Type::X86_FP80TyID: OS << "x86_fp80"; break;
199 case Type::FP128TyID: OS << "fp128"; break;
200 case Type::PPC_FP128TyID: OS << "ppc_fp128"; break;
201 case Type::LabelTyID: OS << "label"; break;
202 case Type::MetadataTyID: OS << "metadata"; break;
203 case Type::IntegerTyID:
204 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
207 case Type::FunctionTyID: {
208 const FunctionType *FTy = cast<FunctionType>(Ty);
209 CalcTypeName(FTy->getReturnType(), TypeStack, OS);
211 for (FunctionType::param_iterator I = FTy->param_begin(),
212 E = FTy->param_end(); I != E; ++I) {
213 if (I != FTy->param_begin())
215 CalcTypeName(*I, TypeStack, OS);
217 if (FTy->isVarArg()) {
218 if (FTy->getNumParams()) OS << ", ";
224 case Type::StructTyID: {
225 const StructType *STy = cast<StructType>(Ty);
229 for (StructType::element_iterator I = STy->element_begin(),
230 E = STy->element_end(); I != E; ++I) {
231 CalcTypeName(*I, TypeStack, OS);
232 if (next(I) != STy->element_end())
241 case Type::PointerTyID: {
242 const PointerType *PTy = cast<PointerType>(Ty);
243 CalcTypeName(PTy->getElementType(), TypeStack, OS);
244 if (unsigned AddressSpace = PTy->getAddressSpace())
245 OS << " addrspace(" << AddressSpace << ')';
249 case Type::ArrayTyID: {
250 const ArrayType *ATy = cast<ArrayType>(Ty);
251 OS << '[' << ATy->getNumElements() << " x ";
252 CalcTypeName(ATy->getElementType(), TypeStack, OS);
256 case Type::VectorTyID: {
257 const VectorType *PTy = cast<VectorType>(Ty);
258 OS << "<" << PTy->getNumElements() << " x ";
259 CalcTypeName(PTy->getElementType(), TypeStack, OS);
263 case Type::OpaqueTyID:
267 OS << "<unrecognized-type>";
271 TypeStack.pop_back(); // Remove self from stack.
274 /// printTypeInt - The internal guts of printing out a type that has a
275 /// potentially named portion.
277 void TypePrinting::print(const Type *Ty, raw_ostream &OS,
278 bool IgnoreTopLevelName) {
279 // Check to see if the type is named.
280 DenseMap<const Type*, std::string> &TM = getTypeNamesMap(TypeNames);
281 if (!IgnoreTopLevelName) {
282 DenseMap<const Type*, std::string>::iterator I = TM.find(Ty);
289 // Otherwise we have a type that has not been named but is a derived type.
290 // Carefully recurse the type hierarchy to print out any contained symbolic
292 SmallVector<const Type *, 16> TypeStack;
293 std::string TypeName;
295 raw_string_ostream TypeOS(TypeName);
296 CalcTypeName(Ty, TypeStack, TypeOS, IgnoreTopLevelName);
299 // Cache type name for later use.
300 if (!IgnoreTopLevelName)
301 TM.insert(std::make_pair(Ty, TypeOS.str()));
306 // To avoid walking constant expressions multiple times and other IR
307 // objects, we keep several helper maps.
308 DenseSet<const Value*> VisitedConstants;
309 DenseSet<const Type*> VisitedTypes;
312 std::vector<const Type*> &NumberedTypes;
314 TypeFinder(TypePrinting &tp, std::vector<const Type*> &numberedTypes)
315 : TP(tp), NumberedTypes(numberedTypes) {}
317 void Run(const Module &M) {
318 // Get types from the type symbol table. This gets opaque types referened
319 // only through derived named types.
320 const TypeSymbolTable &ST = M.getTypeSymbolTable();
321 for (TypeSymbolTable::const_iterator TI = ST.begin(), E = ST.end();
323 IncorporateType(TI->second);
325 // Get types from global variables.
326 for (Module::const_global_iterator I = M.global_begin(),
327 E = M.global_end(); I != E; ++I) {
328 IncorporateType(I->getType());
329 if (I->hasInitializer())
330 IncorporateValue(I->getInitializer());
333 // Get types from aliases.
334 for (Module::const_alias_iterator I = M.alias_begin(),
335 E = M.alias_end(); I != E; ++I) {
336 IncorporateType(I->getType());
337 IncorporateValue(I->getAliasee());
340 // Get types from functions.
341 for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
342 IncorporateType(FI->getType());
344 for (Function::const_iterator BB = FI->begin(), E = FI->end();
346 for (BasicBlock::const_iterator II = BB->begin(),
347 E = BB->end(); II != E; ++II) {
348 const Instruction &I = *II;
349 // Incorporate the type of the instruction and all its operands.
350 IncorporateType(I.getType());
351 for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
353 IncorporateValue(*OI);
359 void IncorporateType(const Type *Ty) {
360 // Check to see if we're already visited this type.
361 if (!VisitedTypes.insert(Ty).second)
364 // If this is a structure or opaque type, add a name for the type.
365 if (((isa<StructType>(Ty) && cast<StructType>(Ty)->getNumElements())
366 || isa<OpaqueType>(Ty)) && !TP.hasTypeName(Ty)) {
367 TP.addTypeName(Ty, "%"+utostr(unsigned(NumberedTypes.size())));
368 NumberedTypes.push_back(Ty);
371 // Recursively walk all contained types.
372 for (Type::subtype_iterator I = Ty->subtype_begin(),
373 E = Ty->subtype_end(); I != E; ++I)
377 /// IncorporateValue - This method is used to walk operand lists finding
378 /// types hiding in constant expressions and other operands that won't be
379 /// walked in other ways. GlobalValues, basic blocks, instructions, and
380 /// inst operands are all explicitly enumerated.
381 void IncorporateValue(const Value *V) {
382 if (V == 0 || !isa<Constant>(V) || isa<GlobalValue>(V)) return;
385 if (!VisitedConstants.insert(V).second)
389 IncorporateType(V->getType());
391 // Look in operands for types.
392 const Constant *C = cast<Constant>(V);
393 for (Constant::const_op_iterator I = C->op_begin(),
394 E = C->op_end(); I != E;++I)
395 IncorporateValue(*I);
398 } // end anonymous namespace
401 /// AddModuleTypesToPrinter - Add all of the symbolic type names for types in
402 /// the specified module to the TypePrinter and all numbered types to it and the
403 /// NumberedTypes table.
404 static void AddModuleTypesToPrinter(TypePrinting &TP,
405 std::vector<const Type*> &NumberedTypes,
409 // If the module has a symbol table, take all global types and stuff their
410 // names into the TypeNames map.
411 const TypeSymbolTable &ST = M->getTypeSymbolTable();
412 for (TypeSymbolTable::const_iterator TI = ST.begin(), E = ST.end();
414 const Type *Ty = cast<Type>(TI->second);
416 // As a heuristic, don't insert pointer to primitive types, because
417 // they are used too often to have a single useful name.
418 if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
419 const Type *PETy = PTy->getElementType();
420 if ((PETy->isPrimitiveType() || PETy->isInteger()) &&
421 !isa<OpaqueType>(PETy))
425 // Likewise don't insert primitives either.
426 if (Ty->isInteger() || Ty->isPrimitiveType())
429 // Get the name as a string and insert it into TypeNames.
431 raw_string_ostream NameROS(NameStr);
432 formatted_raw_ostream NameOS(NameROS);
433 PrintLLVMName(NameOS, TI->first, LocalPrefix);
435 TP.addTypeName(Ty, NameStr);
438 // Walk the entire module to find references to unnamed structure and opaque
439 // types. This is required for correctness by opaque types (because multiple
440 // uses of an unnamed opaque type needs to be referred to by the same ID) and
441 // it shrinks complex recursive structure types substantially in some cases.
442 TypeFinder(TP, NumberedTypes).Run(*M);
446 /// WriteTypeSymbolic - This attempts to write the specified type as a symbolic
447 /// type, iff there is an entry in the modules symbol table for the specified
448 /// type or one of it's component types.
450 void llvm::WriteTypeSymbolic(raw_ostream &OS, const Type *Ty, const Module *M) {
451 TypePrinting Printer;
452 std::vector<const Type*> NumberedTypes;
453 AddModuleTypesToPrinter(Printer, NumberedTypes, M);
454 Printer.print(Ty, OS);
457 //===----------------------------------------------------------------------===//
458 // SlotTracker Class: Enumerate slot numbers for unnamed values
459 //===----------------------------------------------------------------------===//
463 /// This class provides computation of slot numbers for LLVM Assembly writing.
467 /// ValueMap - A mapping of Values to slot numbers.
468 typedef DenseMap<const Value*, unsigned> ValueMap;
471 /// TheModule - The module for which we are holding slot numbers.
472 const Module* TheModule;
474 /// TheFunction - The function for which we are holding slot numbers.
475 const Function* TheFunction;
476 bool FunctionProcessed;
478 /// TheMDNode - The MDNode for which we are holding slot numbers.
479 const MDNode *TheMDNode;
481 /// TheNamedMDNode - The MDNode for which we are holding slot numbers.
482 const NamedMDNode *TheNamedMDNode;
484 /// mMap - The TypePlanes map for the module level data.
488 /// fMap - The TypePlanes map for the function level data.
492 /// mdnMap - Map for MDNodes.
496 /// Construct from a module
497 explicit SlotTracker(const Module *M);
498 /// Construct from a function, starting out in incorp state.
499 explicit SlotTracker(const Function *F);
500 /// Construct from a mdnode.
501 explicit SlotTracker(const MDNode *N);
502 /// Construct from a named mdnode.
503 explicit SlotTracker(const NamedMDNode *N);
505 /// Return the slot number of the specified value in it's type
506 /// plane. If something is not in the SlotTracker, return -1.
507 int getLocalSlot(const Value *V);
508 int getGlobalSlot(const GlobalValue *V);
509 int getMetadataSlot(const MDNode *N);
511 /// If you'd like to deal with a function instead of just a module, use
512 /// this method to get its data into the SlotTracker.
513 void incorporateFunction(const Function *F) {
515 FunctionProcessed = false;
518 /// After calling incorporateFunction, use this method to remove the
519 /// most recently incorporated function from the SlotTracker. This
520 /// will reset the state of the machine back to just the module contents.
521 void purgeFunction();
523 /// MDNode map iterators.
524 ValueMap::iterator mdnBegin() { return mdnMap.begin(); }
525 ValueMap::iterator mdnEnd() { return mdnMap.end(); }
526 unsigned mdnSize() const { return mdnMap.size(); }
527 bool mdnEmpty() const { return mdnMap.empty(); }
529 /// This function does the actual initialization.
530 inline void initialize();
532 // Implementation Details
534 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
535 void CreateModuleSlot(const GlobalValue *V);
537 /// CreateMetadataSlot - Insert the specified MDNode* into the slot table.
538 void CreateMetadataSlot(const MDNode *N);
540 /// CreateFunctionSlot - Insert the specified Value* into the slot table.
541 void CreateFunctionSlot(const Value *V);
543 /// Add all of the module level global variables (and their initializers)
544 /// and function declarations, but not the contents of those functions.
545 void processModule();
547 /// Add all of the functions arguments, basic blocks, and instructions.
548 void processFunction();
550 /// Add all MDNode operands.
551 void processMDNode();
553 /// Add all MDNode operands.
554 void processNamedMDNode();
556 SlotTracker(const SlotTracker &); // DO NOT IMPLEMENT
557 void operator=(const SlotTracker &); // DO NOT IMPLEMENT
560 } // end anonymous namespace
563 static SlotTracker *createSlotTracker(const Value *V) {
564 if (const Argument *FA = dyn_cast<Argument>(V))
565 return new SlotTracker(FA->getParent());
567 if (const Instruction *I = dyn_cast<Instruction>(V))
568 return new SlotTracker(I->getParent()->getParent());
570 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
571 return new SlotTracker(BB->getParent());
573 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
574 return new SlotTracker(GV->getParent());
576 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
577 return new SlotTracker(GA->getParent());
579 if (const Function *Func = dyn_cast<Function>(V))
580 return new SlotTracker(Func);
586 #define ST_DEBUG(X) errs() << X
591 // Module level constructor. Causes the contents of the Module (sans functions)
592 // to be added to the slot table.
593 SlotTracker::SlotTracker(const Module *M)
594 : TheModule(M), TheFunction(0), FunctionProcessed(false), TheMDNode(0),
595 TheNamedMDNode(0), mNext(0), fNext(0), mdnNext(0) {
598 // Function level constructor. Causes the contents of the Module and the one
599 // function provided to be added to the slot table.
600 SlotTracker::SlotTracker(const Function *F)
601 : TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false),
602 TheMDNode(0), TheNamedMDNode(0), mNext(0), fNext(0), mdnNext(0) {
605 // Constructor to handle single MDNode.
606 SlotTracker::SlotTracker(const MDNode *C)
607 : TheModule(0), TheFunction(0), FunctionProcessed(false), TheMDNode(C),
608 TheNamedMDNode(0), mNext(0), fNext(0), mdnNext(0) {
611 // Constructor to handle single NamedMDNode.
612 SlotTracker::SlotTracker(const NamedMDNode *N)
613 : TheModule(0), TheFunction(0), FunctionProcessed(false), TheMDNode(0),
614 TheNamedMDNode(N), mNext(0), fNext(0), mdnNext(0) {
617 inline void SlotTracker::initialize() {
620 TheModule = 0; ///< Prevent re-processing next time we're called.
623 if (TheFunction && !FunctionProcessed)
630 processNamedMDNode();
633 // Iterate through all the global variables, functions, and global
634 // variable initializers and create slots for them.
635 void SlotTracker::processModule() {
636 ST_DEBUG("begin processModule!\n");
638 // Add all of the unnamed global variables to the value table.
639 for (Module::const_global_iterator I = TheModule->global_begin(),
640 E = TheModule->global_end(); I != E; ++I) {
643 if (I->hasInitializer()) {
644 if (MDNode *N = dyn_cast<MDNode>(I->getInitializer()))
645 CreateMetadataSlot(N);
649 // Add metadata used by named metadata.
650 for (Module::const_named_metadata_iterator
651 I = TheModule->named_metadata_begin(),
652 E = TheModule->named_metadata_end(); I != E; ++I) {
653 const NamedMDNode *NMD = I;
654 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
655 MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getElement(i));
657 CreateMetadataSlot(MD);
661 // Add all the unnamed functions to the table.
662 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
667 ST_DEBUG("end processModule!\n");
670 // Process the arguments, basic blocks, and instructions of a function.
671 void SlotTracker::processFunction() {
672 ST_DEBUG("begin processFunction!\n");
675 // Add all the function arguments with no names.
676 for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
677 AE = TheFunction->arg_end(); AI != AE; ++AI)
679 CreateFunctionSlot(AI);
681 ST_DEBUG("Inserting Instructions:\n");
683 MetadataContext &TheMetadata = TheFunction->getContext().getMetadata();
684 typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
687 // Add all of the basic blocks and instructions with no names.
688 for (Function::const_iterator BB = TheFunction->begin(),
689 E = TheFunction->end(); BB != E; ++BB) {
691 CreateFunctionSlot(BB);
692 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
694 if (I->getType() != Type::getVoidTy(TheFunction->getContext()) &&
696 CreateFunctionSlot(I);
697 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
698 if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
699 CreateMetadataSlot(N);
701 // Process metadata attached with this instruction.
703 TheMetadata.getMDs(I, MDs);
704 for (MDMapTy::const_iterator MI = MDs.begin(), ME = MDs.end(); MI != ME;
706 CreateMetadataSlot(MI->second);
710 FunctionProcessed = true;
712 ST_DEBUG("end processFunction!\n");
715 /// processMDNode - Process TheMDNode.
716 void SlotTracker::processMDNode() {
717 ST_DEBUG("begin processMDNode!\n");
719 CreateMetadataSlot(TheMDNode);
721 ST_DEBUG("end processMDNode!\n");
724 /// processNamedMDNode - Process TheNamedMDNode.
725 void SlotTracker::processNamedMDNode() {
726 ST_DEBUG("begin processNamedMDNode!\n");
728 for (unsigned i = 0, e = TheNamedMDNode->getNumElements(); i != e; ++i) {
729 MDNode *MD = dyn_cast_or_null<MDNode>(TheNamedMDNode->getElement(i));
731 CreateMetadataSlot(MD);
734 ST_DEBUG("end processNamedMDNode!\n");
737 /// Clean up after incorporating a function. This is the only way to get out of
738 /// the function incorporation state that affects get*Slot/Create*Slot. Function
739 /// incorporation state is indicated by TheFunction != 0.
740 void SlotTracker::purgeFunction() {
741 ST_DEBUG("begin purgeFunction!\n");
742 fMap.clear(); // Simply discard the function level map
744 FunctionProcessed = false;
745 ST_DEBUG("end purgeFunction!\n");
748 /// getGlobalSlot - Get the slot number of a global value.
749 int SlotTracker::getGlobalSlot(const GlobalValue *V) {
750 // Check for uninitialized state and do lazy initialization.
753 // Find the type plane in the module map
754 ValueMap::iterator MI = mMap.find(V);
755 return MI == mMap.end() ? -1 : (int)MI->second;
758 /// getGlobalSlot - Get the slot number of a MDNode.
759 int SlotTracker::getMetadataSlot(const MDNode *N) {
760 // Check for uninitialized state and do lazy initialization.
763 // Find the type plane in the module map
764 ValueMap::iterator MI = mdnMap.find(N);
765 return MI == mdnMap.end() ? -1 : (int)MI->second;
769 /// getLocalSlot - Get the slot number for a value that is local to a function.
770 int SlotTracker::getLocalSlot(const Value *V) {
771 assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!");
773 // Check for uninitialized state and do lazy initialization.
776 ValueMap::iterator FI = fMap.find(V);
777 return FI == fMap.end() ? -1 : (int)FI->second;
781 /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
782 void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
783 assert(V && "Can't insert a null Value into SlotTracker!");
784 assert(V->getType() != Type::getVoidTy(V->getContext()) &&
785 "Doesn't need a slot!");
786 assert(!V->hasName() && "Doesn't need a slot!");
788 unsigned DestSlot = mNext++;
791 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
793 // G = Global, F = Function, A = Alias, o = other
794 ST_DEBUG((isa<GlobalVariable>(V) ? 'G' :
795 (isa<Function>(V) ? 'F' :
796 (isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n");
799 /// CreateSlot - Create a new slot for the specified value if it has no name.
800 void SlotTracker::CreateFunctionSlot(const Value *V) {
801 assert(V->getType() != Type::getVoidTy(TheFunction->getContext()) &&
802 !V->hasName() && "Doesn't need a slot!");
804 unsigned DestSlot = fNext++;
807 // G = Global, F = Function, o = other
808 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
809 DestSlot << " [o]\n");
812 /// CreateModuleSlot - Insert the specified MDNode* into the slot table.
813 void SlotTracker::CreateMetadataSlot(const MDNode *N) {
814 assert(N && "Can't insert a null Value into SlotTracker!");
816 // Don't insert if N is a function-local metadata.
817 if (N->isFunctionLocal())
820 ValueMap::iterator I = mdnMap.find(N);
821 if (I != mdnMap.end())
824 unsigned DestSlot = mdnNext++;
825 mdnMap[N] = DestSlot;
827 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
828 const Value *TV = N->getElement(i);
830 if (const MDNode *N2 = dyn_cast<MDNode>(TV))
831 CreateMetadataSlot(N2);
835 //===----------------------------------------------------------------------===//
836 // AsmWriter Implementation
837 //===----------------------------------------------------------------------===//
839 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
840 TypePrinting *TypePrinter,
841 SlotTracker *Machine);
845 static const char *getPredicateText(unsigned predicate) {
846 const char * pred = "unknown";
848 case FCmpInst::FCMP_FALSE: pred = "false"; break;
849 case FCmpInst::FCMP_OEQ: pred = "oeq"; break;
850 case FCmpInst::FCMP_OGT: pred = "ogt"; break;
851 case FCmpInst::FCMP_OGE: pred = "oge"; break;
852 case FCmpInst::FCMP_OLT: pred = "olt"; break;
853 case FCmpInst::FCMP_OLE: pred = "ole"; break;
854 case FCmpInst::FCMP_ONE: pred = "one"; break;
855 case FCmpInst::FCMP_ORD: pred = "ord"; break;
856 case FCmpInst::FCMP_UNO: pred = "uno"; break;
857 case FCmpInst::FCMP_UEQ: pred = "ueq"; break;
858 case FCmpInst::FCMP_UGT: pred = "ugt"; break;
859 case FCmpInst::FCMP_UGE: pred = "uge"; break;
860 case FCmpInst::FCMP_ULT: pred = "ult"; break;
861 case FCmpInst::FCMP_ULE: pred = "ule"; break;
862 case FCmpInst::FCMP_UNE: pred = "une"; break;
863 case FCmpInst::FCMP_TRUE: pred = "true"; break;
864 case ICmpInst::ICMP_EQ: pred = "eq"; break;
865 case ICmpInst::ICMP_NE: pred = "ne"; break;
866 case ICmpInst::ICMP_SGT: pred = "sgt"; break;
867 case ICmpInst::ICMP_SGE: pred = "sge"; break;
868 case ICmpInst::ICMP_SLT: pred = "slt"; break;
869 case ICmpInst::ICMP_SLE: pred = "sle"; break;
870 case ICmpInst::ICMP_UGT: pred = "ugt"; break;
871 case ICmpInst::ICMP_UGE: pred = "uge"; break;
872 case ICmpInst::ICMP_ULT: pred = "ult"; break;
873 case ICmpInst::ICMP_ULE: pred = "ule"; break;
878 static void WriteMDNodeComment(const MDNode *Node,
879 formatted_raw_ostream &Out) {
880 if (Node->getNumElements() < 1)
882 ConstantInt *CI = dyn_cast_or_null<ConstantInt>(Node->getElement(0));
884 unsigned Val = CI->getZExtValue();
885 unsigned Tag = Val & ~LLVMDebugVersionMask;
886 if (Val >= LLVMDebugVersion) {
887 if (Tag == dwarf::DW_TAG_auto_variable)
888 Out << "; [ DW_TAG_auto_variable ]";
889 else if (Tag == dwarf::DW_TAG_arg_variable)
890 Out << "; [ DW_TAG_arg_variable ]";
891 else if (Tag == dwarf::DW_TAG_return_variable)
892 Out << "; [ DW_TAG_return_variable ]";
893 else if (Tag == dwarf::DW_TAG_vector_type)
894 Out << "; [ DW_TAG_vector_type ]";
895 else if (Tag == dwarf::DW_TAG_user_base)
896 Out << "; [ DW_TAG_user_base ]";
898 Out << "; [" << dwarf::TagString(Tag) << " ]";
902 static void WriteMDNodes(formatted_raw_ostream &Out, TypePrinting &TypePrinter,
903 SlotTracker &Machine) {
904 SmallVector<const MDNode *, 16> Nodes;
905 Nodes.resize(Machine.mdnSize());
906 for (SlotTracker::ValueMap::iterator I =
907 Machine.mdnBegin(), E = Machine.mdnEnd(); I != E; ++I)
908 Nodes[I->second] = cast<MDNode>(I->first);
910 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
911 Out << '!' << i << " = metadata ";
912 const MDNode *Node = Nodes[i];
914 for (unsigned mi = 0, me = Node->getNumElements(); mi != me; ++mi) {
915 const Value *V = Node->getElement(mi);
918 else if (const MDNode *N = dyn_cast<MDNode>(V)) {
920 Out << '!' << Machine.getMetadataSlot(N);
923 TypePrinter.print(V->getType(), Out);
925 WriteAsOperandInternal(Out, Node->getElement(mi),
926 &TypePrinter, &Machine);
933 WriteMDNodeComment(Node, Out);
938 static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
939 if (const OverflowingBinaryOperator *OBO =
940 dyn_cast<OverflowingBinaryOperator>(U)) {
941 if (OBO->hasNoUnsignedWrap())
943 if (OBO->hasNoSignedWrap())
945 } else if (const SDivOperator *Div = dyn_cast<SDivOperator>(U)) {
948 } else if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
949 if (GEP->isInBounds())
954 static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
955 TypePrinting &TypePrinter, SlotTracker *Machine) {
956 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
957 if (CI->getType() == Type::getInt1Ty(CV->getContext())) {
958 Out << (CI->getZExtValue() ? "true" : "false");
961 Out << CI->getValue();
965 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
966 if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble ||
967 &CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) {
968 // We would like to output the FP constant value in exponential notation,
969 // but we cannot do this if doing so will lose precision. Check here to
970 // make sure that we only output it in exponential format if we can parse
971 // the value back and get the same value.
974 bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
975 double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
976 CFP->getValueAPF().convertToFloat();
977 std::string StrVal = ftostr(CFP->getValueAPF());
979 // Check to make sure that the stringized number is not some string like
980 // "Inf" or NaN, that atof will accept, but the lexer will not. Check
981 // that the string matches the "[-+]?[0-9]" regex.
983 if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
984 ((StrVal[0] == '-' || StrVal[0] == '+') &&
985 (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
986 // Reparse stringized version!
987 if (atof(StrVal.c_str()) == Val) {
992 // Otherwise we could not reparse it to exactly the same value, so we must
993 // output the string in hexadecimal format! Note that loading and storing
994 // floating point types changes the bits of NaNs on some hosts, notably
995 // x86, so we must not use these types.
996 assert(sizeof(double) == sizeof(uint64_t) &&
997 "assuming that double is 64 bits!");
999 APFloat apf = CFP->getValueAPF();
1000 // Floats are represented in ASCII IR as double, convert.
1002 apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1005 utohex_buffer(uint64_t(apf.bitcastToAPInt().getZExtValue()),
1010 // Some form of long double. These appear as a magic letter identifying
1011 // the type, then a fixed number of hex digits.
1013 if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) {
1015 // api needed to prevent premature destruction
1016 APInt api = CFP->getValueAPF().bitcastToAPInt();
1017 const uint64_t* p = api.getRawData();
1018 uint64_t word = p[1];
1020 int width = api.getBitWidth();
1021 for (int j=0; j<width; j+=4, shiftcount-=4) {
1022 unsigned int nibble = (word>>shiftcount) & 15;
1024 Out << (unsigned char)(nibble + '0');
1026 Out << (unsigned char)(nibble - 10 + 'A');
1027 if (shiftcount == 0 && j+4 < width) {
1031 shiftcount = width-j-4;
1035 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad)
1037 else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1040 llvm_unreachable("Unsupported floating point type");
1041 // api needed to prevent premature destruction
1042 APInt api = CFP->getValueAPF().bitcastToAPInt();
1043 const uint64_t* p = api.getRawData();
1046 int width = api.getBitWidth();
1047 for (int j=0; j<width; j+=4, shiftcount-=4) {
1048 unsigned int nibble = (word>>shiftcount) & 15;
1050 Out << (unsigned char)(nibble + '0');
1052 Out << (unsigned char)(nibble - 10 + 'A');
1053 if (shiftcount == 0 && j+4 < width) {
1057 shiftcount = width-j-4;
1063 if (isa<ConstantAggregateZero>(CV)) {
1064 Out << "zeroinitializer";
1068 if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1069 Out << "blockaddress(";
1070 WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine);
1072 WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine);
1077 if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1078 // As a special case, print the array as a string if it is an array of
1079 // i8 with ConstantInt values.
1081 const Type *ETy = CA->getType()->getElementType();
1082 if (CA->isString()) {
1084 PrintEscapedString(CA->getAsString(), Out);
1086 } else { // Cannot output in string format...
1088 if (CA->getNumOperands()) {
1089 TypePrinter.print(ETy, Out);
1091 WriteAsOperandInternal(Out, CA->getOperand(0),
1092 &TypePrinter, Machine);
1093 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1095 TypePrinter.print(ETy, Out);
1097 WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine);
1105 if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
1106 if (CS->getType()->isPacked())
1109 unsigned N = CS->getNumOperands();
1112 TypePrinter.print(CS->getOperand(0)->getType(), Out);
1115 WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine);
1117 for (unsigned i = 1; i < N; i++) {
1119 TypePrinter.print(CS->getOperand(i)->getType(), Out);
1122 WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine);
1128 if (CS->getType()->isPacked())
1133 if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
1134 const Type *ETy = CP->getType()->getElementType();
1135 assert(CP->getNumOperands() > 0 &&
1136 "Number of operands for a PackedConst must be > 0");
1138 TypePrinter.print(ETy, Out);
1140 WriteAsOperandInternal(Out, CP->getOperand(0), &TypePrinter, Machine);
1141 for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
1143 TypePrinter.print(ETy, Out);
1145 WriteAsOperandInternal(Out, CP->getOperand(i), &TypePrinter, Machine);
1151 if (isa<ConstantPointerNull>(CV)) {
1156 if (isa<UndefValue>(CV)) {
1161 if (const MDNode *Node = dyn_cast<MDNode>(CV)) {
1162 Out << "!" << Machine->getMetadataSlot(Node);
1166 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1167 Out << CE->getOpcodeName();
1168 WriteOptimizationInfo(Out, CE);
1169 if (CE->isCompare())
1170 Out << ' ' << getPredicateText(CE->getPredicate());
1173 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1174 TypePrinter.print((*OI)->getType(), Out);
1176 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine);
1177 if (OI+1 != CE->op_end())
1181 if (CE->hasIndices()) {
1182 const SmallVector<unsigned, 4> &Indices = CE->getIndices();
1183 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1184 Out << ", " << Indices[i];
1189 TypePrinter.print(CE->getType(), Out);
1196 Out << "<placeholder or erroneous Constant>";
1200 /// WriteAsOperand - Write the name of the specified value out to the specified
1201 /// ostream. This can be useful when you just want to print int %reg126, not
1202 /// the whole instruction that generated it.
1204 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1205 TypePrinting *TypePrinter,
1206 SlotTracker *Machine) {
1208 PrintLLVMName(Out, V);
1212 const Constant *CV = dyn_cast<Constant>(V);
1213 if (CV && !isa<GlobalValue>(CV)) {
1214 assert(TypePrinter && "Constants require TypePrinting!");
1215 WriteConstantInt(Out, CV, *TypePrinter, Machine);
1219 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1221 if (IA->hasSideEffects())
1222 Out << "sideeffect ";
1223 if (IA->isAlignStack())
1224 Out << "alignstack ";
1226 PrintEscapedString(IA->getAsmString(), Out);
1228 PrintEscapedString(IA->getConstraintString(), Out);
1233 if (const MDNode *N = dyn_cast<MDNode>(V)) {
1234 if (N->isFunctionLocal()) {
1235 // Print metadata inline, not via slot reference number.
1237 for (unsigned mi = 0, me = N->getNumElements(); mi != me; ++mi) {
1238 const Value *Val = N->getElement(mi);
1242 TypePrinter->print(N->getElement(0)->getType(), Out);
1244 WriteAsOperandInternal(Out, N->getElement(0), TypePrinter, Machine);
1253 Out << '!' << Machine->getMetadataSlot(N);
1257 if (const MDString *MDS = dyn_cast<MDString>(V)) {
1259 PrintEscapedString(MDS->getString(), Out);
1264 if (V->getValueID() == Value::PseudoSourceValueVal ||
1265 V->getValueID() == Value::FixedStackPseudoSourceValueVal) {
1273 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1274 Slot = Machine->getGlobalSlot(GV);
1277 Slot = Machine->getLocalSlot(V);
1280 Machine = createSlotTracker(V);
1282 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1283 Slot = Machine->getGlobalSlot(GV);
1286 Slot = Machine->getLocalSlot(V);
1295 Out << Prefix << Slot;
1300 void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
1301 bool PrintType, const Module *Context) {
1303 // Fast path: Don't construct and populate a TypePrinting object if we
1304 // won't be needing any types printed.
1306 (!isa<Constant>(V) || V->hasName() || isa<GlobalValue>(V))) {
1307 WriteAsOperandInternal(Out, V, 0, 0);
1311 if (Context == 0) Context = getModuleFromVal(V);
1313 TypePrinting TypePrinter;
1314 std::vector<const Type*> NumberedTypes;
1315 AddModuleTypesToPrinter(TypePrinter, NumberedTypes, Context);
1317 TypePrinter.print(V->getType(), Out);
1321 WriteAsOperandInternal(Out, V, &TypePrinter, 0);
1326 class AssemblyWriter {
1327 formatted_raw_ostream &Out;
1328 SlotTracker &Machine;
1329 const Module *TheModule;
1330 TypePrinting TypePrinter;
1331 AssemblyAnnotationWriter *AnnotationWriter;
1332 std::vector<const Type*> NumberedTypes;
1333 DenseMap<unsigned, StringRef> MDNames;
1336 inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
1338 AssemblyAnnotationWriter *AAW)
1339 : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
1340 AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
1341 // FIXME: Provide MDPrinter
1343 MetadataContext &TheMetadata = M->getContext().getMetadata();
1344 SmallVector<std::pair<unsigned, StringRef>, 4> Names;
1345 TheMetadata.getHandlerNames(Names);
1346 for (SmallVector<std::pair<unsigned, StringRef>, 4>::iterator
1348 E = Names.end(); I != E; ++I) {
1349 MDNames[I->first] = I->second;
1354 void write(const Module *M) { printModule(M); }
1356 void write(const GlobalValue *G) {
1357 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(G))
1359 else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(G))
1361 else if (const Function *F = dyn_cast<Function>(G))
1364 llvm_unreachable("Unknown global");
1367 void write(const BasicBlock *BB) { printBasicBlock(BB); }
1368 void write(const Instruction *I) { printInstruction(*I); }
1370 void writeOperand(const Value *Op, bool PrintType);
1371 void writeParamOperand(const Value *Operand, Attributes Attrs);
1374 void printModule(const Module *M);
1375 void printTypeSymbolTable(const TypeSymbolTable &ST);
1376 void printGlobal(const GlobalVariable *GV);
1377 void printAlias(const GlobalAlias *GV);
1378 void printFunction(const Function *F);
1379 void printArgument(const Argument *FA, Attributes Attrs);
1380 void printBasicBlock(const BasicBlock *BB);
1381 void printInstruction(const Instruction &I);
1383 // printInfoComment - Print a little comment after the instruction indicating
1384 // which slot it occupies.
1385 void printInfoComment(const Value &V);
1387 } // end of anonymous namespace
1390 void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
1392 Out << "<null operand!>";
1395 TypePrinter.print(Operand->getType(), Out);
1398 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
1402 void AssemblyWriter::writeParamOperand(const Value *Operand,
1405 Out << "<null operand!>";
1408 TypePrinter.print(Operand->getType(), Out);
1409 // Print parameter attributes list
1410 if (Attrs != Attribute::None)
1411 Out << ' ' << Attribute::getAsString(Attrs);
1413 // Print the operand
1414 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
1418 void AssemblyWriter::printModule(const Module *M) {
1419 if (!M->getModuleIdentifier().empty() &&
1420 // Don't print the ID if it will start a new line (which would
1421 // require a comment char before it).
1422 M->getModuleIdentifier().find('\n') == std::string::npos)
1423 Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
1425 if (!M->getDataLayout().empty())
1426 Out << "target datalayout = \"" << M->getDataLayout() << "\"\n";
1427 if (!M->getTargetTriple().empty())
1428 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
1430 if (!M->getModuleInlineAsm().empty()) {
1431 // Split the string into lines, to make it easier to read the .ll file.
1432 std::string Asm = M->getModuleInlineAsm();
1434 size_t NewLine = Asm.find_first_of('\n', CurPos);
1436 while (NewLine != std::string::npos) {
1437 // We found a newline, print the portion of the asm string from the
1438 // last newline up to this newline.
1439 Out << "module asm \"";
1440 PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine),
1444 NewLine = Asm.find_first_of('\n', CurPos);
1446 Out << "module asm \"";
1447 PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.end()), Out);
1451 // Loop over the dependent libraries and emit them.
1452 Module::lib_iterator LI = M->lib_begin();
1453 Module::lib_iterator LE = M->lib_end();
1456 Out << "deplibs = [ ";
1458 Out << '"' << *LI << '"';
1466 // Loop over the symbol table, emitting all id'd types.
1467 if (!M->getTypeSymbolTable().empty() || !NumberedTypes.empty()) Out << '\n';
1468 printTypeSymbolTable(M->getTypeSymbolTable());
1470 // Output all globals.
1471 if (!M->global_empty()) Out << '\n';
1472 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
1476 // Output all aliases.
1477 if (!M->alias_empty()) Out << "\n";
1478 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
1482 // Output all of the functions.
1483 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
1486 // Output named metadata.
1487 if (!M->named_metadata_empty()) Out << '\n';
1488 for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
1489 E = M->named_metadata_end(); I != E; ++I) {
1490 const NamedMDNode *NMD = I;
1491 Out << "!" << NMD->getName() << " = !{";
1492 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
1494 MDNode *MD = dyn_cast_or_null<MDNode>(NMD->getElement(i));
1495 Out << '!' << Machine.getMetadataSlot(MD);
1501 if (!Machine.mdnEmpty()) Out << '\n';
1502 WriteMDNodes(Out, TypePrinter, Machine);
1505 static void PrintLinkage(GlobalValue::LinkageTypes LT,
1506 formatted_raw_ostream &Out) {
1508 case GlobalValue::ExternalLinkage: break;
1509 case GlobalValue::PrivateLinkage: Out << "private "; break;
1510 case GlobalValue::LinkerPrivateLinkage: Out << "linker_private "; break;
1511 case GlobalValue::InternalLinkage: Out << "internal "; break;
1512 case GlobalValue::LinkOnceAnyLinkage: Out << "linkonce "; break;
1513 case GlobalValue::LinkOnceODRLinkage: Out << "linkonce_odr "; break;
1514 case GlobalValue::WeakAnyLinkage: Out << "weak "; break;
1515 case GlobalValue::WeakODRLinkage: Out << "weak_odr "; break;
1516 case GlobalValue::CommonLinkage: Out << "common "; break;
1517 case GlobalValue::AppendingLinkage: Out << "appending "; break;
1518 case GlobalValue::DLLImportLinkage: Out << "dllimport "; break;
1519 case GlobalValue::DLLExportLinkage: Out << "dllexport "; break;
1520 case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break;
1521 case GlobalValue::AvailableExternallyLinkage:
1522 Out << "available_externally ";
1524 // This is invalid syntax and just a debugging aid.
1525 case GlobalValue::GhostLinkage: Out << "ghost "; break;
1530 static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
1531 formatted_raw_ostream &Out) {
1533 default: llvm_unreachable("Invalid visibility style!");
1534 case GlobalValue::DefaultVisibility: break;
1535 case GlobalValue::HiddenVisibility: Out << "hidden "; break;
1536 case GlobalValue::ProtectedVisibility: Out << "protected "; break;
1540 void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
1541 WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
1544 if (!GV->hasInitializer() && GV->hasExternalLinkage())
1547 PrintLinkage(GV->getLinkage(), Out);
1548 PrintVisibility(GV->getVisibility(), Out);
1550 if (GV->isThreadLocal()) Out << "thread_local ";
1551 if (unsigned AddressSpace = GV->getType()->getAddressSpace())
1552 Out << "addrspace(" << AddressSpace << ") ";
1553 Out << (GV->isConstant() ? "constant " : "global ");
1554 TypePrinter.print(GV->getType()->getElementType(), Out);
1556 if (GV->hasInitializer()) {
1558 writeOperand(GV->getInitializer(), false);
1561 if (GV->hasSection())
1562 Out << ", section \"" << GV->getSection() << '"';
1563 if (GV->getAlignment())
1564 Out << ", align " << GV->getAlignment();
1566 printInfoComment(*GV);
1570 void AssemblyWriter::printAlias(const GlobalAlias *GA) {
1571 // Don't crash when dumping partially built GA
1573 Out << "<<nameless>> = ";
1575 PrintLLVMName(Out, GA);
1578 PrintVisibility(GA->getVisibility(), Out);
1582 PrintLinkage(GA->getLinkage(), Out);
1584 const Constant *Aliasee = GA->getAliasee();
1586 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Aliasee)) {
1587 TypePrinter.print(GV->getType(), Out);
1589 PrintLLVMName(Out, GV);
1590 } else if (const Function *F = dyn_cast<Function>(Aliasee)) {
1591 TypePrinter.print(F->getFunctionType(), Out);
1594 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
1595 } else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Aliasee)) {
1596 TypePrinter.print(GA->getType(), Out);
1598 PrintLLVMName(Out, GA);
1600 const ConstantExpr *CE = cast<ConstantExpr>(Aliasee);
1601 // The only valid GEP is an all zero GEP.
1602 assert((CE->getOpcode() == Instruction::BitCast ||
1603 CE->getOpcode() == Instruction::GetElementPtr) &&
1604 "Unsupported aliasee");
1605 writeOperand(CE, false);
1608 printInfoComment(*GA);
1612 void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) {
1613 // Emit all numbered types.
1614 for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
1615 Out << '%' << i << " = type ";
1617 // Make sure we print out at least one level of the type structure, so
1618 // that we do not get %2 = type %2
1619 TypePrinter.printAtLeastOneLevel(NumberedTypes[i], Out);
1623 // Print the named types.
1624 for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end();
1626 PrintLLVMName(Out, TI->first, LocalPrefix);
1629 // Make sure we print out at least one level of the type structure, so
1630 // that we do not get %FILE = type %FILE
1631 TypePrinter.printAtLeastOneLevel(TI->second, Out);
1636 /// printFunction - Print all aspects of a function.
1638 void AssemblyWriter::printFunction(const Function *F) {
1639 // Print out the return type and name.
1642 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
1644 if (F->isDeclaration())
1649 PrintLinkage(F->getLinkage(), Out);
1650 PrintVisibility(F->getVisibility(), Out);
1652 // Print the calling convention.
1653 switch (F->getCallingConv()) {
1654 case CallingConv::C: break; // default
1655 case CallingConv::Fast: Out << "fastcc "; break;
1656 case CallingConv::Cold: Out << "coldcc "; break;
1657 case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
1658 case CallingConv::X86_FastCall: Out << "x86_fastcallcc "; break;
1659 case CallingConv::ARM_APCS: Out << "arm_apcscc "; break;
1660 case CallingConv::ARM_AAPCS: Out << "arm_aapcscc "; break;
1661 case CallingConv::ARM_AAPCS_VFP:Out << "arm_aapcs_vfpcc "; break;
1662 case CallingConv::MSP430_INTR: Out << "msp430_intrcc "; break;
1663 default: Out << "cc" << F->getCallingConv() << " "; break;
1666 const FunctionType *FT = F->getFunctionType();
1667 const AttrListPtr &Attrs = F->getAttributes();
1668 Attributes RetAttrs = Attrs.getRetAttributes();
1669 if (RetAttrs != Attribute::None)
1670 Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' ';
1671 TypePrinter.print(F->getReturnType(), Out);
1673 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
1675 Machine.incorporateFunction(F);
1677 // Loop over the arguments, printing them...
1680 if (!F->isDeclaration()) {
1681 // If this isn't a declaration, print the argument names as well.
1682 for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end();
1684 // Insert commas as we go... the first arg doesn't get a comma
1685 if (I != F->arg_begin()) Out << ", ";
1686 printArgument(I, Attrs.getParamAttributes(Idx));
1690 // Otherwise, print the types from the function type.
1691 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
1692 // Insert commas as we go... the first arg doesn't get a comma
1696 TypePrinter.print(FT->getParamType(i), Out);
1698 Attributes ArgAttrs = Attrs.getParamAttributes(i+1);
1699 if (ArgAttrs != Attribute::None)
1700 Out << ' ' << Attribute::getAsString(ArgAttrs);
1704 // Finish printing arguments...
1705 if (FT->isVarArg()) {
1706 if (FT->getNumParams()) Out << ", ";
1707 Out << "..."; // Output varargs portion of signature!
1710 Attributes FnAttrs = Attrs.getFnAttributes();
1711 if (FnAttrs != Attribute::None)
1712 Out << ' ' << Attribute::getAsString(Attrs.getFnAttributes());
1713 if (F->hasSection())
1714 Out << " section \"" << F->getSection() << '"';
1715 if (F->getAlignment())
1716 Out << " align " << F->getAlignment();
1718 Out << " gc \"" << F->getGC() << '"';
1719 if (F->isDeclaration()) {
1724 // Output all of its basic blocks... for the function
1725 for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
1731 Machine.purgeFunction();
1734 /// printArgument - This member is called for every argument that is passed into
1735 /// the function. Simply print it out
1737 void AssemblyWriter::printArgument(const Argument *Arg,
1740 TypePrinter.print(Arg->getType(), Out);
1742 // Output parameter attributes list
1743 if (Attrs != Attribute::None)
1744 Out << ' ' << Attribute::getAsString(Attrs);
1746 // Output name, if available...
1747 if (Arg->hasName()) {
1749 PrintLLVMName(Out, Arg);
1753 /// printBasicBlock - This member is called for each basic block in a method.
1755 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
1756 if (BB->hasName()) { // Print out the label if it exists...
1758 PrintLLVMName(Out, BB->getName(), LabelPrefix);
1760 } else if (!BB->use_empty()) { // Don't print block # of no uses...
1761 Out << "\n; <label>:";
1762 int Slot = Machine.getLocalSlot(BB);
1769 if (BB->getParent() == 0) {
1770 Out.PadToColumn(50);
1771 Out << "; Error: Block without parent!";
1772 } else if (BB != &BB->getParent()->getEntryBlock()) { // Not the entry block?
1773 // Output predecessors for the block...
1774 Out.PadToColumn(50);
1776 pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
1779 Out << " No predecessors!";
1782 writeOperand(*PI, false);
1783 for (++PI; PI != PE; ++PI) {
1785 writeOperand(*PI, false);
1792 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
1794 // Output all of the instructions in the basic block...
1795 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
1796 printInstruction(*I);
1800 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
1804 /// printInfoComment - Print a little comment after the instruction indicating
1805 /// which slot it occupies.
1807 void AssemblyWriter::printInfoComment(const Value &V) {
1808 if (V.getType() != Type::getVoidTy(V.getContext())) {
1809 Out.PadToColumn(50);
1811 TypePrinter.print(V.getType(), Out);
1812 Out << "> [#uses=" << V.getNumUses() << ']'; // Output # uses
1816 // This member is called for each Instruction in a function..
1817 void AssemblyWriter::printInstruction(const Instruction &I) {
1818 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
1820 // Print out indentation for an instruction.
1823 // Print out name if it exists...
1825 PrintLLVMName(Out, &I);
1827 } else if (I.getType() != Type::getVoidTy(I.getContext())) {
1828 // Print out the def slot taken.
1829 int SlotNum = Machine.getLocalSlot(&I);
1831 Out << "<badref> = ";
1833 Out << '%' << SlotNum << " = ";
1836 // If this is a volatile load or store, print out the volatile marker.
1837 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) ||
1838 (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile())) {
1840 } else if (isa<CallInst>(I) && cast<CallInst>(I).isTailCall()) {
1841 // If this is a call, check if it's a tail call.
1845 // Print out the opcode...
1846 Out << I.getOpcodeName();
1848 // Print out optimization information.
1849 WriteOptimizationInfo(Out, &I);
1851 // Print out the compare instruction predicates
1852 if (const CmpInst *CI = dyn_cast<CmpInst>(&I))
1853 Out << ' ' << getPredicateText(CI->getPredicate());
1855 // Print out the type of the operands...
1856 const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0;
1858 // Special case conditional branches to swizzle the condition out to the front
1859 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
1860 BranchInst &BI(cast<BranchInst>(I));
1862 writeOperand(BI.getCondition(), true);
1864 writeOperand(BI.getSuccessor(0), true);
1866 writeOperand(BI.getSuccessor(1), true);
1868 } else if (isa<SwitchInst>(I)) {
1869 // Special case switch instruction to get formatting nice and correct.
1871 writeOperand(Operand , true);
1873 writeOperand(I.getOperand(1), true);
1876 for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; op += 2) {
1878 writeOperand(I.getOperand(op ), true);
1880 writeOperand(I.getOperand(op+1), true);
1883 } else if (isa<IndirectBrInst>(I)) {
1884 // Special case indirectbr instruction to get formatting nice and correct.
1886 writeOperand(Operand, true);
1889 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
1892 writeOperand(I.getOperand(i), true);
1895 } else if (isa<PHINode>(I)) {
1897 TypePrinter.print(I.getType(), Out);
1900 for (unsigned op = 0, Eop = I.getNumOperands(); op < Eop; op += 2) {
1901 if (op) Out << ", ";
1903 writeOperand(I.getOperand(op ), false); Out << ", ";
1904 writeOperand(I.getOperand(op+1), false); Out << " ]";
1906 } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) {
1908 writeOperand(I.getOperand(0), true);
1909 for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
1911 } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
1913 writeOperand(I.getOperand(0), true); Out << ", ";
1914 writeOperand(I.getOperand(1), true);
1915 for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
1917 } else if (isa<ReturnInst>(I) && !Operand) {
1919 } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
1920 // Print the calling convention being used.
1921 switch (CI->getCallingConv()) {
1922 case CallingConv::C: break; // default
1923 case CallingConv::Fast: Out << " fastcc"; break;
1924 case CallingConv::Cold: Out << " coldcc"; break;
1925 case CallingConv::X86_StdCall: Out << " x86_stdcallcc"; break;
1926 case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break;
1927 case CallingConv::ARM_APCS: Out << " arm_apcscc "; break;
1928 case CallingConv::ARM_AAPCS: Out << " arm_aapcscc "; break;
1929 case CallingConv::ARM_AAPCS_VFP:Out << " arm_aapcs_vfpcc "; break;
1930 case CallingConv::MSP430_INTR: Out << " msp430_intrcc "; break;
1931 default: Out << " cc" << CI->getCallingConv(); break;
1934 const PointerType *PTy = cast<PointerType>(Operand->getType());
1935 const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1936 const Type *RetTy = FTy->getReturnType();
1937 const AttrListPtr &PAL = CI->getAttributes();
1939 if (PAL.getRetAttributes() != Attribute::None)
1940 Out << ' ' << Attribute::getAsString(PAL.getRetAttributes());
1942 // If possible, print out the short form of the call instruction. We can
1943 // only do this if the first argument is a pointer to a nonvararg function,
1944 // and if the return type is not a pointer to a function.
1947 if (!FTy->isVarArg() &&
1948 (!isa<PointerType>(RetTy) ||
1949 !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
1950 TypePrinter.print(RetTy, Out);
1952 writeOperand(Operand, false);
1954 writeOperand(Operand, true);
1957 for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) {
1960 writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op));
1963 if (PAL.getFnAttributes() != Attribute::None)
1964 Out << ' ' << Attribute::getAsString(PAL.getFnAttributes());
1965 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
1966 const PointerType *PTy = cast<PointerType>(Operand->getType());
1967 const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1968 const Type *RetTy = FTy->getReturnType();
1969 const AttrListPtr &PAL = II->getAttributes();
1971 // Print the calling convention being used.
1972 switch (II->getCallingConv()) {
1973 case CallingConv::C: break; // default
1974 case CallingConv::Fast: Out << " fastcc"; break;
1975 case CallingConv::Cold: Out << " coldcc"; break;
1976 case CallingConv::X86_StdCall: Out << " x86_stdcallcc"; break;
1977 case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break;
1978 case CallingConv::ARM_APCS: Out << " arm_apcscc "; break;
1979 case CallingConv::ARM_AAPCS: Out << " arm_aapcscc "; break;
1980 case CallingConv::ARM_AAPCS_VFP:Out << " arm_aapcs_vfpcc "; break;
1981 case CallingConv::MSP430_INTR: Out << " msp430_intrcc "; break;
1982 default: Out << " cc" << II->getCallingConv(); break;
1985 if (PAL.getRetAttributes() != Attribute::None)
1986 Out << ' ' << Attribute::getAsString(PAL.getRetAttributes());
1988 // If possible, print out the short form of the invoke instruction. We can
1989 // only do this if the first argument is a pointer to a nonvararg function,
1990 // and if the return type is not a pointer to a function.
1993 if (!FTy->isVarArg() &&
1994 (!isa<PointerType>(RetTy) ||
1995 !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
1996 TypePrinter.print(RetTy, Out);
1998 writeOperand(Operand, false);
2000 writeOperand(Operand, true);
2003 for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) {
2006 writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op-2));
2010 if (PAL.getFnAttributes() != Attribute::None)
2011 Out << ' ' << Attribute::getAsString(PAL.getFnAttributes());
2014 writeOperand(II->getNormalDest(), true);
2016 writeOperand(II->getUnwindDest(), true);
2018 } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
2020 TypePrinter.print(AI->getType()->getElementType(), Out);
2021 if (!AI->getArraySize() || AI->isArrayAllocation()) {
2023 writeOperand(AI->getArraySize(), true);
2025 if (AI->getAlignment()) {
2026 Out << ", align " << AI->getAlignment();
2028 } else if (isa<CastInst>(I)) {
2031 writeOperand(Operand, true); // Work with broken code
2034 TypePrinter.print(I.getType(), Out);
2035 } else if (isa<VAArgInst>(I)) {
2038 writeOperand(Operand, true); // Work with broken code
2041 TypePrinter.print(I.getType(), Out);
2042 } else if (Operand) { // Print the normal way.
2044 // PrintAllTypes - Instructions who have operands of all the same type
2045 // omit the type from all but the first operand. If the instruction has
2046 // different type operands (for example br), then they are all printed.
2047 bool PrintAllTypes = false;
2048 const Type *TheType = Operand->getType();
2050 // Select, Store and ShuffleVector always print all types.
2051 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
2052 || isa<ReturnInst>(I)) {
2053 PrintAllTypes = true;
2055 for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
2056 Operand = I.getOperand(i);
2057 // note that Operand shouldn't be null, but the test helps make dump()
2058 // more tolerant of malformed IR
2059 if (Operand && Operand->getType() != TheType) {
2060 PrintAllTypes = true; // We have differing types! Print them all!
2066 if (!PrintAllTypes) {
2068 TypePrinter.print(TheType, Out);
2072 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {
2074 writeOperand(I.getOperand(i), PrintAllTypes);
2078 // Print post operand alignment for load/store
2079 if (isa<LoadInst>(I) && cast<LoadInst>(I).getAlignment()) {
2080 Out << ", align " << cast<LoadInst>(I).getAlignment();
2081 } else if (isa<StoreInst>(I) && cast<StoreInst>(I).getAlignment()) {
2082 Out << ", align " << cast<StoreInst>(I).getAlignment();
2085 // Print Metadata info
2086 if (!MDNames.empty()) {
2087 MetadataContext &TheMetadata = I.getContext().getMetadata();
2088 typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
2090 TheMetadata.getMDs(&I, MDs);
2091 for (MDMapTy::const_iterator MI = MDs.begin(), ME = MDs.end(); MI != ME;
2093 Out << ", !" << MDNames[MI->first]
2094 << " !" << Machine.getMetadataSlot(MI->second);
2096 printInfoComment(I);
2100 //===----------------------------------------------------------------------===//
2101 // External Interface declarations
2102 //===----------------------------------------------------------------------===//
2104 void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2105 SlotTracker SlotTable(this);
2106 formatted_raw_ostream OS(ROS);
2107 AssemblyWriter W(OS, SlotTable, this, AAW);
2111 void Type::print(raw_ostream &OS) const {
2113 OS << "<null Type>";
2116 TypePrinting().print(this, OS);
2119 void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
2121 ROS << "printing a <null> value\n";
2124 formatted_raw_ostream OS(ROS);
2125 if (const Instruction *I = dyn_cast<Instruction>(this)) {
2126 const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
2127 SlotTracker SlotTable(F);
2128 AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW);
2130 } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
2131 SlotTracker SlotTable(BB->getParent());
2132 AssemblyWriter W(OS, SlotTable,
2133 BB->getParent() ? BB->getParent()->getParent() : 0, AAW);
2135 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
2136 SlotTracker SlotTable(GV->getParent());
2137 AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
2139 } else if (const MDString *MDS = dyn_cast<MDString>(this)) {
2140 TypePrinting TypePrinter;
2141 TypePrinter.print(MDS->getType(), OS);
2144 PrintEscapedString(MDS->getString(), OS);
2146 } else if (const MDNode *N = dyn_cast<MDNode>(this)) {
2147 SlotTracker SlotTable(N);
2148 TypePrinting TypePrinter;
2149 SlotTable.initialize();
2150 WriteMDNodes(OS, TypePrinter, SlotTable);
2151 } else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
2152 SlotTracker SlotTable(N);
2153 TypePrinting TypePrinter;
2154 SlotTable.initialize();
2155 OS << "!" << N->getName() << " = !{";
2156 for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
2158 MDNode *MD = dyn_cast_or_null<MDNode>(N->getElement(i));
2160 OS << '!' << SlotTable.getMetadataSlot(MD);
2165 WriteMDNodes(OS, TypePrinter, SlotTable);
2166 } else if (const Constant *C = dyn_cast<Constant>(this)) {
2167 TypePrinting TypePrinter;
2168 TypePrinter.print(C->getType(), OS);
2170 WriteConstantInt(OS, C, TypePrinter, 0);
2171 } else if (const Argument *A = dyn_cast<Argument>(this)) {
2172 WriteAsOperand(OS, this, true,
2173 A->getParent() ? A->getParent()->getParent() : 0);
2174 } else if (isa<InlineAsm>(this)) {
2175 WriteAsOperand(OS, this, true, 0);
2177 // Otherwise we don't know what it is. Call the virtual function to
2178 // allow a subclass to print itself.
2183 // Value::printCustom - subclasses should override this to implement printing.
2184 void Value::printCustom(raw_ostream &OS) const {
2185 llvm_unreachable("Unknown value to print out!");
2188 // Value::dump - allow easy printing of Values from the debugger.
2189 void Value::dump() const { print(errs()); errs() << '\n'; }
2191 // Type::dump - allow easy printing of Types from the debugger.
2192 // This one uses type names from the given context module
2193 void Type::dump(const Module *Context) const {
2194 WriteTypeSymbolic(errs(), this, Context);
2198 // Type::dump - allow easy printing of Types from the debugger.
2199 void Type::dump() const { dump(0); }
2201 // Module::dump() - Allow printing of Modules from the debugger.
2202 void Module::dump() const { print(errs(), 0); }