56 if (
const Argument *MA = dyn_cast<Argument>(V))
57 return MA->getParent() ? MA->getParent()->getParent() : 0;
59 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
60 return BB->getParent() ? BB->getParent()->getParent() : 0;
63 const Function *M =
I->getParent() ?
I->getParent()->getParent() : 0;
67 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
68 return GV->getParent();
74 default: Out <<
"cc" << cc;
break;
97 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
98 unsigned char C = Name[i];
99 if (isprint(C) && C !=
'\\' && C !=
'"')
102 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
117 assert(!Name.
empty() &&
"Cannot get empty name!");
126 bool NeedsQuotes =
isdigit(static_cast<unsigned char>(Name[0]));
128 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
133 unsigned char C = Name[i];
134 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
171 unsigned NextNumber = 0;
237 OS <<
'%' << I->second;
239 OS <<
"%\"type " << STy <<
'\"';
265 OS << "<unrecognized-type>";
270 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
271 if (STy->isOpaque()) {
279 if (STy->getNumElements() == 0) {
282 StructType::element_iterator I = STy->element_begin();
285 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
296 //===----------------------------------------------------------------------===//
297 // SlotTracker Class: Enumerate slot numbers for unnamed values
298 //===----------------------------------------------------------------------===//
304 typedef DenseMap<const Value*, unsigned> ValueMap;
308 const Module* TheModule;
311 const Function* TheFunction;
312 bool FunctionProcessed;
323 DenseMap<const MDNode*, unsigned> mdnMap;
327 DenseMap<AttributeSet, unsigned> asMap;
331 explicit SlotTracker(const Module *M);
333 explicit SlotTracker(const Function *F);
337 int getLocalSlot(const Value *V);
338 int getGlobalSlot(const GlobalValue *V);
339 int getMetadataSlot(const MDNode *N);
340 int getAttributeGroupSlot(AttributeSet AS);
344 void incorporateFunction(const Function *F) {
346 FunctionProcessed = false;
352 void purgeFunction();
355 typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator;
356 mdn_iterator mdn_begin() { return mdnMap.begin(); }
357 mdn_iterator mdn_end() { return mdnMap.end(); }
358 unsigned mdn_size() const { return mdnMap.size(); }
359 bool mdn_empty() const { return mdnMap.empty(); }
362 typedef DenseMap<AttributeSet, unsigned>::iterator as_iterator;
363 as_iterator as_begin() { return asMap.begin(); }
364 as_iterator as_end() { return asMap.end(); }
365 unsigned as_size() const { return asMap.size(); }
366 bool as_empty() const { return asMap.empty(); }
369 inline void initialize();
371 // Implementation Details
374 void CreateModuleSlot(const GlobalValue *V);
377 void CreateMetadataSlot(const MDNode *N);
380 void CreateFunctionSlot(const Value *V);
383 void CreateAttributeSetSlot(AttributeSet AS);
387 void processModule();
390 void processFunction();
392 SlotTracker(const SlotTracker &) LLVM_DELETED_FUNCTION;
393 void operator=(const SlotTracker &) LLVM_DELETED_FUNCTION;
396 SlotTracker *createSlotTracker(const Module *M) {
397 return new SlotTracker(M);
400 static SlotTracker *createSlotTracker(const Value *V) {
401 if (const Argument *FA = dyn_cast<Argument>(V))
402 return new SlotTracker(FA->getParent());
404 if (const Instruction *I = dyn_cast<Instruction>(V))
406 return new SlotTracker(I->getParent()->getParent());
408 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
409 return new SlotTracker(BB->getParent());
411 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
412 return new SlotTracker(GV->getParent());
414 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
415 return new SlotTracker(GA->getParent());
417 if (const Function *Func = dyn_cast<Function>(V))
418 return new SlotTracker(Func);
420 if (const MDNode *MD = dyn_cast<MDNode>(V)) {
421 if (!MD->isFunctionLocal())
422 return new SlotTracker(MD->getFunction());
424 return new SlotTracker((Function *)0);
431 #define ST_DEBUG(X) dbgs() << X
436 // Module level constructor. Causes the contents of the Module (sans functions)
437 // to be added to the slot table.
438 SlotTracker::SlotTracker(const Module *M)
439 : TheModule(M), TheFunction(0), FunctionProcessed(false),
440 mNext(0), fNext(0), mdnNext(0), asNext(0) {
443 // Function level constructor. Causes the contents of the Module and the one
444 // function provided to be added to the slot table.
445 SlotTracker::SlotTracker(const Function *F)
446 : TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false),
447 mNext(0), fNext(0), mdnNext(0), asNext(0) {
450 inline void SlotTracker::initialize() {
453 TheModule = 0; ///< Prevent re-processing next time we're called.
456 if (TheFunction && !FunctionProcessed)
462 void SlotTracker::processModule() {
467 E = TheModule->global_end();
I != E; ++
I) {
474 I = TheModule->named_metadata_begin(),
475 E = TheModule->named_metadata_end();
I != E; ++
I) {
491 CreateAttributeSetSlot(FnAttrs);
498 void SlotTracker::processFunction() {
499 ST_DEBUG(
"begin processFunction!\n");
504 AE = TheFunction->arg_end(); AI != AE; ++AI)
506 CreateFunctionSlot(AI);
508 ST_DEBUG(
"Inserting Instructions:\n");
514 E = TheFunction->end(); BB != E; ++BB) {
516 CreateFunctionSlot(BB);
520 if (!
I->getType()->isVoidTy() && !
I->hasName())
521 CreateFunctionSlot(
I);
526 if (
const CallInst *CI = dyn_cast<CallInst>(
I)) {
527 if (
Function *
F = CI->getCalledFunction())
528 if (
F->getName().startswith(
"llvm."))
529 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i)
530 if (
MDNode *
N = dyn_cast_or_null<MDNode>(
I->getOperand(i)))
531 CreateMetadataSlot(
N);
534 AttributeSet Attrs = CI->getAttributes().getFnAttributes();
536 CreateAttributeSetSlot(Attrs);
537 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(
I)) {
539 AttributeSet Attrs = II->getAttributes().getFnAttributes();
541 CreateAttributeSetSlot(Attrs);
545 I->getAllMetadata(MDForInst);
546 for (
unsigned i = 0, e = MDForInst.
size(); i != e; ++i)
547 CreateMetadataSlot(MDForInst[i].second);
552 FunctionProcessed =
true;
564 FunctionProcessed =
false;
575 return MI == mMap.end() ? -1 : (int)MI->second;
585 return MI == mdnMap.end() ? -1 : (int)MI->second;
591 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
597 return FI == fMap.end() ? -1 : (int)FI->second;
606 return AI == asMap.end() ? -1 : (int)AI->second;
610 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
611 assert(V &&
"Can't insert a null Value into SlotTracker!");
613 assert(!V->
hasName() &&
"Doesn't need a slot!");
615 unsigned DestSlot = mNext++;
618 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
621 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
622 (isa<Function>(V) ?
'F' :
623 (isa<GlobalAlias>(V) ?
'A' :
'o'))) <<
"]\n");
627 void SlotTracker::CreateFunctionSlot(
const Value *V) {
630 unsigned DestSlot = fNext++;
634 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
635 DestSlot <<
" [o]\n");
639 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
640 assert(N &&
"Can't insert a null Value into SlotTracker!");
645 mdn_iterator
I = mdnMap.find(N);
646 if (I != mdnMap.end())
649 unsigned DestSlot = mdnNext++;
650 mdnMap[
N] = DestSlot;
656 CreateMetadataSlot(Op);
659 void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
661 "Doesn't need a slot!");
663 as_iterator I = asMap.find(AS);
664 if (I != asMap.end())
667 unsigned DestSlot = asNext++;
668 asMap[AS] = DestSlot;
683 const char * pred =
"unknown";
718 default: Out <<
" <unknown operation " << Op <<
">";
break;
734 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
736 if (FPO->hasUnsafeAlgebra())
739 if (FPO->hasNoNaNs())
741 if (FPO->hasNoInfs())
743 if (FPO->hasNoSignedZeros())
745 if (FPO->hasAllowReciprocal())
751 dyn_cast<OverflowingBinaryOperator>(U)) {
752 if (OBO->hasNoUnsignedWrap())
754 if (OBO->hasNoSignedWrap())
757 dyn_cast<PossiblyExactOperator>(U)) {
760 }
else if (
const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
761 if (GEP->isInBounds())
770 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
771 if (CI->getType()->isIntegerTy(1)) {
772 Out << (CI->getZExtValue() ?
"true" :
"false");
775 Out << CI->getValue();
779 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
790 bool isInf = CFP->getValueAPF().isInfinity();
791 bool isNaN = CFP->getValueAPF().isNaN();
792 if (!isHalf && !isInf && !isNaN) {
793 double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
794 CFP->getValueAPF().convertToFloat();
802 if ((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
803 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
804 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) {
816 assert(
sizeof(
double) ==
sizeof(uint64_t) &&
817 "assuming that double is 64 bits!");
819 APFloat apf = CFP->getValueAPF();
840 APInt api = CFP->getValueAPF().bitcastToAPInt();
842 uint64_t word = p[1];
845 for (
int j=0; j<width; j+=4, shiftcount-=4) {
846 unsigned int nibble = (word>>shiftcount) & 15;
848 Out << (
unsigned char)(nibble +
'0');
850 Out << (
unsigned char)(nibble - 10 +
'A');
851 if (shiftcount == 0 && j+4 < width) {
855 shiftcount = width-j-4;
871 APInt api = CFP->getValueAPF().bitcastToAPInt();
875 for (
int j=0; j<width; j+=4, shiftcount-=4) {
876 unsigned int nibble = (word>>shiftcount) & 15;
878 Out << (
unsigned char)(nibble +
'0');
880 Out << (
unsigned char)(nibble - 10 +
'A');
881 if (shiftcount == 0 && j+4 < width) {
885 shiftcount = width-j-4;
891 if (isa<ConstantAggregateZero>(CV)) {
892 Out <<
"zeroinitializer";
896 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
897 Out <<
"blockaddress(";
908 Type *ETy = CA->getType()->getElementType();
910 TypePrinter.
print(ETy, Out);
915 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
917 TypePrinter.
print(ETy, Out);
929 if (CA->isString()) {
936 Type *ETy = CA->getType()->getElementType();
938 TypePrinter.
print(ETy, Out);
943 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
945 TypePrinter.
print(ETy, Out);
956 if (CS->getType()->isPacked())
962 TypePrinter.
print(CS->getOperand(0)->getType(), Out);
968 for (
unsigned i = 1; i <
N; i++) {
970 TypePrinter.
print(CS->getOperand(i)->getType(), Out);
980 if (CS->getType()->isPacked())
985 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
988 TypePrinter.
print(ETy, Out);
994 TypePrinter.
print(ETy, Out);
1003 if (isa<ConstantPointerNull>(CV)) {
1008 if (isa<UndefValue>(CV)) {
1013 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1014 Out << CE->getOpcodeName();
1015 WriteOptimizationInfo(Out, CE);
1016 if (CE->isCompare())
1017 Out << ' ' << getPredicateText(CE->getPredicate());
1020 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1021 TypePrinter.print((*OI)->getType(), Out);
1023 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
1024 if (OI+1 != CE->op_end())
1028 if (CE->hasIndices()) {
1029 ArrayRef<unsigned> Indices = CE->getIndices();
1030 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1031 Out << ", " << Indices[i];
1036 TypePrinter.print(CE->getType(), Out);
1043 Out << "<placeholder or erroneous Constant>";
1046 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
1047 TypePrinting *TypePrinter,
1048 SlotTracker *Machine,
1049 const Module *Context) {
1051 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
1052 const Value *V = Node->getOperand(mi);
1056 TypePrinter->print(V->getType(), Out);
1058 WriteAsOperandInternal(Out, Node->getOperand(mi),
1059 TypePrinter, Machine, Context);
1073 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1074 TypePrinting *TypePrinter,
1075 SlotTracker *Machine,
1076 const Module *Context) {
1078 PrintLLVMName(Out, V);
1082 const Constant *CV = dyn_cast<Constant>(V);
1083 if (CV && !isa<GlobalValue>(CV)) {
1084 assert(TypePrinter && "Constants require TypePrinting!");
1085 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
1089 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1091 if (IA->hasSideEffects())
1092 Out << "sideeffect ";
1093 if (IA->isAlignStack())
1094 Out << "alignstack ";
1095 // We don't emit the AD_ATT dialect as it
's the assumed default.
1096 if (IA->getDialect() == InlineAsm::AD_Intel)
1097 Out << "inteldialect ";
1099 PrintEscapedString(IA->getAsmString(), Out);
1106 if (
const MDNode *N = dyn_cast<MDNode>(V)) {
1119 int Slot = Machine->getMetadataSlot(N);
1127 if (
const MDString *MDS = dyn_cast<MDString>(V)) {
1144 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1145 Slot = Machine->getGlobalSlot(GV);
1148 Slot = Machine->getLocalSlot(V);
1155 Slot = Machine->getLocalSlot(V);
1161 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1162 Slot = Machine->getGlobalSlot(GV);
1165 Slot = Machine->getLocalSlot(V);
1174 Out << Prefix << Slot;
1180 bool PrintType,
const Module *Context) {
1185 ((!isa<Constant>(V) && !isa<MDNode>(V)) ||
1186 V->
hasName() || isa<GlobalValue>(V))) {
1204 void AssemblyWriter::init() {
1213 : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW) {
1220 Machine(*ModuleSlotTracker), AnnotationWriter(AAW) {
1228 Out <<
"<null operand!>";
1243 switch (SynchScope) {
1249 default: Out <<
" <bad ordering " << int(Ordering) <<
">";
break;
1250 case Unordered: Out <<
" unordered";
break;
1251 case Monotonic: Out <<
" monotonic";
break;
1252 case Acquire: Out <<
" acquire";
break;
1253 case Release: Out <<
" release";
break;
1262 Out <<
"<null operand!>";
1277 Machine.initialize();
1286 Out <<
"target datalayout = \"" << M->
getDataLayout() <<
"\"\n";
1294 size_t NewLine = Asm.find_first_of(
'\n', CurPos);
1296 while (NewLine != std::string::npos) {
1299 Out <<
"module asm \"";
1304 NewLine = Asm.find_first_of(
'\n', CurPos);
1306 std::string rest(Asm.begin()+CurPos, Asm.end());
1307 if (!rest.empty()) {
1308 Out <<
"module asm \"";
1334 if (!Machine.as_empty()) {
1347 if (!Machine.mdn_empty()) {
1357 Out <<
"<empty name> ";
1359 if (isalpha(static_cast<unsigned char>(Name[0])) ||
1360 Name[0] ==
'-' || Name[0] ==
'$' ||
1361 Name[0] ==
'.' || Name[0] ==
'_')
1364 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
1365 for (
unsigned i = 1, e = Name.
size(); i != e; ++i) {
1366 unsigned char C = Name[i];
1367 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
1368 C ==
'.' || C ==
'_')
1371 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
1377 int Slot = Machine.getMetadataSlot(NMD->
getOperand(i));
1394 Out <<
"linker_private_weak ";
1407 Out <<
"available_externally ";
1428 Out <<
"thread_local ";
1431 Out <<
"thread_local(localdynamic) ";
1434 Out <<
"thread_local(initialexec) ";
1437 Out <<
"thread_local(localexec) ";
1444 Out <<
"; Materializable\n";
1460 Out << (GV->
isConstant() ?
"constant " :
"global ");
1469 Out <<
", section \"";
1476 printInfoComment(*GV);
1481 Out <<
"; Materializable\n";
1485 Out <<
"<<nameless>> = ";
1500 Out <<
" <<NULL ALIASEE>>";
1505 printInfoComment(*GA);
1518 std::vector<StructType*> NumberedTypes(TypePrinter.
NumberedTypes.size());
1522 assert(I->second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
1523 NumberedTypes[I->second] = I->first;
1527 for (
unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
1528 Out <<
'%' << i <<
" = type ";
1536 for (
unsigned i = 0, e = TypePrinter.
NamedTypes.
size(); i != e; ++i) {
1556 Out <<
"; Materializable\n";
1561 std::string AttrStr;
1564 for (
unsigned E = AS.
getNumSlots(); Idx != E; ++Idx)
1565 if (AS.
getSlotIndex(Idx) == AttributeSet::FunctionIndex)
1572 if (!AttrStr.empty()) AttrStr +=
' ';
1577 if (!AttrStr.empty())
1578 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
1597 Out << Attrs.
getAsString(AttributeSet::ReturnIndex) <<
' ';
1602 Machine.incorporateFunction(F);
1618 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
1637 Out <<
" unnamed_addr";
1639 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
1641 Out <<
" section \"";
1648 Out <<
" gc \"" << F->
getGC() <<
'"';
1664 Machine.purgeFunction();
1694 Out <<
"\n; <label>:";
1695 int Slot = Machine.getLocalSlot(BB);
1703 Out.PadToColumn(50);
1704 Out <<
"; Error: Block without parent!";
1707 Out.PadToColumn(50);
1712 Out <<
" No predecessors!";
1716 for (++PI; PI != PE; ++PI) {
1744 void AssemblyWriter::printInfoComment(
const Value &V) {
1745 if (AnnotationWriter)
1762 int SlotNum = Machine.getLocalSlot(&I);
1764 Out <<
"<badref> = ";
1766 Out <<
'%' << SlotNum <<
" = ";
1769 if (isa<CallInst>(I) && cast<CallInst>(I).isTailCall())
1776 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
1777 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
1781 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) ||
1782 (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile()) ||
1783 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isVolatile()) ||
1784 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).isVolatile()))
1791 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
1795 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
1802 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
1811 }
else if (isa<SwitchInst>(I)) {
1827 }
else if (isa<IndirectBrInst>(I)) {
1839 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
1844 for (
unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) {
1845 if (op) Out <<
", ";
1847 writeOperand(PN->getIncomingValue(op),
false); Out <<
", ";
1848 writeOperand(PN->getIncomingBlock(op),
false); Out <<
" ]";
1853 for (
const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
1855 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
1859 for (
const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
1861 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
1864 Out <<
" personality ";
1867 if (LPI->isCleanup())
1870 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
1871 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
1872 if (LPI->isCatch(i))
1879 }
else if (isa<ReturnInst>(I) && !Operand) {
1881 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
1888 Operand = CI->getCalledValue();
1891 Type *RetTy = FTy->getReturnType();
1895 Out <<
' ' << PAL.
getAsString(AttributeSet::ReturnIndex);
1902 if (!FTy->isVarArg() &&
1903 (!RetTy->isPointerTy() ||
1904 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1905 TypePrinter.
print(RetTy, Out);
1912 for (
unsigned op = 0, Eop = CI->getNumArgOperands(); op < Eop; ++op) {
1920 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
1921 Operand = II->getCalledValue();
1924 Type *RetTy = FTy->getReturnType();
1934 Out <<
' ' << PAL.
getAsString(AttributeSet::ReturnIndex);
1941 if (!FTy->isVarArg() &&
1942 (!RetTy->isPointerTy() ||
1943 !cast<PointerType>(RetTy)->getElementType()->isFunctionTy())) {
1944 TypePrinter.
print(RetTy, Out);
1951 for (
unsigned op = 0, Eop = II->getNumArgOperands(); op < Eop; ++op) {
1966 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
1968 TypePrinter.
print(AI->getAllocatedType(),
Out);
1969 if (!AI->getArraySize() || AI->isArrayAllocation()) {
1973 if (AI->getAlignment()) {
1974 Out <<
", align " << AI->getAlignment();
1976 }
else if (isa<CastInst>(I)) {
1983 }
else if (isa<VAArgInst>(I)) {
1990 }
else if (Operand) {
1995 bool PrintAllTypes =
false;
1999 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
2000 || isa<ReturnInst>(I)) {
2001 PrintAllTypes =
true;
2007 if (Operand && Operand->
getType() != TheType) {
2008 PrintAllTypes =
true;
2014 if (!PrintAllTypes) {
2016 TypePrinter.
print(TheType, Out);
2027 if (
const LoadInst *
LI = dyn_cast<LoadInst>(&I)) {
2030 if (
LI->getAlignment())
2031 Out <<
", align " <<
LI->getAlignment();
2032 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
2034 writeAtomic(SI->getOrdering(), SI->getSynchScope());
2035 if (SI->getAlignment())
2036 Out <<
", align " << SI->getAlignment();
2038 writeAtomic(CXI->getOrdering(), CXI->getSynchScope());
2039 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
2040 writeAtomic(RMWI->getOrdering(), RMWI->getSynchScope());
2041 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
2042 writeAtomic(FI->getOrdering(), FI->getSynchScope());
2048 if (!InstMD.
empty()) {
2051 for (
unsigned i = 0, e = InstMD.
size(); i != e; ++i) {
2052 unsigned Kind = InstMD[i].first;
2053 if (Kind < MDNames.
size()) {
2054 Out <<
", !" << MDNames[
Kind];
2056 Out <<
", !<unknown kind #" << Kind <<
">";
2063 printInfoComment(I);
2072 if (!Op || !isa<ConstantInt>(Op) || cast<ConstantInt>(Op)->
getBitWidth() < 32)
2079 unsigned Tag = Desc.
getTag();
2084 }
else if (Tag == dwarf::DW_TAG_user_base) {
2085 Out <<
"; [ DW_TAG_user_base ]";
2090 Out <<
'!' << Slot <<
" = metadata ";
2096 Nodes.
resize(Machine.mdn_size());
2099 Nodes[I->second] = cast<MDNode>(I->first);
2101 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
2113 std::vector<std::pair<AttributeSet, unsigned> > asVec;
2114 asVec.resize(Machine.as_size());
2118 asVec[I->second] = *I;
2120 for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
2121 I = asVec.begin(), E = asVec.end(); I != E; ++
I)
2122 Out <<
"attributes #" << I->second <<
" = { "
2123 << I->first.getAsString(AttributeSet::FunctionIndex,
true) <<
" }\n";
2148 OS <<
"<null Type>";
2152 TP.
print(const_cast<Type*>(
this), OS);
2155 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
2156 if (!STy->isLiteral()) {
2164 ROS <<
"printing a <null> value\n";
2168 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
2169 const Function *
F = I->getParent() ? I->getParent()->getParent() : 0;
2173 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
2176 W.printBasicBlock(BB);
2177 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
2182 else if (
const Function *
F = dyn_cast<Function>(GV))
2185 W.printAlias(cast<GlobalAlias>(GV));
2186 }
else if (
const MDNode *N = dyn_cast<MDNode>(
this)) {
2191 }
else if (
const Constant *
C = dyn_cast<Constant>(
this)) {
2193 TypePrinter.
print(
C->getType(), OS);
2196 }
else if (isa<InlineAsm>(
this) || isa<MDString>(
this) ||
2197 isa<Argument>(
this)) {
int getAttributeGroupSlot(AttributeSet AS)
void printStructBody(StructType *Ty, raw_ostream &OS)
void printInstructionLine(const Instruction &I)
printInstructionLine - Print an instruction and a newline character.
StringRef getName() const
getName - Return a constant reference to this named metadata's name.
LinkageTypes getLinkage() const
formatted_raw_ostream & Out
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
Abstract base class of comparison instructions.
virtual void emitBasicBlockEndAnnot(const BasicBlock *, formatted_raw_ostream &)
Like Private, but linker removes.
void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx)
Special purpose, only applies to global arrays.
VisibilityTypes getVisibility() const
*p = old <signed v ? old : v
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
ThreadLocalMode getThreadLocalMode() const
size_t size() const
size - Get the string size.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
static const fltSemantics IEEEdouble
The main container class for the LLVM Intermediate Representation.
unsigned getNumParams() const
2: 32-bit floating point type
unsigned getAlignment() const
Same, but only replaced by something equivalent.
unsigned getNumOperands() const
Available for inspection, not emission.
void printTypeIdentities()
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
Type::subtype_iterator param_iterator
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
const char * getGC() const
named_metadata_iterator named_metadata_end()
*p = old <unsigned v ? old : v
0 1 0 0 True if ordered and less than
Like Internal, but omit from symbol table.
*p = old >unsigned v ? old : v
Externally visible function.
iterator begin(unsigned Slot) const
1 1 1 0 True if unordered or not equal
Type * getReturnType() const
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
const Function * getParent() const
Return the enclosing method, or null if none.
MDNode - a tuple of other values.
4: 80-bit floating point type (X87)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
1: 16-bit floating point type
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
virtual void emitFunctionAnnot(const Function *, formatted_raw_ostream &)
const Constant * getInitializer() const
AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, const Module *M, AssemblyAnnotationWriter *AAW)
Construct an AssemblyWriter with an external SlotTracker.
*p = old >signed v ? old : v
void printBasicBlock(const BasicBlock *BB)
const Constant * getAliasee() const
const std::string & getTargetTriple() const
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
LoopInfoBase< BlockT, LoopT > * LI
CallingConv::ID getCallingConv() const
StringRef getName() const
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
void print(raw_ostream &O) const
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
1 0 0 1 True if unordered or equal
static void writeAtomicRMWOperation(raw_ostream &Out, AtomicRMWInst::BinOp Op)
static const fltSemantics x87DoubleExtended
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
void dump() const
dump - Support for debugging, callable in GDB: V->dump()
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic. This is, presumably, for writing out the mnemonics for the assembly writer.
#define llvm_unreachable(msg)
void writeAllAttributeGroups()
param_iterator param_end() const
void print(Type *Ty, raw_ostream &OS)
0 1 0 1 True if ordered and less than or equal
static const fltSemantics IEEEquad
static void PrintLinkage(GlobalValue::LinkageTypes LT, formatted_raw_ostream &Out)
Type * getVectorElementType() const
const std::string & getModuleIdentifier() const
virtual void printInfoComment(const Value &, formatted_raw_ostream &)
void writeMDNode(unsigned Slot, const MDNode *Node)
static void WriteMDNodeComment(const MDNode *Node, formatted_raw_ostream &Out)
void printGlobal(const GlobalVariable *GV)
global_iterator global_begin()
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
virtual void emitInstructionAnnot(const Instruction *, formatted_raw_ostream &)
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Function to be imported from DLL.
BasicBlock * getSuccessor(unsigned i) const
bool isMaterializable() const
bool named_metadata_empty() const
COFF::MachineTypes Machine
unsigned getNumElements() const
Return the number of elements in the Vector type.
const char * getOpcodeName() const
Type * getElementType() const
int getMetadataSlot(const MDNode *N)
getMetadataSlot - Get the slot number of a MDNode.
bool global_empty() const
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
10: Arbitrary bit width integers
ExternalWeak linkage description.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Same, but only replaced by something equivalent.
unsigned getNumSlots() const
Return the number of slots used in this attribute list. This is the number of arguments that have an ...
Type * getParamType(unsigned i) const
Parameter type accessors.
void writeOperand(const Value *Op, bool PrintType)
bool isExternallyInitialized() const
DenseMap< StructType *, unsigned > NumberedTypes
NumberedTypes - The numbered types, along with their value.
alias_iterator alias_end()
LLVM Basic Block Representation.
static void initialize(TargetLibraryInfo &TLI, const Triple &T, const char **StandardNames)
LLVM Constant Representation.
TypeFinder NamedTypes
NamedTypes - The named types that are used by the current module.
param_iterator param_begin() const
Interval::pred_iterator pred_begin(Interval *I)
void printInstruction(const Instruction &I)
uint64_t getNumElements() const
MDNode * getOperand(unsigned i) const
getOperand - Return specified operand.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getValueID() const
static void PrintEscapedString(StringRef Name, raw_ostream &Out)
opStatus convert(const fltSemantics &, roundingMode, bool *)
virtual void emitBasicBlockStartAnnot(const BasicBlock *, formatted_raw_ostream &)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
0 1 1 1 True if ordered (no nans)
void printFunction(const Function *F)
Function to be accessible from DLL.
static const Module * getModuleFromVal(const Value *V)
Constant * getAggregateElement(unsigned Elt) const
1 1 1 1 Always true (always folded)
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
const std::string & getSection() const
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static bool isAtomic(Instruction *I)
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const
const std::string & getModuleInlineAsm() const
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix)
global_iterator global_end()
virtual void printCustom(raw_ostream &O) const
0 0 1 0 True if ordered and greater than
bool hasExternalLinkage() const
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, TypePrinting &TypePrinter, SlotTracker *Machine, const Module *Context)
static const fltSemantics PPCDoubleDouble
void incorporateTypes(const Module &M)
SlotTracker * createSlotTracker(const Module *M)
Create a new SlotTracker for a Module.
Class for constant integers.
15: SIMD 'packed' format, or other vector type
const char * TagString(unsigned Tag)
unsigned getVectorNumElements() const
void run(const Module &M, bool onlyNamed)
const std::string & getDataLayout() const
void print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW=0) const
print - Implement operator<< on NamedMDNode.
void printMDNodeBody(const MDNode *MD)
1 1 0 0 True if unordered or less than
Keep one copy of function when linking (inline)
iterator end(unsigned Slot) const
alias_iterator alias_begin()
virtual ~AssemblyAnnotationWriter()
const BasicBlock & getEntryBlock() const
void writeParamOperand(const Value *Operand, AttributeSet Attrs, unsigned Idx)
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
AttributeSet getAttributes() const
Return the attribute list for this Function.
bool hasInitializer() const
Class for arbitrary precision integers.
StringRef str() const
Explicit conversion to StringRef.
LinkageTypes
An enumeration for the kinds of linkage for global values.
StringRef getName() const
APInt bitcastToAPInt() const
Value * getCondition() const
Like LinkerPrivate, but weak.
static char hexdigit(unsigned X, bool LowerCase=false)
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
PointerType * getType() const
getType - Global values are always pointers.
bool isFunctionLocal() const
isFunctionLocal - Return whether MDNode is local to a function.
static const fltSemantics IEEEsingle
Value * getCondition() const
static char * utohex_buffer(IntTy X, char *BufferEnd)
BasicBlock * getDefaultDest() const
const uint64_t * getRawData() const
bool isDeclaration() const
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
void print(raw_ostream &OS) const
print - print descriptor.
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned greater or equal
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
void printNamedMDNode(const NamedMDNode *NMD)
FunctionType * getFunctionType() const
0 1 1 0 True if ordered and operands are unequal
bool hasPrefixData() const
Keep one copy of named function when linking (weak)
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Rename collisions when linking (static functions).
Constant * getPrefixData() const
1 0 1 0 True if unordered or greater than
iterator erase(iterator I, iterator E)
3: 64-bit floating point type
The C convention as implemented on Windows/x86-64. This convention differs from the more common X86_6...
Type * getReturnType() const
virtual ~AssemblyWriter()
0 0 0 1 True if ordered and equal
LLVM Value Representation.
bool hasUnnamedAddr() const
1 0 1 1 True if unordered, greater than, or equal
void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope)
unsigned getNumOperands() const
getNumOperands - Return the number of NamedMDNode operands.
void print(raw_ostream &O, AssemblyAnnotationWriter *AAW=0) const
static const char * getPredicateText(unsigned predicate)
9: MMX vectors (64 bits, X86 specific)
0 0 1 1 True if ordered and greater than or equal
void printAlias(const GlobalAlias *GV)
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
void dump() const
dump() - Allow printing of NamedMDNodes from the debugger.
const Function * getFunction() const
void dump() const
Dump the module to stderr (for debugging).
void printModule(const Module *M)
named_metadata_iterator named_metadata_begin()
0 0 0 0 Always false (always folded)
int getLocalSlot(const Value *V)
getLocalSlot - Get the slot number for a value that is local to a function.
Module * getParent()
getParent - Get the module that holds this named metadata collection.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
bool empty() const
empty - Check if the string is empty.
5: 128-bit floating point type (112-bit mantissa)
AttributeSet getFnAttributes() const
The function attributes are returned.