60 unsigned size()
const {
return IDs.size(); }
61 std::pair<unsigned, bool> &operator[](
const Value *V) {
return IDs[V]; }
62 std::pair<unsigned, bool>
lookup(
const Value *V)
const {
65 void index(
const Value *V) {
67 unsigned ID = IDs.size() + 1;
74 if (OM.lookup(V).first)
77 if (
const Constant *C = dyn_cast<Constant>(V))
78 if (C->getNumOperands() && !isa<GlobalValue>(C))
79 for (
const Value *Op : C->operands())
80 if (!isa<BasicBlock>(Op) && !isa<GlobalValue>(Op))
94 if (
G.hasInitializer())
95 if (!isa<GlobalValue>(
G.getInitializer()))
100 if (!isa<GlobalValue>(
A.getAliasee()))
105 if (
F.hasPrefixData())
106 if (!isa<GlobalValue>(
F.getPrefixData()))
109 if (
F.hasPrologueData())
110 if (!isa<GlobalValue>(
F.getPrologueData()))
113 if (
F.hasPersonalityFn())
114 if (!isa<GlobalValue>(
F.getPersonalityFn()))
119 if (
F.isDeclaration())
127 for (
const Value *Op :
I.operands())
128 if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) ||
139 unsigned ID,
const OrderMap &OM,
142 typedef std::pair<const Use *, unsigned> Entry;
146 if (OM.lookup(U.getUser()).first)
154 !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V);
155 if (
auto *BA = dyn_cast<BlockAddress>(V))
156 ID = OM.lookup(BA->getBasicBlock()).first;
157 std::sort(List.
begin(), List.
end(), [&](
const Entry &L,
const Entry &R) {
158 const Use *LU = L.first;
159 const Use *RU = R.first;
163 auto LID = OM.lookup(LU->getUser()).first;
164 auto RID = OM.lookup(RU->getUser()).first;
184 return LU->getOperandNo() < RU->getOperandNo();
185 return LU->getOperandNo() > RU->getOperandNo();
190 [](
const Entry &L,
const Entry &R) {
return L.second < R.second; }))
195 Stack.emplace_back(V, F, List.
size());
196 assert(List.
size() == Stack.back().Shuffle.size() &&
"Wrong size");
197 for (
size_t I = 0, E = List.
size();
I != E; ++
I)
198 Stack.back().Shuffle[
I] = List[
I].second;
203 auto &IDPair = OM[V];
204 assert(IDPair.first &&
"Unmapped value");
210 IDPair.second =
true;
215 if (
const Constant *C = dyn_cast<Constant>(V))
216 if (C->getNumOperands())
217 for (
const Value *Op : C->operands())
218 if (isa<Constant>(Op))
245 for (
const Value *Op :
I.operands())
246 if (isa<Constant>(*Op) || isa<InlineAsm>(*Op))
261 if (
G.hasInitializer())
266 if (
F.hasPrefixData())
273 if (
const Argument *MA = dyn_cast<Argument>(V))
274 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
276 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
277 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
280 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
284 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
285 return GV->getParent();
287 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
289 if (isa<Instruction>(U))
300 default: Out <<
"cc" << cc;
break;
329 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
330 unsigned char C = Name[i];
331 if (isprint(C) && C !=
'\\' && C !=
'"')
334 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
350 assert(!Name.
empty() &&
"Cannot get empty name!");
360 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
362 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
367 unsigned char C = Name[i];
368 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
400 TypePrinting(
const TypePrinting &) =
delete;
401 void operator=(
const TypePrinting&) =
delete;
410 TypePrinting() =
default;
412 void incorporateTypes(
const Module &M);
420 void TypePrinting::incorporateTypes(
const Module &M) {
421 NamedTypes.run(M,
false);
425 unsigned NextNumber = 0;
427 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(),
I, E;
428 for (
I = NamedTypes.begin(), E = NamedTypes.end();
I != E; ++
I) {
436 NumberedTypes[STy] = NextNumber++;
441 NamedTypes.erase(NextToUse, NamedTypes.end());
484 return printStructBody(STy, OS);
490 if (I != NumberedTypes.
end())
491 OS <<
'%' << I->second;
493 OS <<
"%\"type " << STy <<
'\"';
519 llvm_unreachable("Invalid TypeID");
522 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
523 if (STy->isOpaque()) {
531 if (STy->getNumElements() == 0) {
534 StructType::element_iterator I = STy->element_begin();
537 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
549 //===----------------------------------------------------------------------===//
550 // SlotTracker Class: Enumerate slot numbers for unnamed values
551 //===----------------------------------------------------------------------===//
557 typedef DenseMap<const Value*, unsigned> ValueMap;
561 const Module* TheModule;
564 const Function* TheFunction;
565 bool FunctionProcessed;
566 bool ShouldInitializeAllMetadata;
577 DenseMap<const MDNode*, unsigned> mdnMap;
581 DenseMap<AttributeSet, unsigned> asMap;
589 explicit SlotTracker(const Module *M,
590 bool ShouldInitializeAllMetadata = false);
596 explicit SlotTracker(const Function *F,
597 bool ShouldInitializeAllMetadata = false);
601 int getLocalSlot(const Value *V);
602 int getGlobalSlot(const GlobalValue *V);
603 int getMetadataSlot(const MDNode *N);
604 int getAttributeGroupSlot(AttributeSet AS);
608 void incorporateFunction(const Function *F) {
610 FunctionProcessed = false;
613 const Function *getFunction() const { return TheFunction; }
618 void purgeFunction();
621 typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator;
622 mdn_iterator mdn_begin() { return mdnMap.begin(); }
623 mdn_iterator mdn_end() { return mdnMap.end(); }
624 unsigned mdn_size() const { return mdnMap.size(); }
625 bool mdn_empty() const { return mdnMap.empty(); }
628 typedef DenseMap<AttributeSet, unsigned>::iterator as_iterator;
629 as_iterator as_begin() { return asMap.begin(); }
630 as_iterator as_end() { return asMap.end(); }
631 unsigned as_size() const { return asMap.size(); }
632 bool as_empty() const { return asMap.empty(); }
635 inline void initialize();
637 // Implementation Details
640 void CreateModuleSlot(const GlobalValue *V);
643 void CreateMetadataSlot(const MDNode *N);
646 void CreateFunctionSlot(const Value *V);
649 void CreateAttributeSetSlot(AttributeSet AS);
653 void processModule();
656 void processFunction();
659 void processFunctionMetadata(const Function &F);
662 void processInstructionMetadata(const Instruction &I);
664 SlotTracker(const SlotTracker &) = delete;
665 void operator=(const SlotTracker &) = delete;
669 ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
671 : M(M), F(F), Machine(&Machine) {}
673 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
674 bool ShouldInitializeAllMetadata)
675 : MachineStorage(M ? new SlotTracker(M, ShouldInitializeAllMetadata)
677 M(M), Machine(MachineStorage.get()) {}
679 ModuleSlotTracker::~ModuleSlotTracker() {}
681 void ModuleSlotTracker::incorporateFunction(const Function &F) {
685 // Nothing to do if this is the right function already.
689 Machine->purgeFunction();
690 Machine->incorporateFunction(&F);
694 static SlotTracker *createSlotTracker(const Module *M) {
695 return new SlotTracker(M);
698 static SlotTracker *createSlotTracker(const Value *V) {
699 if (const Argument *FA = dyn_cast<Argument>(V))
700 return new SlotTracker(FA->getParent());
702 if (const Instruction *I = dyn_cast<Instruction>(V))
704 return new SlotTracker(I->getParent()->getParent());
706 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
707 return new SlotTracker(BB->getParent());
709 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
710 return new SlotTracker(GV->getParent());
712 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
713 return new SlotTracker(GA->getParent());
715 if (const Function *Func = dyn_cast<Function>(V))
716 return new SlotTracker(Func);
722 #define ST_DEBUG(X) dbgs() << X
727 // Module level constructor. Causes the contents of the Module (sans functions)
728 // to be added to the slot table.
729 SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
730 : TheModule(M), TheFunction(nullptr), FunctionProcessed(false),
731 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), mNext(0),
732 fNext(0), mdnNext(0), asNext(0) {}
734 // Function level constructor. Causes the contents of the Module and the one
735 // function provided to be added to the slot table.
736 SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
737 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
738 FunctionProcessed(false),
739 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), mNext(0),
740 fNext(0), mdnNext(0), asNext(0) {}
742 inline void SlotTracker::initialize() {
745 TheModule = nullptr; ///< Prevent re-processing next time we're called.
748 if (TheFunction && !FunctionProcessed)
754 void SlotTracker::processModule() {
760 CreateModuleSlot(&Var);
765 CreateModuleSlot(&
A);
770 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
771 CreateMetadataSlot(NMD.getOperand(i));
777 CreateModuleSlot(&
F);
779 if (ShouldInitializeAllMetadata)
780 processFunctionMetadata(
F);
786 CreateAttributeSetSlot(FnAttrs);
793 void SlotTracker::processFunction() {
794 ST_DEBUG(
"begin processFunction!\n");
799 AE = TheFunction->
arg_end(); AI != AE; ++AI)
801 CreateFunctionSlot(AI);
803 ST_DEBUG(
"Inserting Instructions:\n");
806 for (
auto &BB : *TheFunction) {
808 CreateFunctionSlot(&BB);
810 processFunctionMetadata(*TheFunction);
813 if (!I.getType()->isVoidTy() && !I.hasName())
814 CreateFunctionSlot(&I);
818 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
820 AttributeSet Attrs = CI->getAttributes().getFnAttributes();
822 CreateAttributeSetSlot(Attrs);
823 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
825 AttributeSet Attrs = II->getAttributes().getFnAttributes();
827 CreateAttributeSetSlot(Attrs);
832 FunctionProcessed =
true;
837 void SlotTracker::processFunctionMetadata(
const Function &
F) {
840 F.getAllMetadata(MDs);
842 CreateMetadataSlot(MD.second);
845 processInstructionMetadata(I);
849 void SlotTracker::processInstructionMetadata(
const Instruction &I) {
851 if (
const CallInst *CI = dyn_cast<CallInst>(&I))
852 if (
Function *F = CI->getCalledFunction())
853 if (F->isIntrinsic())
855 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
856 if (
MDNode *
N = dyn_cast<MDNode>(V->getMetadata()))
857 CreateMetadataSlot(
N);
863 CreateMetadataSlot(MD.second);
872 TheFunction =
nullptr;
873 FunctionProcessed =
false;
884 return MI == mMap.
end() ? -1 : (
int)MI->second;
894 return MI == mdnMap.end() ? -1 : (
int)MI->second;
900 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
906 return FI == fMap.
end() ? -1 : (
int)FI->second;
915 return AI == asMap.
end() ? -1 : (
int)AI->second;
919 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
920 assert(V &&
"Can't insert a null Value into SlotTracker!");
922 assert(!V->
hasName() &&
"Doesn't need a slot!");
924 unsigned DestSlot = mNext++;
927 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
930 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
931 (isa<Function>(V) ?
'F' :
932 (isa<GlobalAlias>(V) ?
'A' :
'o'))) <<
"]\n");
936 void SlotTracker::CreateFunctionSlot(
const Value *V) {
939 unsigned DestSlot = fNext++;
943 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
944 DestSlot <<
" [o]\n");
948 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
949 assert(N &&
"Can't insert a null Value into SlotTracker!");
951 unsigned DestSlot = mdnNext;
952 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
959 CreateMetadataSlot(Op);
962 void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
964 "Doesn't need a slot!");
967 if (I != asMap.
end())
970 unsigned DestSlot = asNext++;
971 asMap[AS] = DestSlot;
979 TypePrinting *TypePrinter,
984 TypePrinting *TypePrinter,
986 bool FromValue =
false);
989 const char *
pred =
"unknown";
1024 default: Out <<
" <unknown operation " << Op <<
">";
break;
1042 if (
FPO->hasUnsafeAlgebra())
1045 if (
FPO->hasNoNaNs())
1047 if (
FPO->hasNoInfs())
1049 if (
FPO->hasNoSignedZeros())
1051 if (
FPO->hasAllowReciprocal())
1057 dyn_cast<OverflowingBinaryOperator>(U)) {
1058 if (OBO->hasNoUnsignedWrap())
1060 if (OBO->hasNoSignedWrap())
1063 dyn_cast<PossiblyExactOperator>(U)) {
1067 if (
GEP->isInBounds())
1073 TypePrinting &TypePrinter,
1076 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1077 if (CI->getType()->isIntegerTy(1)) {
1078 Out << (CI->getZExtValue() ?
"true" :
"false");
1081 Out << CI->getValue();
1085 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1096 bool isInf = CFP->getValueAPF().isInfinity();
1097 bool isNaN = CFP->getValueAPF().isNaN();
1098 if (!isHalf && !isInf && !isNaN) {
1099 double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
1100 CFP->getValueAPF().convertToFloat();
1108 if ((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
1109 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
1110 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) {
1122 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
1123 "assuming that double is 64 bits!");
1125 APFloat apf = CFP->getValueAPF();
1146 APInt api = CFP->getValueAPF().bitcastToAPInt();
1148 uint64_t word = p[1];
1151 for (
int j=0; j<width; j+=4, shiftcount-=4) {
1152 unsigned int nibble = (word>>shiftcount) & 15;
1154 Out << (
unsigned char)(nibble +
'0');
1156 Out << (
unsigned char)(nibble - 10 +
'A');
1157 if (shiftcount == 0 && j+4 < width) {
1161 shiftcount = width-j-4;
1177 APInt api = CFP->getValueAPF().bitcastToAPInt();
1181 for (
int j=0; j<width; j+=4, shiftcount-=4) {
1182 unsigned int nibble = (word>>shiftcount) & 15;
1184 Out << (
unsigned char)(nibble +
'0');
1186 Out << (
unsigned char)(nibble - 10 +
'A');
1187 if (shiftcount == 0 && j+4 < width) {
1191 shiftcount = width-j-4;
1197 if (isa<ConstantAggregateZero>(CV)) {
1198 Out <<
"zeroinitializer";
1202 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1203 Out <<
"blockaddress(";
1213 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1214 Type *ETy = CA->getType()->getElementType();
1216 TypePrinter.print(ETy, Out);
1221 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1223 TypePrinter.print(ETy, Out);
1235 if (CA->isString()) {
1242 Type *ETy = CA->getType()->getElementType();
1244 TypePrinter.print(ETy, Out);
1249 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1251 TypePrinter.print(ETy, Out);
1262 if (
CS->getType()->isPacked())
1265 unsigned N =
CS->getNumOperands();
1268 TypePrinter.print(
CS->getOperand(0)->getType(), Out);
1274 for (
unsigned i = 1; i <
N; i++) {
1276 TypePrinter.print(
CS->getOperand(i)->getType(), Out);
1286 if (
CS->getType()->isPacked())
1291 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1294 TypePrinter.print(ETy, Out);
1300 TypePrinter.print(ETy, Out);
1309 if (isa<ConstantPointerNull>(CV)) {
1314 if (isa<UndefValue>(CV)) {
1319 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1320 Out << CE->getOpcodeName();
1321 WriteOptimizationInfo(Out, CE);
1322 if (CE->isCompare())
1323 Out << ' ' << getPredicateText(CE->getPredicate());
1326 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) {
1328 cast<PointerType>(GEP->getPointerOperandType()->getScalarType())
1334 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1335 TypePrinter.print((*OI)->getType(), Out);
1337 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
1338 if (OI+1 != CE->op_end())
1342 if (CE->hasIndices()) {
1343 ArrayRef<unsigned> Indices = CE->getIndices();
1344 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1345 Out << ", " << Indices[i];
1350 TypePrinter.print(CE->getType(), Out);
1357 Out << "<placeholder or erroneous Constant>";
1360 static void writeMDTuple(raw_ostream &Out, const MDTuple *Node,
1361 TypePrinting *TypePrinter, SlotTracker *Machine,
1362 const Module *Context) {
1364 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
1365 const Metadata *MD = Node->getOperand(mi);
1368 else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1369 Value *V = MDV->getValue();
1370 TypePrinter->print(V->getType(), Out);
1372 WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context);
1374 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context);
1384 struct FieldSeparator {
1387 FieldSeparator(const char *Sep = ", ") : Skip(true), Sep(Sep) {}
1389 raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) {
1394 return OS << FS.Sep;
1396 struct MDFieldPrinter {
1399 TypePrinting *TypePrinter;
1400 SlotTracker *Machine;
1401 const Module *Context;
1403 explicit MDFieldPrinter(raw_ostream &Out)
1404 : Out(Out), TypePrinter(nullptr), Machine(nullptr), Context(nullptr) {}
1405 MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter,
1406 SlotTracker *Machine, const Module *Context)
1407 : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) {
1409 void printTag(const DINode *N);
1410 void printString(StringRef Name, StringRef Value,
1411 bool ShouldSkipEmpty = true);
1412 void printMetadata(StringRef Name, const Metadata *MD,
1413 bool ShouldSkipNull = true);
1414 template <class IntTy>
1415 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true);
1416 void printBool(StringRef Name, bool Value);
1417 void printDIFlags(StringRef Name, unsigned Flags);
1418 template <class IntTy, class Stringifier>
1419 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString,
1420 bool ShouldSkipZero = true);
1424 void MDFieldPrinter::printTag(const DINode *N) {
1425 Out << FS << "tag: ";
1426 if (const char *Tag = dwarf::TagString(N->getTag()))
1432 void MDFieldPrinter::printString(StringRef Name, StringRef Value,
1433 bool ShouldSkipEmpty) {
1434 if (ShouldSkipEmpty && Value.empty())
1437 Out << FS << Name << ": \"";
1438 PrintEscapedString(Value, Out);
1442 static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD,
1443 TypePrinting *TypePrinter,
1444 SlotTracker *Machine,
1445 const Module *Context) {
1450 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context);
1453 void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD,
1454 bool ShouldSkipNull) {
1455 if (ShouldSkipNull && !MD)
1458 Out << FS << Name << ": ";
1459 writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context);
1462 template <class IntTy>
1463 void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) {
1464 if (ShouldSkipZero && !Int)
1467 Out << FS << Name << ": " << Int;
1470 void MDFieldPrinter::printBool(StringRef Name, bool Value) {
1471 Out << FS << Name << ": " << (Value ? "true" : "false");
1474 void MDFieldPrinter::printDIFlags(StringRef Name, unsigned Flags) {
1478 Out << FS << Name << ": ";
1480 SmallVector<unsigned, 8> SplitFlags;
1481 unsigned Extra = DINode::splitFlags(Flags, SplitFlags);
1483 FieldSeparator FlagsFS(" | ");
1484 for (unsigned F : SplitFlags) {
1485 const char *StringF = DINode::getFlagString(F);
1486 assert(StringF && "Expected valid flag");
1487 Out << FlagsFS << StringF;
1489 if (Extra || SplitFlags.empty())
1490 Out << FlagsFS << Extra;
1493 template <class IntTy, class Stringifier>
1494 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
1495 Stringifier toString, bool ShouldSkipZero) {
1499 Out << FS << Name << ": ";
1500 if (const char *S = toString(Value))
1506 static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N,
1507 TypePrinting *TypePrinter, SlotTracker *Machine,
1508 const Module *Context) {
1509 Out << "!GenericDINode(";
1510 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1511 Printer.printTag(N);
1512 Printer.printString("header", N->getHeader());
1513 if (N->getNumDwarfOperands()) {
1514 Out << Printer.FS << "operands: {";
1516 for (auto &I : N->dwarf_operands()) {
1518 writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context);
1525 static void writeDILocation(raw_ostream &Out, const DILocation *DL,
1526 TypePrinting *TypePrinter, SlotTracker *Machine,
1527 const Module *Context) {
1528 Out << "!DILocation(";
1529 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1530 // Always output the line, since 0 is a relevant and important value for it.
1531 Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false);
1532 Printer.printInt("column", DL->getColumn());
1533 Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false);
1534 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());
1538 static void writeDISubrange(raw_ostream &Out, const DISubrange *N,
1539 TypePrinting *, SlotTracker *, const Module *) {
1540 Out << "!DISubrange(";
1541 MDFieldPrinter Printer(Out);
1542 Printer.printInt("count", N->getCount(), /* ShouldSkipZero */ false);
1543 Printer.printInt("lowerBound", N->getLowerBound());
1547 static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N,
1548 TypePrinting *, SlotTracker *, const Module *) {
1549 Out << "!DIEnumerator(";
1550 MDFieldPrinter Printer(Out);
1551 Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false);
1552 Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false);
1556 static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
1557 TypePrinting *, SlotTracker *, const Module *) {
1558 Out << "!DIBasicType(";
1559 MDFieldPrinter Printer(Out);
1560 if (N->getTag() != dwarf::DW_TAG_base_type)
1561 Printer.printTag(N);
1562 Printer.printString("name", N->getName());
1563 Printer.printInt("size", N->getSizeInBits());
1564 Printer.printInt("align", N->getAlignInBits());
1565 Printer.printDwarfEnum("encoding", N->getEncoding(),
1566 dwarf::AttributeEncodingString);
1570 static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N,
1571 TypePrinting *TypePrinter, SlotTracker *Machine,
1572 const Module *Context) {
1573 Out << "!DIDerivedType(";
1574 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1575 Printer.printTag(N);
1576 Printer.printString("name", N->getName());
1577 Printer.printMetadata("scope", N->getRawScope());
1578 Printer.printMetadata("file", N->getRawFile());
1579 Printer.printInt("line", N->getLine());
1580 Printer.printMetadata("baseType", N->getRawBaseType(),
1581 /* ShouldSkipNull */ false);
1582 Printer.printInt("size", N->getSizeInBits());
1583 Printer.printInt("align", N->getAlignInBits());
1584 Printer.printInt("offset", N->getOffsetInBits());
1585 Printer.printDIFlags("flags", N->getFlags());
1586 Printer.printMetadata("extraData", N->getRawExtraData());
1590 static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
1591 TypePrinting *TypePrinter,
1592 SlotTracker *Machine, const Module *Context) {
1593 Out << "!DICompositeType(";
1594 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1595 Printer.printTag(N);
1596 Printer.printString("name", N->getName());
1597 Printer.printMetadata("scope", N->getRawScope());
1598 Printer.printMetadata("file", N->getRawFile());
1599 Printer.printInt("line", N->getLine());
1600 Printer.printMetadata("baseType", N->getRawBaseType());
1601 Printer.printInt("size", N->getSizeInBits());
1602 Printer.printInt("align", N->getAlignInBits());
1603 Printer.printInt("offset", N->getOffsetInBits());
1604 Printer.printDIFlags("flags", N->getFlags());
1605 Printer.printMetadata("elements", N->getRawElements());
1606 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(),
1607 dwarf::LanguageString);
1608 Printer.printMetadata("vtableHolder", N->getRawVTableHolder());
1609 Printer.printMetadata("templateParams", N->getRawTemplateParams());
1610 Printer.printString("identifier", N->getIdentifier());
1614 static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N,
1615 TypePrinting *TypePrinter,
1616 SlotTracker *Machine, const Module *Context) {
1617 Out << "!DISubroutineType(";
1618 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1619 Printer.printDIFlags("flags", N->getFlags());
1620 Printer.printMetadata("types", N->getRawTypeArray(),
1621 /* ShouldSkipNull */ false);
1625 static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *,
1626 SlotTracker *, const Module *) {
1628 MDFieldPrinter Printer(Out);
1629 Printer.printString("filename", N->getFilename(),
1630 /* ShouldSkipEmpty */ false);
1631 Printer.printString("directory", N->getDirectory(),
1632 /* ShouldSkipEmpty */ false);
1636 static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
1637 TypePrinting *TypePrinter, SlotTracker *Machine,
1638 const Module *Context) {
1639 Out << "!DICompileUnit(";
1640 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1641 Printer.printDwarfEnum("language", N->getSourceLanguage(),
1642 dwarf::LanguageString, /* ShouldSkipZero */ false);
1643 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
1644 Printer.printString("producer", N->getProducer());
1645 Printer.printBool("isOptimized", N->isOptimized());
1646 Printer.printString("flags", N->getFlags());
1647 Printer.printInt("runtimeVersion", N->getRuntimeVersion(),
1648 /* ShouldSkipZero */ false);
1649 Printer.printString("splitDebugFilename", N->getSplitDebugFilename());
1650 Printer.printInt("emissionKind", N->getEmissionKind(),
1651 /* ShouldSkipZero */ false);
1652 Printer.printMetadata("enums", N->getRawEnumTypes());
1653 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes());
1654 Printer.printMetadata("subprograms", N->getRawSubprograms());
1655 Printer.printMetadata("globals", N->getRawGlobalVariables());
1656 Printer.printMetadata("imports", N->getRawImportedEntities());
1657 Printer.printInt("dwoId", N->getDWOId());
1661 static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N,
1662 TypePrinting *TypePrinter, SlotTracker *Machine,
1663 const Module *Context) {
1664 Out << "!DISubprogram(";
1665 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1666 Printer.printString("name", N->getName());
1667 Printer.printString("linkageName", N->getLinkageName());
1668 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1669 Printer.printMetadata("file", N->getRawFile());
1670 Printer.printInt("line", N->getLine());
1671 Printer.printMetadata("type", N->getRawType());
1672 Printer.printBool("isLocal", N->isLocalToUnit());
1673 Printer.printBool("isDefinition", N->isDefinition());
1674 Printer.printInt("scopeLine", N->getScopeLine());
1675 Printer.printMetadata("containingType", N->getRawContainingType());
1676 Printer.printDwarfEnum("virtuality", N->getVirtuality(),
1677 dwarf::VirtualityString);
1678 Printer.printInt("virtualIndex", N->getVirtualIndex());
1679 Printer.printDIFlags("flags", N->getFlags());
1680 Printer.printBool("isOptimized", N->isOptimized());
1681 Printer.printMetadata("function", N->getRawFunction());
1682 Printer.printMetadata("templateParams", N->getRawTemplateParams());
1683 Printer.printMetadata("declaration", N->getRawDeclaration());
1684 Printer.printMetadata("variables", N->getRawVariables());
1688 static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N,
1689 TypePrinting *TypePrinter, SlotTracker *Machine,
1690 const Module *Context) {
1691 Out << "!DILexicalBlock(";
1692 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1693 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1694 Printer.printMetadata("file", N->getRawFile());
1695 Printer.printInt("line", N->getLine());
1696 Printer.printInt("column", N->getColumn());
1700 static void writeDILexicalBlockFile(raw_ostream &Out,
1701 const DILexicalBlockFile *N,
1702 TypePrinting *TypePrinter,
1703 SlotTracker *Machine,
1704 const Module *Context) {
1705 Out << "!DILexicalBlockFile(";
1706 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1707 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1708 Printer.printMetadata("file", N->getRawFile());
1709 Printer.printInt("discriminator", N->getDiscriminator(),
1710 /* ShouldSkipZero */ false);
1714 static void writeDINamespace(raw_ostream &Out, const DINamespace *N,
1715 TypePrinting *TypePrinter, SlotTracker *Machine,
1716 const Module *Context) {
1717 Out << "!DINamespace(";
1718 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1719 Printer.printString("name", N->getName());
1720 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1721 Printer.printMetadata("file", N->getRawFile());
1722 Printer.printInt("line", N->getLine());
1726 static void writeDIModule(raw_ostream &Out, const DIModule *N,
1727 TypePrinting *TypePrinter, SlotTracker *Machine,
1728 const Module *Context) {
1729 Out << "!DIModule(";
1730 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1731 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1732 Printer.printString("name", N->getName());
1733 Printer.printString("configMacros", N->getConfigurationMacros());
1734 Printer.printString("includePath", N->getIncludePath());
1735 Printer.printString("isysroot", N->getISysRoot());
1740 static void writeDITemplateTypeParameter(raw_ostream &Out,
1741 const DITemplateTypeParameter *N,
1742 TypePrinting *TypePrinter,
1743 SlotTracker *Machine,
1744 const Module *Context) {
1745 Out << "!DITemplateTypeParameter(";
1746 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1747 Printer.printString("name", N->getName());
1748 Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false);
1752 static void writeDITemplateValueParameter(raw_ostream &Out,
1753 const DITemplateValueParameter *N,
1754 TypePrinting *TypePrinter,
1755 SlotTracker *Machine,
1756 const Module *Context) {
1757 Out << "!DITemplateValueParameter(";
1758 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1759 if (N->getTag() != dwarf::DW_TAG_template_value_parameter)
1760 Printer.printTag(N);
1761 Printer.printString("name", N->getName());
1762 Printer.printMetadata("type", N->getRawType());
1763 Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false);
1767 static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N,
1768 TypePrinting *TypePrinter,
1769 SlotTracker *Machine, const Module *Context) {
1770 Out << "!DIGlobalVariable(";
1771 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1772 Printer.printString("name", N->getName());
1773 Printer.printString("linkageName", N->getLinkageName());
1774 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1775 Printer.printMetadata("file", N->getRawFile());
1776 Printer.printInt("line", N->getLine());
1777 Printer.printMetadata("type", N->getRawType());
1778 Printer.printBool("isLocal", N->isLocalToUnit());
1779 Printer.printBool("isDefinition", N->isDefinition());
1780 Printer.printMetadata("variable", N->getRawVariable());
1781 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration());
1785 static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N,
1786 TypePrinting *TypePrinter,
1787 SlotTracker *Machine, const Module *Context) {
1788 Out << "!DILocalVariable(";
1789 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1790 Printer.printTag(N);
1791 Printer.printString("name", N->getName());
1792 Printer.printInt("arg", N->getArg(),
1793 /* ShouldSkipZero */
1794 N->getTag() == dwarf::DW_TAG_auto_variable);
1795 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1796 Printer.printMetadata("file", N->getRawFile());
1797 Printer.printInt("line", N->getLine());
1798 Printer.printMetadata("type", N->getRawType());
1799 Printer.printDIFlags("flags", N->getFlags());
1803 static void writeDIExpression(raw_ostream &Out, const DIExpression *N,
1804 TypePrinting *TypePrinter, SlotTracker *Machine,
1805 const Module *Context) {
1806 Out << "!DIExpression(";
1809 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) {
1810 const char *OpStr = dwarf::OperationEncodingString(I->getOp());
1811 assert(OpStr && "Expected valid opcode");
1814 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A)
1815 Out << FS << I->getArg(A);
1818 for (const auto &I : N->getElements())
1824 static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N,
1825 TypePrinting *TypePrinter, SlotTracker *Machine,
1826 const Module *Context) {
1827 Out << "!DIObjCProperty(";
1828 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1829 Printer.printString("name", N->getName());
1830 Printer.printMetadata("file", N->getRawFile());
1831 Printer.printInt("line", N->getLine());
1832 Printer.printString("setter", N->getSetterName());
1833 Printer.printString("getter", N->getGetterName());
1834 Printer.printInt("attributes", N->getAttributes());
1835 Printer.printMetadata("type", N->getRawType());
1839 static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N,
1840 TypePrinting *TypePrinter,
1841 SlotTracker *Machine, const Module *Context) {
1842 Out << "!DIImportedEntity(";
1843 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1844 Printer.printTag(N);
1845 Printer.printString("name", N->getName());
1846 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1847 Printer.printMetadata("entity", N->getRawEntity());
1848 Printer.printInt("line", N->getLine());
1853 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
1854 TypePrinting *TypePrinter,
1855 SlotTracker *Machine,
1856 const Module *Context) {
1857 if (Node->isDistinct())
1859 else if (Node->isTemporary())
1860 Out << "<temporary!> "; // Handle broken code.
1862 switch (Node->getMetadataID()) {
1864 llvm_unreachable("Expected uniquable MDNode");
1865 #define HANDLE_MDNODE_LEAF(CLASS) \
1866 case Metadata::CLASS##Kind: \
1867 write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \
1869 #include "llvm/IR/Metadata.def"
1873 // Full implementation of printing a Value as an operand with support for
1874 // TypePrinting, etc.
1875 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1876 TypePrinting *TypePrinter,
1877 SlotTracker *Machine,
1878 const Module *Context) {
1880 PrintLLVMName(Out, V);
1884 const Constant *CV = dyn_cast<Constant>(V);
1885 if (CV && !isa<GlobalValue>(CV)) {
1886 assert(TypePrinter && "Constants require TypePrinting!");
1887 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
1891 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1893 if (IA->hasSideEffects())
1894 Out << "sideeffect ";
1895 if (IA->isAlignStack())
1896 Out << "alignstack ";
1897 // We don't emit the AD_ATT dialect as it
's the assumed default.
1898 if (IA->getDialect() == InlineAsm::AD_Intel)
1899 Out << "inteldialect ";
1901 PrintEscapedString(IA->getAsmString(), Out);
1908 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1918 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1919 Slot = Machine->getGlobalSlot(GV);
1922 Slot = Machine->getLocalSlot(V);
1929 Slot = Machine->getLocalSlot(V);
1935 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1936 Slot = Machine->getGlobalSlot(GV);
1939 Slot = Machine->getLocalSlot(V);
1948 Out << Prefix << Slot;
1954 TypePrinting *TypePrinter,
1957 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
1958 std::unique_ptr<SlotTracker> MachineStorage;
1960 MachineStorage = make_unique<SlotTracker>(Context);
1961 Machine = MachineStorage.get();
1967 Out <<
"<" << N <<
">";
1973 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
1980 auto *V = cast<ValueAsMetadata>(MD);
1981 assert(TypePrinter &&
"TypePrinter required for metadata values");
1982 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
1983 "Unexpected function-local metadata outside of value argument");
1985 TypePrinter->print(V->getValue()->
getType(), Out);
1991 class AssemblyWriter {
1994 std::unique_ptr<SlotTracker> SlotTrackerStorage;
1996 TypePrinting TypePrinter;
1999 bool ShouldPreserveUseListOrder;
2007 bool ShouldPreserveUseListOrder =
false);
2012 bool ShouldPreserveUseListOrder =
false);
2014 void printMDNodeBody(
const MDNode *MD);
2017 void printModule(
const Module *M);
2019 void writeOperand(
const Value *Op,
bool PrintType);
2026 void writeAllMDNodes();
2027 void writeMDNode(
unsigned Slot,
const MDNode *Node);
2028 void writeAllAttributeGroups();
2030 void printTypeIdentities();
2033 void printComdat(
const Comdat *
C);
2034 void printFunction(
const Function *F);
2041 void printUseLists(
const Function *F);
2047 void printMetadataAttachments(
2053 void printInfoComment(
const Value &V);
2057 void printGCRelocateComment(
const Value &V);
2064 TypePrinter.incorporateTypes(*TheModule);
2065 for (
const Function &F : *TheModule)
2066 if (
const Comdat *C = F.getComdat())
2069 if (
const Comdat *C = GV.getComdat())
2075 bool ShouldPreserveUseListOrder)
2076 : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW),
2077 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2083 bool ShouldPreserveUseListOrder)
2085 Machine(*SlotTrackerStorage), AnnotationWriter(AAW),
2086 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2090 void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2092 Out <<
"<null operand!>";
2096 TypePrinter.print(Operand->
getType(), Out);
2107 switch (SynchScope) {
2113 default: Out <<
" <bad ordering " <<
int(Ordering) <<
">";
break;
2114 case Unordered: Out <<
" unordered";
break;
2115 case Monotonic: Out <<
" monotonic";
break;
2116 case Acquire: Out <<
" acquire";
break;
2117 case Release: Out <<
" release";
break;
2123 void AssemblyWriter::writeAtomicCmpXchg(
AtomicOrdering SuccessOrdering,
2128 switch (SynchScope) {
2133 switch (SuccessOrdering) {
2134 default: Out <<
" <bad ordering " <<
int(SuccessOrdering) <<
">";
break;
2135 case Unordered: Out <<
" unordered";
break;
2136 case Monotonic: Out <<
" monotonic";
break;
2137 case Acquire: Out <<
" acquire";
break;
2138 case Release: Out <<
" release";
break;
2143 switch (FailureOrdering) {
2144 default: Out <<
" <bad ordering " <<
int(FailureOrdering) <<
">";
break;
2145 case Unordered: Out <<
" unordered";
break;
2146 case Monotonic: Out <<
" monotonic";
break;
2147 case Acquire: Out <<
" acquire";
break;
2148 case Release: Out <<
" release";
break;
2154 void AssemblyWriter::writeParamOperand(
const Value *Operand,
2157 Out <<
"<null operand!>";
2162 TypePrinter.print(Operand->
getType(), Out);
2171 void AssemblyWriter::printModule(
const Module *M) {
2172 Machine.initialize();
2174 if (ShouldPreserveUseListOrder)
2185 Out <<
"target datalayout = \"" << DL <<
"\"\n";
2196 std::tie(Front, Asm) = Asm.
split(
'\n');
2200 Out <<
"module asm \"";
2203 }
while (!Asm.
empty());
2206 printTypeIdentities();
2209 if (!Comdats.empty())
2211 for (
const Comdat *
C : Comdats) {
2213 if (
C != Comdats.back())
2220 printGlobal(&GV); Out <<
'\n';
2229 printUseLists(
nullptr);
2234 assert(UseListOrders.empty() &&
"All use-lists should have been consumed");
2237 if (!Machine.as_empty()) {
2239 writeAllAttributeGroups();
2243 if (!M->named_metadata_empty()) Out <<
'\n';
2245 for (
const NamedMDNode &Node : M->named_metadata())
2246 printNamedMDNode(&Node);
2249 if (!Machine.mdn_empty()) {
2258 Out <<
"<empty name> ";
2260 if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] ==
'-' ||
2261 Name[0] ==
'$' || Name[0] ==
'.' || Name[0] ==
'_')
2264 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
2265 for (
unsigned i = 1, e = Name.
size(); i != e; ++i) {
2266 unsigned char C = Name[i];
2267 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
2268 C ==
'.' || C ==
'_')
2271 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
2276 void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
2283 int Slot = Machine.getMetadataSlot(NMD->
getOperand(i));
2295 case GlobalValue::ExternalLinkage:
break;
2296 case GlobalValue::PrivateLinkage: Out <<
"private ";
break;
2297 case GlobalValue::InternalLinkage: Out <<
"internal ";
break;
2298 case GlobalValue::LinkOnceAnyLinkage: Out <<
"linkonce ";
break;
2299 case GlobalValue::LinkOnceODRLinkage: Out <<
"linkonce_odr ";
break;
2300 case GlobalValue::WeakAnyLinkage: Out <<
"weak ";
break;
2301 case GlobalValue::WeakODRLinkage: Out <<
"weak_odr ";
break;
2302 case GlobalValue::CommonLinkage: Out <<
"common ";
break;
2303 case GlobalValue::AppendingLinkage: Out <<
"appending ";
break;
2304 case GlobalValue::ExternalWeakLinkage: Out <<
"extern_weak ";
break;
2305 case GlobalValue::AvailableExternallyLinkage:
2306 Out <<
"available_externally ";
2314 case GlobalValue::DefaultVisibility:
break;
2315 case GlobalValue::HiddenVisibility: Out <<
"hidden ";
break;
2316 case GlobalValue::ProtectedVisibility: Out <<
"protected ";
break;
2323 case GlobalValue::DefaultStorageClass:
break;
2324 case GlobalValue::DLLImportStorageClass: Out <<
"dllimport ";
break;
2325 case GlobalValue::DLLExportStorageClass: Out <<
"dllexport ";
break;
2332 case GlobalVariable::NotThreadLocal:
2334 case GlobalVariable::GeneralDynamicTLSModel:
2335 Out <<
"thread_local ";
2337 case GlobalVariable::LocalDynamicTLSModel:
2338 Out <<
"thread_local(localdynamic) ";
2340 case GlobalVariable::InitialExecTLSModel:
2341 Out <<
"thread_local(initialexec) ";
2343 case GlobalVariable::LocalExecTLSModel:
2344 Out <<
"thread_local(localexec) ";
2355 if (isa<GlobalVariable>(GO))
2369 Out <<
"; Materializable\n";
2382 Out <<
"unnamed_addr ";
2387 Out << (GV->
isConstant() ?
"constant " :
"global ");
2396 Out <<
", section \"";
2404 printInfoComment(*GV);
2407 void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
2409 Out <<
"; Materializable\n";
2419 Out <<
"unnamed_addr ";
2426 TypePrinter.print(GA->
getType(), Out);
2427 Out <<
" <<NULL ALIASEE>>";
2429 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
2432 printInfoComment(*GA);
2436 void AssemblyWriter::printComdat(
const Comdat *
C) {
2440 void AssemblyWriter::printTypeIdentities() {
2441 if (TypePrinter.NumberedTypes.empty() &&
2442 TypePrinter.NamedTypes.empty())
2449 std::vector<StructType*> NumberedTypes(TypePrinter.NumberedTypes.size());
2451 TypePrinter.NumberedTypes.begin(), E = TypePrinter.NumberedTypes.end();
2453 assert(I->second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
2454 NumberedTypes[I->second] = I->first;
2458 for (
unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
2459 Out <<
'%' << i <<
" = type ";
2463 TypePrinter.printStructBody(NumberedTypes[i], Out);
2467 for (
unsigned i = 0, e = TypePrinter.NamedTypes.size(); i != e; ++i) {
2473 TypePrinter.printStructBody(TypePrinter.NamedTypes[i], Out);
2480 void AssemblyWriter::printFunction(
const Function *F) {
2484 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
2487 Out <<
"; Materializable\n";
2492 std::string AttrStr;
2495 for (
unsigned E = AS.
getNumSlots(); Idx != E; ++Idx)
2496 if (AS.
getSlotIndex(Idx) == AttributeSet::FunctionIndex)
2503 if (!AttrStr.empty()) AttrStr +=
' ';
2508 if (!AttrStr.empty())
2509 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
2529 Out << Attrs.
getAsString(AttributeSet::ReturnIndex) <<
' ';
2534 Machine.incorporateFunction(F);
2545 printArgument(I, Attrs, Idx);
2550 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
2569 Out <<
" unnamed_addr";
2571 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
2573 Out <<
" section \"";
2581 Out <<
" gc \"" << F->
getGC() <<
'"';
2587 Out <<
" prologue ";
2591 Out <<
" personality ";
2597 printMetadataAttachments(MDs,
" ");
2613 Machine.purgeFunction();
2619 void AssemblyWriter::printArgument(
const Argument *Arg,
2622 TypePrinter.print(Arg->
getType(), Out);
2637 void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
2643 Out <<
"\n; <label>:";
2644 int Slot = Machine.getLocalSlot(BB);
2652 Out.PadToColumn(50);
2653 Out <<
"; Error: Block without parent!";
2656 Out.PadToColumn(50);
2661 Out <<
" No predecessors!";
2664 writeOperand(*PI,
false);
2665 for (++PI; PI != PE; ++PI) {
2667 writeOperand(*PI,
false);
2674 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
2678 printInstructionLine(*I);
2681 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
2685 void AssemblyWriter::printInstructionLine(
const Instruction &I) {
2686 printInstruction(I);
2692 void AssemblyWriter::printGCRelocateComment(
const Value &V) {
2697 writeOperand(GCOps.getBasePtr(),
false);
2699 writeOperand(GCOps.getDerivedPtr(),
false);
2706 void AssemblyWriter::printInfoComment(
const Value &V) {
2708 printGCRelocateComment(V);
2710 if (AnnotationWriter)
2711 AnnotationWriter->printInfoComment(V, Out);
2715 void AssemblyWriter::printInstruction(
const Instruction &I) {
2716 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
2727 int SlotNum = Machine.getLocalSlot(&I);
2729 Out <<
"<badref> = ";
2731 Out <<
'%' << SlotNum <<
" = ";
2734 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
2735 if (CI->isMustTailCall())
2737 else if (CI->isTailCall())
2745 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
2746 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
2749 if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isWeak())
2753 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isVolatile()) ||
2754 (isa<StoreInst>(I) && cast<StoreInst>(I).
isVolatile()) ||
2755 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isVolatile()) ||
2756 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).
isVolatile()))
2763 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
2767 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
2774 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
2777 writeOperand(BI.getCondition(),
true);
2779 writeOperand(BI.getSuccessor(0),
true);
2781 writeOperand(BI.getSuccessor(1),
true);
2783 }
else if (isa<SwitchInst>(I)) {
2787 writeOperand(
SI.getCondition(),
true);
2789 writeOperand(
SI.getDefaultDest(),
true);
2794 writeOperand(i.getCaseValue(),
true);
2796 writeOperand(i.getCaseSuccessor(),
true);
2799 }
else if (isa<IndirectBrInst>(I)) {
2802 writeOperand(Operand,
true);
2811 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
2813 TypePrinter.print(I.
getType(), Out);
2816 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
2817 if (
op) Out <<
", ";
2819 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
2820 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
2825 for (
const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
2827 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
2829 writeOperand(I.
getOperand(0),
true); Out <<
", ";
2831 for (
const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
2833 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
2835 TypePrinter.print(I.
getType(), Out);
2836 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
2839 if (LPI->isCleanup())
2842 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
2843 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
2844 if (LPI->isCatch(i))
2849 writeOperand(LPI->getClause(i),
true);
2851 }
else if (isa<ReturnInst>(I) && !Operand) {
2853 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
2860 Operand = CI->getCalledValue();
2861 FunctionType *FTy = cast<FunctionType>(CI->getFunctionType());
2866 Out <<
' ' << PAL.
getAsString(AttributeSet::ReturnIndex);
2873 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
2875 writeOperand(Operand,
false);
2877 for (
unsigned op = 0, Eop = CI->getNumArgOperands();
op < Eop; ++
op) {
2880 writeParamOperand(CI->getArgOperand(
op), PAL,
op + 1);
2885 if (CI->isMustTailCall() && CI->getParent() &&
2886 CI->getParent()->getParent() &&
2887 CI->getParent()->getParent()->isVarArg())
2893 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
2894 Operand = II->getCalledValue();
2895 FunctionType *FTy = cast<FunctionType>(II->getFunctionType());
2906 Out <<
' ' << PAL.
getAsString(AttributeSet::ReturnIndex);
2913 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
2915 writeOperand(Operand,
false);
2917 for (
unsigned op = 0, Eop = II->getNumArgOperands();
op < Eop; ++
op) {
2920 writeParamOperand(II->getArgOperand(
op), PAL,
op + 1);
2928 writeOperand(II->getNormalDest(),
true);
2930 writeOperand(II->getUnwindDest(),
true);
2932 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
2934 if (AI->isUsedWithInAlloca())
2936 TypePrinter.print(AI->getAllocatedType(), Out);
2942 if (!AI->getArraySize() || AI->isArrayAllocation() ||
2943 !AI->getArraySize()->getType()->isIntegerTy(32)) {
2945 writeOperand(AI->getArraySize(),
true);
2947 if (AI->getAlignment()) {
2948 Out <<
", align " << AI->getAlignment();
2950 }
else if (isa<CastInst>(I)) {
2953 writeOperand(Operand,
true);
2956 TypePrinter.print(I.
getType(), Out);
2957 }
else if (isa<VAArgInst>(I)) {
2960 writeOperand(Operand,
true);
2963 TypePrinter.print(I.
getType(), Out);
2964 }
else if (Operand) {
2965 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
2967 TypePrinter.print(
GEP->getSourceElementType(), Out);
2969 }
else if (
const auto *LI = dyn_cast<LoadInst>(&I)) {
2971 TypePrinter.print(LI->getType(), Out);
2978 bool PrintAllTypes =
false;
2982 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
2983 || isa<ReturnInst>(I)) {
2984 PrintAllTypes =
true;
2990 if (Operand && Operand->
getType() != TheType) {
2991 PrintAllTypes =
true;
2997 if (!PrintAllTypes) {
2999 TypePrinter.print(TheType, Out);
3005 writeOperand(I.
getOperand(i), PrintAllTypes);
3010 if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
3012 writeAtomic(LI->getOrdering(), LI->getSynchScope());
3013 if (LI->getAlignment())
3014 Out <<
", align " << LI->getAlignment();
3015 }
else if (
const StoreInst *
SI = dyn_cast<StoreInst>(&I)) {
3017 writeAtomic(
SI->getOrdering(),
SI->getSynchScope());
3018 if (
SI->getAlignment())
3019 Out <<
", align " <<
SI->getAlignment();
3021 writeAtomicCmpXchg(CXI->getSuccessOrdering(), CXI->getFailureOrdering(),
3022 CXI->getSynchScope());
3023 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
3024 writeAtomic(RMWI->getOrdering(), RMWI->getSynchScope());
3025 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
3026 writeAtomic(FI->getOrdering(), FI->getSynchScope());
3032 printMetadataAttachments(InstMD,
", ");
3035 printInfoComment(I);
3038 void AssemblyWriter::printMetadataAttachments(
3044 if (MDNames.empty())
3045 TheModule->getMDKindNames(MDNames);
3047 for (
const auto &I : MDs) {
3048 unsigned Kind = I.first;
3050 if (Kind < MDNames.size()) {
3054 Out <<
"!<unknown kind #" << Kind <<
">";
3060 void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
3061 Out <<
'!' << Slot <<
" = ";
3062 printMDNodeBody(Node);
3066 void AssemblyWriter::writeAllMDNodes() {
3068 Nodes.
resize(Machine.mdn_size());
3071 Nodes[I->second] = cast<MDNode>(I->first);
3073 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
3074 writeMDNode(i, Nodes[i]);
3078 void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
3082 void AssemblyWriter::writeAllAttributeGroups() {
3083 std::vector<std::pair<AttributeSet, unsigned> > asVec;
3084 asVec.resize(Machine.as_size());
3088 asVec[I->second] = *I;
3090 for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
3091 I = asVec.begin(), E = asVec.end(); I != E; ++
I)
3092 Out <<
"attributes #" << I->second <<
" = { "
3093 << I->first.getAsString(AttributeSet::FunctionIndex,
true) <<
" }\n";
3096 void AssemblyWriter::printUseListOrder(
const UseListOrder &Order) {
3097 bool IsInFunction = Machine.getFunction();
3101 Out <<
"uselistorder";
3103 IsInFunction ?
nullptr : dyn_cast<BasicBlock>(Order.
V)) {
3107 writeOperand(BB,
false);
3110 writeOperand(Order.
V,
true);
3114 assert(Order.
Shuffle.size() >= 2 &&
"Shuffle too small");
3116 for (
unsigned I = 1, E = Order.
Shuffle.size(); I != E; ++
I)
3117 Out <<
", " << Order.
Shuffle[I];
3121 void AssemblyWriter::printUseLists(
const Function *F) {
3123 [&]() {
return !UseListOrders.empty() && UseListOrders.back().F ==
F; };
3128 Out <<
"\n; uselistorder directives\n";
3130 printUseListOrder(UseListOrders.back());
3131 UseListOrders.pop_back();
3142 AssemblyWriter W(OS, SlotTable, this->
getParent(), AAW);
3143 W.printFunction(
this);
3147 bool ShouldPreserveUseListOrder)
const {
3150 AssemblyWriter W(OS, SlotTable,
this, AAW, ShouldPreserveUseListOrder);
3151 W.printModule(
this);
3157 AssemblyWriter W(OS, SlotTable,
getParent(),
nullptr);
3158 W.printNamedMDNode(
this);
3163 ROS <<
" = comdat ";
3170 ROS <<
"exactmatch";
3176 ROS <<
"noduplicates";
3188 TP.print(const_cast<Type*>(
this), OS);
3191 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
3194 TP.printStructBody(STy, OS);
3199 if (
const auto *CI = dyn_cast<CallInst>(&I))
3200 if (
Function *F = CI->getCalledFunction())
3203 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
3204 if (isa<MDNode>(V->getMetadata()))
3210 bool ShouldInitializeAllMetadata =
false;
3211 if (
auto *I = dyn_cast<Instruction>(
this))
3213 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
3214 ShouldInitializeAllMetadata =
true;
3222 SlotTracker EmptySlotTable(static_cast<const Module *>(
nullptr));
3225 auto incorporateFunction = [&](
const Function *
F) {
3230 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
3233 W.printInstruction(*I);
3234 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
3237 W.printBasicBlock(BB);
3238 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
3239 AssemblyWriter W(OS, SlotTable, GV->
getParent(),
nullptr);
3242 else if (
const Function *F = dyn_cast<Function>(GV))
3245 W.printAlias(cast<GlobalAlias>(GV));
3246 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
3248 }
else if (
const Constant *C = dyn_cast<Constant>(
this)) {
3249 TypePrinting TypePrinter;
3250 TypePrinter.print(C->getType(), OS);
3253 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
3265 if (V.
hasName() || isa<GlobalValue>(V) ||
3266 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
3275 TypePrinting TypePrinter;
3277 TypePrinter.incorporateTypes(*M);
3279 TypePrinter.print(V.
getType(), O);
3297 M, isa<MetadataAsValue>(
this));
3313 bool OnlyAsOperand) {
3316 TypePrinting TypePrinter;
3318 TypePrinter.incorporateTypes(*M);
3324 if (OnlyAsOperand || !N)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
StringRef getName() const
void push_back(const T &Elt)
LinkageTypes getLinkage() const
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
This class is the base class for the comparison instructions.
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
iterator_range< use_iterator > uses()
VisibilityTypes getVisibility() const
*p = old <signed v ? old : v
LLVM Argument representation.
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
Constant * getPrologueData() const
uint64_t getZExtValue() const
Get zero extended value.
static bool printWithoutType(const Value &V, raw_ostream &O, SlotTracker *Machine, const Module *M)
Print without a type, skipping the TypePrinting object.
size_t size() const
size - Get the string size.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
static const fltSemantics IEEEdouble
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
2: 32-bit floating point type
FenceInst - an instruction for ordering other memory operations.
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
static void writeAtomicRMWOperation(raw_ostream &Out, AtomicRMWInst::BinOp Op)
Type::subtype_iterator param_iterator
PTX_Device - Call to a PTX device function.
const char * getGC() const
CallInst - This class represents a function call, abstracting a target machine's calling convention...
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
*p = old <unsigned v ? old : v
0 1 0 0 True if ordered and less than
static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)
*p = old >unsigned v ? old : v
void initialize()
This function does the actual initialization.
iterator begin(unsigned Slot) const
1 1 1 0 True if unordered or not equal
The data referenced by the COMDAT must be the same size.
A raw_ostream that writes to an SmallVector or SmallString.
Type * getReturnType() const
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
const Function * getParent() const
Return the enclosing method, or null if none.
bool hasPrologueData() const
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
4: 80-bit floating point type (X87)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
LoadInst - an instruction for reading from memory.
Manage lifetime of a slot tracker for printing IR.
1: 16-bit floating point type
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
getAllMetadata - Get all metadata attached to this Instruction.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
*p = old >signed v ? old : v
const Constant * getAliasee() const
void print(raw_ostream &ROS) const
int getMetadataSlot(const MDNode *N)
getMetadataSlot - Get the slot number of a MDNode.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
SlotTracker * getMachine() const
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool isMaterializable() const
StringRef getName() const
Return a constant reference to the value's name.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
iterator begin()
Instruction iterator methods.
static void predictValueUseListOrder(const Value *V, const Function *F, OrderMap &OM, UseListOrderStack &Stack)
void print(raw_ostream &O) const
1 0 0 1 True if unordered or equal
BlockAddress - The address of a basic block.
static const fltSemantics x87DoubleExtended
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
std::vector< unsigned > Shuffle
static OrderMap orderModule(const Module *M)
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand)
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
param_iterator param_end() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isLiteral() const
isLiteral - Return true if this type is uniqued by structural equivalence, false if it is a struct de...
std::vector< UseListOrder > UseListOrderStack
0 1 0 1 True if ordered and less than or equal
The linker may choose any COMDAT.
static const fltSemantics IEEEquad
void print(raw_ostream &O) const
Implement operator<< on Value.
Type * getVectorElementType() const
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
StringRef getName() const
FunctionType - Class to represent function types.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BinOp
This enumeration lists the possible modifications atomicrmw can make.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
unsigned getAlignment() const
ArrayType - Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
PTX_Kernel - Call to a PTX kernel.
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source...
TypeID getTypeID() const
getTypeID - Return the type id for the type.
StoreInst - an instruction for storing to memory.
COFF::MachineTypes Machine
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
unsigned getNumElements() const
Return the number of elements in the Vector type.
Structure to hold a use-list order.
const char * getOpcodeName() const
Type * getElementType() const
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
PointerType - Class to represent pointers.
bool global_empty() const
10: Arbitrary bit width integers
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
This class provides computation of slot numbers for LLVM Assembly writing.
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
Type * getParamType(unsigned i) const
Parameter type accessors.
initializer< Ty > init(const Ty &Val)
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
bool isExternallyInitialized() const
No other Module may specify this COMDAT.
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
static const char * getPredicateText(unsigned predicate)
void dump() const
Dump the module to stderr (for debugging).
ConstantDataArray - An array constant whose element type is a simple 1/2/4/8-byte integer or float/do...
static void predictValueUseListOrderImpl(const Value *V, const Function *F, unsigned ID, const OrderMap &OM, UseListOrderStack &Stack)
LLVM Basic Block Representation.
static void PrintLinkage(GlobalValue::LinkageTypes LT, formatted_raw_ostream &Out)
The instances of the Type class are immutable: once they are created, they are never changed...
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
BranchInst - Conditional or Unconditional Branch instruction.
const Comdat * getComdat() const
This is an important base class in LLVM.
bool isGCRelocate(const Value *V)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
param_iterator param_begin() const
ConstantFP - Floating Point Values [float, double].
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool hasPersonalityFn() const
Get the personality function associated with this function.
iterator_range< named_metadata_iterator > named_metadata()
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed...
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
void print(raw_ostream &OS) const
uint64_t getNumElements() const
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
MDNode * getOperand(unsigned i) const
unsigned getBitWidth() const
Return the number of bits in the APInt.
static void PrintEscapedString(StringRef Name, raw_ostream &Out)
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
DLLStorageClassTypes
Storage classes of global values for PE targets.
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, ModuleSlotTracker &MST)
Interval::pred_iterator pred_end(Interval *I)
0 1 1 1 True if ordered (no nans)
SelectionKind getSelectionKind() const
static const Module * getModuleFromVal(const Value *V)
Wraps a call to a gc.relocate and provides access to it's operands.
The data referenced by the COMDAT must be the same.
Constant * getAggregateElement(unsigned Elt) const
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
1 1 1 1 Always true (always folded)
void incorporateFunction(const Function &F)
Incorporate the given function.
static bool isAtomic(Instruction *I)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
void dump() const
Support for debugging, callable in GDB: V->dump()
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix)
PrintLLVMName - Turn the specified name into an 'LLVM name', which is either prefixed with % (if the ...
reverse_iterator rbegin()
const char * getSection() const
0 0 1 0 True if ordered and greater than
bool hasExternalLinkage() const
const MDOperand & getOperand(unsigned I) const
static const fltSemantics PPCDoubleDouble
This is the shared class of boolean and integer constants.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
15: SIMD 'packed' format, or other vector type
unsigned getVectorNumElements() const
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Utility class for floating point operations which can have information about relaxed accuracy require...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, TypePrinting &TypePrinter, SlotTracker *Machine, const Module *Context)
iterator end(unsigned Slot) const
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all current metadata attachments.
virtual ~AssemblyAnnotationWriter()
The linker will choose the largest COMDAT.
X86_FastCall - 'fast' analog of X86_StdCall.
static bool isReferencingMDNode(const Instruction &I)
const BasicBlock & getEntryBlock() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
AttributeSet getAttributes() const
Return the attribute list for this Function.
static char * utohex_buffer(IntTy X, char *BufferEnd, bool LowerCase=false)
utohex_buffer - Emit the specified number into the buffer specified by BufferEnd, returning a pointer...
VectorType - Class to represent vector types.
bool hasInitializer() const
Definitions have initializers, declarations don't.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
static bool isWeak(const MCSymbolELF &Sym)
LinkageTypes
An enumeration for the kinds of linkage for global values.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
StringRef getName() const
getName - Return the name for this struct type if it has an identity.
iterator_range< user_iterator > users()
APInt bitcastToAPInt() const
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
static char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
ThreadLocalMode getThreadLocalMode() const
static SlotTracker * createSlotTracker(const Module *M)
static const uint16_t * lookup(unsigned opcode, unsigned domain)
PointerType * getType() const
Global values are always pointers.
static const fltSemantics IEEEsingle
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Constant * getPersonalityFn() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
unsigned greater or equal
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
static void orderValue(const Value *V, OrderMap &OM)
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
FunctionType * getFunctionType() const
Fast - This calling convention attempts to make calls as fast as possible (e.g.
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
0 1 1 0 True if ordered and operands are unequal
iterator find(const KeyT &Val)
X86_ThisCall - Similar to X86_StdCall.
bool hasPrefixData() const
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Constant * getPrefixData() const
1 0 1 0 True if unordered or greater than
const Module * getModule() const
This file defines passes to print out IR in various granularities.
3: 64-bit floating point type
SwitchInst - Multiway switch.
Type * getReturnType() const
const ARM::ArchExtKind Kind
0 0 0 1 True if ordered and equal
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool hasUnnamedAddr() const
1 0 1 1 True if unordered, greater than, or equal
A vector that has set insertion semantics.
DLLStorageClassTypes getDLLStorageClass() const
unsigned getNumOperands() const
The C convention as implemented on Windows/x86-64.
This class implements an extremely fast bulk output stream that can only output to a stream...
InvokeInst - Invoke instruction.
iterator_range< global_iterator > globals()
C - The default llvm calling convention, compatible with C.
StringRef - Represent a constant reference to a string, i.e.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
static bool isVolatile(Instruction *Inst)
9: MMX vectors (64 bits, X86 specific)
0 0 1 1 True if ordered and greater than or equal
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
static UseListOrderStack predictUseListOrder(const Module *M)
const BasicBlock * getParent() const
int getAttributeGroupSlot(AttributeSet AS)
0 0 0 0 Always false (always folded)
Module * getParent()
Get the module that holds this named metadata collection.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
bool empty() const
empty - Check if the string is empty.
5: 128-bit floating point type (112-bit mantissa)
iterator_range< alias_iterator > aliases()
AttributeSet getFnAttributes() const
The function attributes are returned.