101 unsigned size()
const {
return IDs.
size(); }
102 std::pair<unsigned, bool> &operator[](
const Value *V) {
return IDs[V]; }
104 std::pair<unsigned, bool>
lookup(
const Value *V)
const {
105 return IDs.lookup(V);
108 void index(
const Value *V) {
110 unsigned ID = IDs.size() + 1;
118 if (OM.lookup(V).first)
121 if (
const Constant *
C = dyn_cast<Constant>(V))
122 if (
C->getNumOperands() && !isa<GlobalValue>(
C))
123 for (
const Value *
Op :
C->operands())
124 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
138 if (
G.hasInitializer())
139 if (!isa<GlobalValue>(
G.getInitializer()))
144 if (!isa<GlobalValue>(
A.getAliasee()))
149 if (!isa<GlobalValue>(
I.getResolver()))
154 for (
const Use &U :
F.operands())
155 if (!isa<GlobalValue>(U.get()))
160 if (
F.isDeclaration())
168 for (
const Value *
Op :
I.operands())
169 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
180 unsigned ID,
const OrderMap &OM,
183 using Entry = std::pair<const Use *, unsigned>;
187 if (OM.lookup(U.getUser()).
first)
195 !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V);
196 if (
auto *BA = dyn_cast<BlockAddress>(V))
197 ID = OM.lookup(BA->getBasicBlock()).
first;
199 const Use *LU = L.first;
200 const Use *RU = R.first;
204 auto LID = OM.lookup(LU->getUser()).
first;
205 auto RID = OM.lookup(RU->getUser()).
first;
225 return LU->getOperandNo() < RU->getOperandNo();
226 return LU->getOperandNo() > RU->getOperandNo();
231 [](
const Entry &
L,
const Entry &R) {
return L.second < R.second; }))
236 Stack.emplace_back(V, F, List.
size());
237 assert(List.
size() == Stack.back().Shuffle.size() &&
"Wrong size");
238 for (
size_t I = 0,
E = List.
size();
I !=
E; ++
I)
239 Stack.back().Shuffle[
I] = List[
I].second;
244 auto &IDPair = OM[V];
245 assert(IDPair.first &&
"Unmapped value");
251 IDPair.second =
true;
256 if (
const Constant *
C = dyn_cast<Constant>(V))
257 if (
C->getNumOperands())
258 for (
const Value *
Op :
C->operands())
259 if (isa<Constant>(
Op))
277 if (
F.isDeclaration())
285 for (
const Value *
Op :
I.operands())
286 if (isa<Constant>(*
Op) || isa<InlineAsm>(*Op))
303 if (
G.hasInitializer())
310 for (
const Use &U :
F.operands())
317 if (
const Argument *MA = dyn_cast<Argument>(V))
318 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
320 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
321 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
324 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
328 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
329 return GV->getParent();
331 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
333 if (isa<Instruction>(U))
344 default: Out <<
"cc" << cc;
break;
385 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
386 unsigned char C = Name[i];
387 if (isprint(C) && C !=
'\\' && C !=
'"')
390 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
406 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
408 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
413 unsigned char C = Name[i];
414 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
475 TypePrinting() =
default;
476 TypePrinting(
const TypePrinting &) =
delete;
477 TypePrinting &operator=(
const TypePrinting &) =
delete;
479 void incorporateTypes(
const Module &M);
488 void TypePrinting::incorporateTypes(
const Module &M) {
489 NamedTypes.run(M,
false);
493 unsigned NextNumber = 0;
495 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(),
I,
E;
496 for (
I = NamedTypes.begin(), E = NamedTypes.end();
I !=
E; ++
I) {
504 NumberedTypes[STy] = NextNumber++;
509 NamedTypes.erase(NextToUse, NamedTypes.end());
553 return printStructBody(STy, OS);
559 if (I != NumberedTypes.
end())
560 OS <<
'%' << I->second;
562 OS <<
"%\"type " << STy <<
'\"';
588 llvm_unreachable("Invalid TypeID");
591 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
592 if (STy->isOpaque()) {
600 if (STy->getNumElements() == 0) {
603 StructType::element_iterator I = STy->element_begin();
606 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
619 //===----------------------------------------------------------------------===//
620 // SlotTracker Class: Enumerate slot numbers for unnamed values
621 //===----------------------------------------------------------------------===//
627 using ValueMap = DenseMap<const Value *, unsigned>;
631 const Module* TheModule;
634 const Function* TheFunction = nullptr;
635 bool FunctionProcessed = false;
636 bool ShouldInitializeAllMetadata;
647 DenseMap<const MDNode*, unsigned> mdnMap;
648 unsigned mdnNext = 0;
651 DenseMap<AttributeSet, unsigned> asMap;
660 explicit SlotTracker(const Module *M,
661 bool ShouldInitializeAllMetadata = false);
668 explicit SlotTracker(const Function *F,
669 bool ShouldInitializeAllMetadata = false);
671 SlotTracker(const SlotTracker &) = delete;
672 SlotTracker &operator=(const SlotTracker &) = delete;
676 int getLocalSlot(const Value *V);
677 int getGlobalSlot(const GlobalValue *V);
678 int getMetadataSlot(const MDNode *N);
679 int getAttributeGroupSlot(AttributeSet AS);
683 void incorporateFunction(const Function *F) {
685 FunctionProcessed = false;
688 const Function *getFunction() const { return TheFunction; }
693 void purgeFunction();
696 using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator;
698 mdn_iterator mdn_begin() { return mdnMap.begin(); }
699 mdn_iterator mdn_end() { return mdnMap.end(); }
700 unsigned mdn_size() const { return mdnMap.size(); }
701 bool mdn_empty() const { return mdnMap.empty(); }
704 using as_iterator = DenseMap<AttributeSet, unsigned>::iterator;
706 as_iterator as_begin() { return asMap.begin(); }
707 as_iterator as_end() { return asMap.end(); }
708 unsigned as_size() const { return asMap.size(); }
709 bool as_empty() const { return asMap.empty(); }
712 inline void initialize();
714 // Implementation Details
717 void CreateModuleSlot(const GlobalValue *V);
720 void CreateMetadataSlot(const MDNode *N);
723 void CreateFunctionSlot(const Value *V);
726 void CreateAttributeSetSlot(AttributeSet AS);
730 void processModule();
733 void processFunction();
736 void processGlobalObjectMetadata(const GlobalObject &GO);
739 void processFunctionMetadata(const Function &F);
742 void processInstructionMetadata(const Instruction &I);
745 } // end namespace llvm
747 ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
749 : M(M), F(F), Machine(&Machine) {}
751 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
752 bool ShouldInitializeAllMetadata)
753 : ShouldCreateStorage(M),
754 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
756 ModuleSlotTracker::~ModuleSlotTracker() = default;
758 SlotTracker *ModuleSlotTracker::getMachine() {
759 if (!ShouldCreateStorage)
762 ShouldCreateStorage = false;
764 llvm::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
765 Machine = MachineStorage.get();
769 void ModuleSlotTracker::incorporateFunction(const Function &F) {
770 // Using getMachine() may lazily create the slot tracker.
774 // Nothing to do if this is the right function already.
778 Machine->purgeFunction();
779 Machine->incorporateFunction(&F);
783 int ModuleSlotTracker::getLocalSlot(const Value *V) {
784 assert(F && "No function incorporated");
785 return Machine->getLocalSlot(V);
788 static SlotTracker *createSlotTracker(const Value *V) {
789 if (const Argument *FA = dyn_cast<Argument>(V))
790 return new SlotTracker(FA->getParent());
792 if (const Instruction *I = dyn_cast<Instruction>(V))
794 return new SlotTracker(I->getParent()->getParent());
796 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
797 return new SlotTracker(BB->getParent());
799 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
800 return new SlotTracker(GV->getParent());
802 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
803 return new SlotTracker(GA->getParent());
805 if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
806 return new SlotTracker(GIF->getParent());
808 if (const Function *Func = dyn_cast<Function>(V))
809 return new SlotTracker(Func);
815 #define ST_DEBUG(X) dbgs() << X
820 // Module level constructor. Causes the contents of the Module (sans functions)
821 // to be added to the slot table.
822 SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
823 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
825 // Function level constructor. Causes the contents of the Module and the one
826 // function provided to be added to the slot table.
827 SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
828 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
829 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
831 inline void SlotTracker::initialize() {
834 TheModule = nullptr; ///< Prevent re-processing next time we're called.
837 if (TheFunction && !FunctionProcessed)
843 void SlotTracker::processModule() {
849 CreateModuleSlot(&Var);
850 processGlobalObjectMetadata(Var);
851 auto Attrs = Var.getAttributes();
852 if (
Attrs.hasAttributes())
853 CreateAttributeSetSlot(
Attrs);
858 CreateModuleSlot(&
A);
863 CreateModuleSlot(&I);
868 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
869 CreateMetadataSlot(NMD.getOperand(i));
875 CreateModuleSlot(&
F);
877 if (ShouldInitializeAllMetadata)
878 processFunctionMetadata(
F);
884 CreateAttributeSetSlot(FnAttrs);
891 void SlotTracker::processFunction() {
892 ST_DEBUG(
"begin processFunction!\n");
896 if (!ShouldInitializeAllMetadata)
897 processFunctionMetadata(*TheFunction);
901 AE = TheFunction->
arg_end(); AI != AE; ++AI)
903 CreateFunctionSlot(&*AI);
905 ST_DEBUG(
"Inserting Instructions:\n");
908 for (
auto &BB : *TheFunction) {
910 CreateFunctionSlot(&BB);
913 if (!I.getType()->isVoidTy() && !I.hasName())
914 CreateFunctionSlot(&I);
922 CreateAttributeSetSlot(Attrs);
927 FunctionProcessed =
true;
932 void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
936 CreateMetadataSlot(MD.second);
939 void SlotTracker::processFunctionMetadata(
const Function &
F) {
940 processGlobalObjectMetadata(F);
943 processInstructionMetadata(I);
947 void SlotTracker::processInstructionMetadata(
const Instruction &I) {
949 if (
const CallInst *CI = dyn_cast<CallInst>(&I))
950 if (
Function *F = CI->getCalledFunction())
951 if (F->isIntrinsic())
953 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
954 if (
MDNode *
N = dyn_cast<MDNode>(V->getMetadata()))
955 CreateMetadataSlot(
N);
961 CreateMetadataSlot(MD.second);
970 TheFunction =
nullptr;
971 FunctionProcessed =
false;
982 return MI == mMap.
end() ? -1 : (int)MI->second;
992 return MI == mdnMap.end() ? -1 : (int)MI->second;
997 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1003 return FI == fMap.
end() ? -1 : (int)FI->second;
1012 return AI == asMap.end() ? -1 : (int)AI->second;
1016 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1017 assert(V &&
"Can't insert a null Value into SlotTracker!");
1021 unsigned DestSlot = mNext++;
1024 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1027 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1028 (isa<Function>(V) ?
'F' :
1029 (isa<GlobalAlias>(V) ?
'A' :
1030 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1034 void SlotTracker::CreateFunctionSlot(
const Value *V) {
1037 unsigned DestSlot = fNext++;
1041 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1042 DestSlot <<
" [o]\n");
1046 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1047 assert(N &&
"Can't insert a null Value into SlotTracker!");
1049 unsigned DestSlot = mdnNext;
1050 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
1057 CreateMetadataSlot(
Op);
1060 void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1064 if (I != asMap.end())
1067 unsigned DestSlot = asNext++;
1068 asMap[AS] = DestSlot;
1076 TypePrinting *TypePrinter,
1081 TypePrinting *TypePrinter,
1083 bool FromValue =
false);
1088 default: Out <<
" <unknown operation " << Op <<
">";
break;
1104 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
1106 if (FPO->hasUnsafeAlgebra())
1109 if (FPO->hasNoNaNs())
1111 if (FPO->hasNoInfs())
1113 if (FPO->hasNoSignedZeros())
1115 if (FPO->hasAllowReciprocal())
1117 if (FPO->hasAllowContract())
1123 dyn_cast<OverflowingBinaryOperator>(U)) {
1124 if (OBO->hasNoUnsignedWrap())
1126 if (OBO->hasNoSignedWrap())
1129 dyn_cast<PossiblyExactOperator>(U)) {
1133 if (
GEP->isInBounds())
1139 TypePrinting &TypePrinter,
1142 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1143 if (CI->getType()->isIntegerTy(1)) {
1144 Out << (CI->getZExtValue() ?
"true" :
"false");
1147 Out << CI->getValue();
1151 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1152 const APFloat &APF = CFP->getValueAPF();
1163 bool isNaN = APF.
isNaN();
1164 if (!isInf && !isNaN) {
1172 assert(((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
1173 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
1174 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) &&
1175 "[-+]?[0-9] regex does not match!");
1186 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
1187 "assuming that double is 64 bits!");
1230 if (isa<ConstantAggregateZero>(CV)) {
1231 Out <<
"zeroinitializer";
1235 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1236 Out <<
"blockaddress(";
1246 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1247 Type *ETy = CA->getType()->getElementType();
1249 TypePrinter.print(ETy, Out);
1254 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1256 TypePrinter.print(ETy, Out);
1268 if (CA->isString()) {
1275 Type *ETy = CA->getType()->getElementType();
1277 TypePrinter.print(ETy, Out);
1282 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1284 TypePrinter.print(ETy, Out);
1294 if (CS->getType()->isPacked())
1297 unsigned N = CS->getNumOperands();
1300 TypePrinter.print(CS->getOperand(0)->getType(), Out);
1306 for (
unsigned i = 1; i <
N; i++) {
1308 TypePrinter.print(CS->getOperand(i)->getType(), Out);
1318 if (CS->getType()->isPacked())
1323 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1326 TypePrinter.print(ETy, Out);
1332 TypePrinter.print(ETy, Out);
1341 if (isa<ConstantPointerNull>(CV)) {
1346 if (isa<ConstantTokenNone>(CV)) {
1351 if (isa<UndefValue>(CV)) {
1356 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1357 Out << CE->getOpcodeName();
1358 WriteOptimizationInfo(Out, CE);
1359 if (CE->isCompare())
1360 Out << ' ' << CmpInst::getPredicateName(
1361 static_cast<CmpInst::Predicate>(CE->getPredicate()));
1364 Optional<unsigned> InRangeOp;
1365 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) {
1366 TypePrinter.print(GEP->getSourceElementType(), Out);
1368 InRangeOp = GEP->getInRangeIndex();
1373 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
1374 if (InRangeOp && unsigned(OI - CE->op_begin()) == *InRangeOp)
1376 TypePrinter.print((*OI)->getType(), Out);
1378 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
1379 if (OI+1 != CE->op_end())
1383 if (CE->hasIndices()) {
1384 ArrayRef<unsigned> Indices = CE->getIndices();
1385 for (unsigned i = 0, e = Indices.size(); i != e; ++i)
1386 Out << ", " << Indices[i];
1391 TypePrinter.print(CE->getType(), Out);
1398 Out << "<placeholder or erroneous Constant>";
1401 static void writeMDTuple(raw_ostream &Out, const MDTuple *Node,
1402 TypePrinting *TypePrinter, SlotTracker *Machine,
1403 const Module *Context) {
1405 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
1406 const Metadata *MD = Node->getOperand(mi);
1409 else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1410 Value *V = MDV->getValue();
1411 TypePrinter->print(V->getType(), Out);
1413 WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context);
1415 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context);
1426 struct FieldSeparator {
1430 FieldSeparator(const char *Sep = ", ") : Sep(Sep) {}
1433 raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) {
1438 return OS << FS.Sep;
1441 struct MDFieldPrinter {
1444 TypePrinting *TypePrinter = nullptr;
1445 SlotTracker *Machine = nullptr;
1446 const Module *Context = nullptr;
1448 explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {}
1449 MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter,
1450 SlotTracker *Machine, const Module *Context)
1451 : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) {
1454 void printTag(const DINode *N);
1455 void printMacinfoType(const DIMacroNode *N);
1456 void printChecksumKind(const DIFile *N);
1457 void printString(StringRef Name, StringRef Value,
1458 bool ShouldSkipEmpty = true);
1459 void printMetadata(StringRef Name, const Metadata *MD,
1460 bool ShouldSkipNull = true);
1461 template <class IntTy>
1462 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true);
1463 void printBool(StringRef Name, bool Value, Optional<bool> Default = None);
1464 void printDIFlags(StringRef Name, DINode::DIFlags Flags);
1465 template <class IntTy, class Stringifier>
1466 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString,
1467 bool ShouldSkipZero = true);
1468 void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK);
1471 } // end anonymous namespace
1473 void MDFieldPrinter::printTag(const DINode *N) {
1474 Out << FS << "tag: ";
1475 auto Tag = dwarf::TagString(N->getTag());
1482 void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) {
1483 Out << FS << "type: ";
1484 auto Type = dwarf::MacinfoString(N->getMacinfoType());
1488 Out << N->getMacinfoType();
1491 void MDFieldPrinter::printChecksumKind(const DIFile *N) {
1492 if (N->getChecksumKind() == DIFile::CSK_None)
1493 // Skip CSK_None checksum kind.
1495 Out << FS << "checksumkind: " << N->getChecksumKindAsString();
1498 void MDFieldPrinter::printString(StringRef Name, StringRef Value,
1499 bool ShouldSkipEmpty) {
1500 if (ShouldSkipEmpty && Value.empty())
1503 Out << FS << Name << ": \"";
1504 PrintEscapedString(Value, Out);
1508 static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD,
1509 TypePrinting *TypePrinter,
1510 SlotTracker *Machine,
1511 const Module *Context) {
1516 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context);
1519 void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD,
1520 bool ShouldSkipNull) {
1521 if (ShouldSkipNull && !MD)
1524 Out << FS << Name << ": ";
1525 writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context);
1528 template <class IntTy>
1529 void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) {
1530 if (ShouldSkipZero && !Int)
1533 Out << FS << Name << ": " << Int;
1536 void MDFieldPrinter::printBool(StringRef Name, bool Value,
1537 Optional<bool> Default) {
1538 if (Default && Value == *Default)
1540 Out << FS << Name << ": " << (Value ? "true" : "false");
1543 void MDFieldPrinter::printDIFlags(StringRef Name, DINode::DIFlags Flags) {
1547 Out << FS << Name << ": ";
1549 SmallVector<DINode::DIFlags, 8> SplitFlags;
1550 auto Extra = DINode::splitFlags(Flags, SplitFlags);
1552 FieldSeparator FlagsFS(" | ");
1553 for (auto F : SplitFlags) {
1554 auto StringF = DINode::getFlagString(F);
1555 assert(!StringF.empty() && "Expected valid flag");
1556 Out << FlagsFS << StringF;
1558 if (Extra || SplitFlags.empty())
1559 Out << FlagsFS << Extra;
1562 void MDFieldPrinter::printEmissionKind(StringRef Name,
1563 DICompileUnit::DebugEmissionKind EK) {
1564 Out << FS << Name << ": " << DICompileUnit::EmissionKindString(EK);
1567 template <class IntTy, class Stringifier>
1568 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
1569 Stringifier toString, bool ShouldSkipZero) {
1573 Out << FS << Name << ": ";
1574 auto S = toString(Value);
1581 static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N,
1582 TypePrinting *TypePrinter, SlotTracker *Machine,
1583 const Module *Context) {
1584 Out << "!GenericDINode(";
1585 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1586 Printer.printTag(N);
1587 Printer.printString("header", N->getHeader());
1588 if (N->getNumDwarfOperands()) {
1589 Out << Printer.FS << "operands: {";
1591 for (auto &I : N->dwarf_operands()) {
1593 writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context);
1600 static void writeDILocation(raw_ostream &Out, const DILocation *DL,
1601 TypePrinting *TypePrinter, SlotTracker *Machine,
1602 const Module *Context) {
1603 Out << "!DILocation(";
1604 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1605 // Always output the line, since 0 is a relevant and important value for it.
1606 Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false);
1607 Printer.printInt("column", DL->getColumn());
1608 Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false);
1609 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());
1613 static void writeDISubrange(raw_ostream &Out, const DISubrange *N,
1614 TypePrinting *, SlotTracker *, const Module *) {
1615 Out << "!DISubrange(";
1616 MDFieldPrinter Printer(Out);
1617 Printer.printInt("count", N->getCount(), /* ShouldSkipZero */ false);
1618 Printer.printInt("lowerBound", N->getLowerBound());
1622 static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N,
1623 TypePrinting *, SlotTracker *, const Module *) {
1624 Out << "!DIEnumerator(";
1625 MDFieldPrinter Printer(Out);
1626 Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false);
1627 Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false);
1631 static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N,
1632 TypePrinting *, SlotTracker *, const Module *) {
1633 Out << "!DIBasicType(";
1634 MDFieldPrinter Printer(Out);
1635 if (N->getTag() != dwarf::DW_TAG_base_type)
1636 Printer.printTag(N);
1637 Printer.printString("name", N->getName());
1638 Printer.printInt("size", N->getSizeInBits());
1639 Printer.printInt("align", N->getAlignInBits());
1640 Printer.printDwarfEnum("encoding", N->getEncoding(),
1641 dwarf::AttributeEncodingString);
1645 static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N,
1646 TypePrinting *TypePrinter, SlotTracker *Machine,
1647 const Module *Context) {
1648 Out << "!DIDerivedType(";
1649 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1650 Printer.printTag(N);
1651 Printer.printString("name", N->getName());
1652 Printer.printMetadata("scope", N->getRawScope());
1653 Printer.printMetadata("file", N->getRawFile());
1654 Printer.printInt("line", N->getLine());
1655 Printer.printMetadata("baseType", N->getRawBaseType(),
1656 /* ShouldSkipNull */ false);
1657 Printer.printInt("size", N->getSizeInBits());
1658 Printer.printInt("align", N->getAlignInBits());
1659 Printer.printInt("offset", N->getOffsetInBits());
1660 Printer.printDIFlags("flags", N->getFlags());
1661 Printer.printMetadata("extraData", N->getRawExtraData());
1662 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1663 Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace,
1664 /* ShouldSkipZero */ false);
1668 static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N,
1669 TypePrinting *TypePrinter,
1670 SlotTracker *Machine, const Module *Context) {
1671 Out << "!DICompositeType(";
1672 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1673 Printer.printTag(N);
1674 Printer.printString("name", N->getName());
1675 Printer.printMetadata("scope", N->getRawScope());
1676 Printer.printMetadata("file", N->getRawFile());
1677 Printer.printInt("line", N->getLine());
1678 Printer.printMetadata("baseType", N->getRawBaseType());
1679 Printer.printInt("size", N->getSizeInBits());
1680 Printer.printInt("align", N->getAlignInBits());
1681 Printer.printInt("offset", N->getOffsetInBits());
1682 Printer.printDIFlags("flags", N->getFlags());
1683 Printer.printMetadata("elements", N->getRawElements());
1684 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(),
1685 dwarf::LanguageString);
1686 Printer.printMetadata("vtableHolder", N->getRawVTableHolder());
1687 Printer.printMetadata("templateParams", N->getRawTemplateParams());
1688 Printer.printString("identifier", N->getIdentifier());
1692 static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N,
1693 TypePrinting *TypePrinter,
1694 SlotTracker *Machine, const Module *Context) {
1695 Out << "!DISubroutineType(";
1696 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1697 Printer.printDIFlags("flags", N->getFlags());
1698 Printer.printDwarfEnum("cc", N->getCC(), dwarf::ConventionString);
1699 Printer.printMetadata("types", N->getRawTypeArray(),
1700 /* ShouldSkipNull */ false);
1704 static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *,
1705 SlotTracker *, const Module *) {
1707 MDFieldPrinter Printer(Out);
1708 Printer.printString("filename", N->getFilename(),
1709 /* ShouldSkipEmpty */ false);
1710 Printer.printString("directory", N->getDirectory(),
1711 /* ShouldSkipEmpty */ false);
1712 Printer.printChecksumKind(N);
1713 Printer.printString("checksum", N->getChecksum(), /* ShouldSkipEmpty */ true);
1717 static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
1718 TypePrinting *TypePrinter, SlotTracker *Machine,
1719 const Module *Context) {
1720 Out << "!DICompileUnit(";
1721 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1722 Printer.printDwarfEnum("language", N->getSourceLanguage(),
1723 dwarf::LanguageString, /* ShouldSkipZero */ false);
1724 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
1725 Printer.printString("producer", N->getProducer());
1726 Printer.printBool("isOptimized", N->isOptimized());
1727 Printer.printString("flags", N->getFlags());
1728 Printer.printInt("runtimeVersion", N->getRuntimeVersion(),
1729 /* ShouldSkipZero */ false);
1730 Printer.printString("splitDebugFilename", N->getSplitDebugFilename());
1731 Printer.printEmissionKind("emissionKind", N->getEmissionKind());
1732 Printer.printMetadata("enums", N->getRawEnumTypes());
1733 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes());
1734 Printer.printMetadata("globals", N->getRawGlobalVariables());
1735 Printer.printMetadata("imports", N->getRawImportedEntities());
1736 Printer.printMetadata("macros", N->getRawMacros());
1737 Printer.printInt("dwoId", N->getDWOId());
1738 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true);
1739 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),
1744 static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N,
1745 TypePrinting *TypePrinter, SlotTracker *Machine,
1746 const Module *Context) {
1747 Out << "!DISubprogram(";
1748 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1749 Printer.printString("name", N->getName());
1750 Printer.printString("linkageName", N->getLinkageName());
1751 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1752 Printer.printMetadata("file", N->getRawFile());
1753 Printer.printInt("line", N->getLine());
1754 Printer.printMetadata("type", N->getRawType());
1755 Printer.printBool("isLocal", N->isLocalToUnit());
1756 Printer.printBool("isDefinition", N->isDefinition());
1757 Printer.printInt("scopeLine", N->getScopeLine());
1758 Printer.printMetadata("containingType", N->getRawContainingType());
1759 Printer.printDwarfEnum("virtuality", N->getVirtuality(),
1760 dwarf::VirtualityString);
1761 if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
1762 N->getVirtualIndex() != 0)
1763 Printer.printInt("virtualIndex", N->getVirtualIndex(), false);
1764 Printer.printInt("thisAdjustment", N->getThisAdjustment());
1765 Printer.printDIFlags("flags", N->getFlags());
1766 Printer.printBool("isOptimized", N->isOptimized());
1767 Printer.printMetadata("unit", N->getRawUnit());
1768 Printer.printMetadata("templateParams", N->getRawTemplateParams());
1769 Printer.printMetadata("declaration", N->getRawDeclaration());
1770 Printer.printMetadata("variables", N->getRawVariables());
1771 Printer.printMetadata("thrownTypes", N->getRawThrownTypes());
1775 static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N,
1776 TypePrinting *TypePrinter, SlotTracker *Machine,
1777 const Module *Context) {
1778 Out << "!DILexicalBlock(";
1779 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1780 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1781 Printer.printMetadata("file", N->getRawFile());
1782 Printer.printInt("line", N->getLine());
1783 Printer.printInt("column", N->getColumn());
1787 static void writeDILexicalBlockFile(raw_ostream &Out,
1788 const DILexicalBlockFile *N,
1789 TypePrinting *TypePrinter,
1790 SlotTracker *Machine,
1791 const Module *Context) {
1792 Out << "!DILexicalBlockFile(";
1793 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1794 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1795 Printer.printMetadata("file", N->getRawFile());
1796 Printer.printInt("discriminator", N->getDiscriminator(),
1797 /* ShouldSkipZero */ false);
1801 static void writeDINamespace(raw_ostream &Out, const DINamespace *N,
1802 TypePrinting *TypePrinter, SlotTracker *Machine,
1803 const Module *Context) {
1804 Out << "!DINamespace(";
1805 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1806 Printer.printString("name", N->getName());
1807 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1808 Printer.printBool("exportSymbols", N->getExportSymbols(), false);
1812 static void writeDIMacro(raw_ostream &Out, const DIMacro *N,
1813 TypePrinting *TypePrinter, SlotTracker *Machine,
1814 const Module *Context) {
1816 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1817 Printer.printMacinfoType(N);
1818 Printer.printInt("line", N->getLine());
1819 Printer.printString("name", N->getName());
1820 Printer.printString("value", N->getValue());
1824 static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N,
1825 TypePrinting *TypePrinter, SlotTracker *Machine,
1826 const Module *Context) {
1827 Out << "!DIMacroFile(";
1828 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1829 Printer.printInt("line", N->getLine());
1830 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
1831 Printer.printMetadata("nodes", N->getRawElements());
1835 static void writeDIModule(raw_ostream &Out, const DIModule *N,
1836 TypePrinting *TypePrinter, SlotTracker *Machine,
1837 const Module *Context) {
1838 Out << "!DIModule(";
1839 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1840 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1841 Printer.printString("name", N->getName());
1842 Printer.printString("configMacros", N->getConfigurationMacros());
1843 Printer.printString("includePath", N->getIncludePath());
1844 Printer.printString("isysroot", N->getISysRoot());
1849 static void writeDITemplateTypeParameter(raw_ostream &Out,
1850 const DITemplateTypeParameter *N,
1851 TypePrinting *TypePrinter,
1852 SlotTracker *Machine,
1853 const Module *Context) {
1854 Out << "!DITemplateTypeParameter(";
1855 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1856 Printer.printString("name", N->getName());
1857 Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false);
1861 static void writeDITemplateValueParameter(raw_ostream &Out,
1862 const DITemplateValueParameter *N,
1863 TypePrinting *TypePrinter,
1864 SlotTracker *Machine,
1865 const Module *Context) {
1866 Out << "!DITemplateValueParameter(";
1867 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1868 if (N->getTag() != dwarf::DW_TAG_template_value_parameter)
1869 Printer.printTag(N);
1870 Printer.printString("name", N->getName());
1871 Printer.printMetadata("type", N->getRawType());
1872 Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false);
1876 static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N,
1877 TypePrinting *TypePrinter,
1878 SlotTracker *Machine, const Module *Context) {
1879 Out << "!DIGlobalVariable(";
1880 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1881 Printer.printString("name", N->getName());
1882 Printer.printString("linkageName", N->getLinkageName());
1883 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1884 Printer.printMetadata("file", N->getRawFile());
1885 Printer.printInt("line", N->getLine());
1886 Printer.printMetadata("type", N->getRawType());
1887 Printer.printBool("isLocal", N->isLocalToUnit());
1888 Printer.printBool("isDefinition", N->isDefinition());
1889 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration());
1890 Printer.printInt("align", N->getAlignInBits());
1894 static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N,
1895 TypePrinting *TypePrinter,
1896 SlotTracker *Machine, const Module *Context) {
1897 Out << "!DILocalVariable(";
1898 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1899 Printer.printString("name", N->getName());
1900 Printer.printInt("arg", N->getArg());
1901 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1902 Printer.printMetadata("file", N->getRawFile());
1903 Printer.printInt("line", N->getLine());
1904 Printer.printMetadata("type", N->getRawType());
1905 Printer.printDIFlags("flags", N->getFlags());
1906 Printer.printInt("align", N->getAlignInBits());
1910 static void writeDIExpression(raw_ostream &Out, const DIExpression *N,
1911 TypePrinting *TypePrinter, SlotTracker *Machine,
1912 const Module *Context) {
1913 Out << "!DIExpression(";
1916 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) {
1917 auto OpStr = dwarf::OperationEncodingString(I->getOp());
1918 assert(!OpStr.empty() && "Expected valid opcode");
1921 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A)
1922 Out << FS << I->getArg(A);
1925 for (const auto &I : N->getElements())
1931 static void writeDIGlobalVariableExpression(raw_ostream &Out,
1932 const DIGlobalVariableExpression *N,
1933 TypePrinting *TypePrinter,
1934 SlotTracker *Machine,
1935 const Module *Context) {
1936 Out << "!DIGlobalVariableExpression(";
1937 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1938 Printer.printMetadata("var", N->getVariable());
1939 Printer.printMetadata("expr", N->getExpression());
1943 static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N,
1944 TypePrinting *TypePrinter, SlotTracker *Machine,
1945 const Module *Context) {
1946 Out << "!DIObjCProperty(";
1947 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1948 Printer.printString("name", N->getName());
1949 Printer.printMetadata("file", N->getRawFile());
1950 Printer.printInt("line", N->getLine());
1951 Printer.printString("setter", N->getSetterName());
1952 Printer.printString("getter", N->getGetterName());
1953 Printer.printInt("attributes", N->getAttributes());
1954 Printer.printMetadata("type", N->getRawType());
1958 static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N,
1959 TypePrinting *TypePrinter,
1960 SlotTracker *Machine, const Module *Context) {
1961 Out << "!DIImportedEntity(";
1962 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
1963 Printer.printTag(N);
1964 Printer.printString("name", N->getName());
1965 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
1966 Printer.printMetadata("entity", N->getRawEntity());
1967 Printer.printMetadata("file", N->getRawFile());
1968 Printer.printInt("line", N->getLine());
1972 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
1973 TypePrinting *TypePrinter,
1974 SlotTracker *Machine,
1975 const Module *Context) {
1976 if (Node->isDistinct())
1978 else if (Node->isTemporary())
1979 Out << "<temporary!> "; // Handle broken code.
1981 switch (Node->getMetadataID()) {
1983 llvm_unreachable("Expected uniquable MDNode");
1984 #define HANDLE_MDNODE_LEAF(CLASS) \
1985 case Metadata::CLASS##Kind: \
1986 write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \
1988 #include "llvm/IR/Metadata.def"
1992 // Full implementation of printing a Value as an operand with support for
1993 // TypePrinting, etc.
1994 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1995 TypePrinting *TypePrinter,
1996 SlotTracker *Machine,
1997 const Module *Context) {
1999 PrintLLVMName(Out, V);
2003 const Constant *CV = dyn_cast<Constant>(V);
2004 if (CV && !isa<GlobalValue>(CV)) {
2005 assert(TypePrinter && "Constants require TypePrinting!");
2006 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
2010 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2012 if (IA->hasSideEffects())
2013 Out << "sideeffect ";
2014 if (IA->isAlignStack())
2015 Out << "alignstack ";
2016 // We don't emit the AD_ATT dialect as it
's the assumed default.
2017 if (IA->getDialect() == InlineAsm::AD_Intel)
2018 Out << "inteldialect ";
2020 PrintEscapedString(IA->getAsmString(), Out);
2027 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2037 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2038 Slot = Machine->getGlobalSlot(GV);
2041 Slot = Machine->getLocalSlot(V);
2048 Slot = Machine->getLocalSlot(V);
2054 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2055 Slot = Machine->getGlobalSlot(GV);
2058 Slot = Machine->getLocalSlot(V);
2067 Out << Prefix << Slot;
2073 TypePrinting *TypePrinter,
2076 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
2077 std::unique_ptr<SlotTracker> MachineStorage;
2079 MachineStorage = make_unique<SlotTracker>(
Context);
2080 Machine = MachineStorage.get();
2086 Out <<
"<" << N <<
">";
2092 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2099 auto *V = cast<ValueAsMetadata>(MD);
2100 assert(TypePrinter &&
"TypePrinter required for metadata values");
2101 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2102 "Unexpected function-local metadata outside of value argument");
2104 TypePrinter->print(V->getValue()->
getType(), Out);
2111 class AssemblyWriter {
2114 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2116 TypePrinting TypePrinter;
2120 bool ShouldPreserveUseListOrder;
2130 bool ShouldPreserveUseListOrder =
false);
2132 void printMDNodeBody(
const MDNode *MD);
2135 void printModule(
const Module *M);
2137 void writeOperand(
const Value *
Op,
bool PrintType);
2145 void writeAtomicCmpXchg(
const LLVMContext &Context,
2150 void writeAllMDNodes();
2151 void writeMDNode(
unsigned Slot,
const MDNode *Node);
2152 void writeAllAttributeGroups();
2154 void printTypeIdentities();
2157 void printComdat(
const Comdat *
C);
2158 void printFunction(
const Function *F);
2165 void printUseLists(
const Function *F);
2169 void printMetadataAttachments(
2175 void printInfoComment(
const Value &V);
2186 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2187 : Out(o), TheModule(M), Machine(Mac), AnnotationWriter(AAW),
2188 IsForDebug(IsForDebug),
2189 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2192 TypePrinter.incorporateTypes(*TheModule);
2193 for (
const GlobalObject &GO : TheModule->global_objects())
2198 void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2200 Out <<
"<null operand!>";
2204 TypePrinter.print(Operand->
getType(), Out);
2210 void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2220 Out <<
" syncscope(\"";
2228 void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2231 if (Ordering == AtomicOrdering::NotAtomic)
2234 writeSyncScope(Context, SSID);
2238 void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2242 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
2243 FailureOrdering != AtomicOrdering::NotAtomic);
2245 writeSyncScope(Context, SSID);
2250 void AssemblyWriter::writeParamOperand(
const Value *Operand,
2253 Out <<
"<null operand!>";
2258 TypePrinter.print(Operand->
getType(), Out);
2273 bool FirstBundle =
true;
2279 FirstBundle =
false;
2287 bool FirstInput =
true;
2288 for (
const auto &Input : BU.
Inputs) {
2293 TypePrinter.print(Input->getType(), Out);
2304 void AssemblyWriter::printModule(
const Module *M) {
2305 Machine.initialize();
2307 if (ShouldPreserveUseListOrder)
2317 Out <<
"source_filename = \"";
2324 Out <<
"target datalayout = \"" << DL <<
"\"\n";
2335 std::tie(Front, Asm) = Asm.
split(
'\n');
2339 Out <<
"module asm \"";
2342 }
while (!Asm.
empty());
2345 printTypeIdentities();
2348 if (!Comdats.empty())
2350 for (
const Comdat *
C : Comdats) {
2352 if (
C != Comdats.back())
2359 printGlobal(&GV); Out <<
'\n';
2365 printIndirectSymbol(&GA);
2370 printIndirectSymbol(&GI);
2373 printUseLists(
nullptr);
2378 assert(UseListOrders.empty() &&
"All use-lists should have been consumed");
2381 if (!Machine.as_empty()) {
2383 writeAllAttributeGroups();
2387 if (!M->named_metadata_empty()) Out <<
'\n';
2389 for (
const NamedMDNode &Node : M->named_metadata())
2390 printNamedMDNode(&Node);
2393 if (!Machine.mdn_empty()) {
2402 Out <<
"<empty name> ";
2404 if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] ==
'-' ||
2405 Name[0] ==
'$' || Name[0] ==
'.' || Name[0] ==
'_')
2408 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
2409 for (
unsigned i = 1, e = Name.
size(); i != e; ++i) {
2410 unsigned char C = Name[i];
2411 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
2412 C ==
'.' || C ==
'_')
2415 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
2420 void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
2427 int Slot = Machine.getMetadataSlot(NMD->
getOperand(i));
2438 case GlobalValue::ExternalLinkage:
2440 case GlobalValue::PrivateLinkage:
2442 case GlobalValue::InternalLinkage:
2444 case GlobalValue::LinkOnceAnyLinkage:
2446 case GlobalValue::LinkOnceODRLinkage:
2447 return "linkonce_odr ";
2448 case GlobalValue::WeakAnyLinkage:
2450 case GlobalValue::WeakODRLinkage:
2452 case GlobalValue::CommonLinkage:
2454 case GlobalValue::AppendingLinkage:
2455 return "appending ";
2456 case GlobalValue::ExternalWeakLinkage:
2457 return "extern_weak ";
2458 case GlobalValue::AvailableExternallyLinkage:
2459 return "available_externally ";
2467 case GlobalValue::DefaultVisibility:
break;
2468 case GlobalValue::HiddenVisibility: Out <<
"hidden ";
break;
2469 case GlobalValue::ProtectedVisibility: Out <<
"protected ";
break;
2476 case GlobalValue::DefaultStorageClass:
break;
2477 case GlobalValue::DLLImportStorageClass: Out <<
"dllimport ";
break;
2478 case GlobalValue::DLLExportStorageClass: Out <<
"dllexport ";
break;
2485 case GlobalVariable::NotThreadLocal:
2487 case GlobalVariable::GeneralDynamicTLSModel:
2488 Out <<
"thread_local ";
2490 case GlobalVariable::LocalDynamicTLSModel:
2491 Out <<
"thread_local(localdynamic) ";
2493 case GlobalVariable::InitialExecTLSModel:
2494 Out <<
"thread_local(initialexec) ";
2496 case GlobalVariable::LocalExecTLSModel:
2497 Out <<
"thread_local(localexec) ";
2506 case GlobalVariable::UnnamedAddr::Local:
2507 return "local_unnamed_addr";
2508 case GlobalVariable::UnnamedAddr::Global:
2509 return "unnamed_addr";
2520 if (isa<GlobalVariable>(GO))
2534 Out <<
"; Materializable\n";
2553 Out << (GV->
isConstant() ?
"constant " :
"global ");
2562 Out <<
", section \"";
2572 printMetadataAttachments(MDs,
", ");
2576 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs);
2578 printInfoComment(*GV);
2583 Out <<
"; Materializable\n";
2596 if (isa<GlobalAlias>(GIS))
2598 else if (isa<GlobalIFunc>(GIS))
2610 TypePrinter.print(GIS->
getType(), Out);
2611 Out <<
" <<NULL ALIASEE>>";
2613 writeOperand(IS, !isa<ConstantExpr>(IS));
2616 printInfoComment(*GIS);
2620 void AssemblyWriter::printComdat(
const Comdat *
C) {
2624 void AssemblyWriter::printTypeIdentities() {
2625 if (TypePrinter.NumberedTypes.empty() &&
2626 TypePrinter.NamedTypes.empty())
2633 std::vector<StructType*> NumberedTypes(TypePrinter.NumberedTypes.size());
2635 TypePrinter.NumberedTypes.begin(), E = TypePrinter.NumberedTypes.end();
2637 assert(I->second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
2638 NumberedTypes[I->second] = I->first;
2642 for (
unsigned i = 0, e = NumberedTypes.size(); i != e; ++i) {
2643 Out <<
'%' << i <<
" = type ";
2647 TypePrinter.printStructBody(NumberedTypes[i], Out);
2651 for (
unsigned i = 0, e = TypePrinter.NamedTypes.size(); i != e; ++i) {
2657 TypePrinter.printStructBody(TypePrinter.NamedTypes[i], Out);
2663 void AssemblyWriter::printFunction(
const Function *F) {
2667 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
2670 Out <<
"; Materializable\n";
2675 std::string AttrStr;
2678 if (!Attr.isStringAttribute()) {
2679 if (!AttrStr.empty()) AttrStr +=
' ';
2684 if (!AttrStr.empty())
2685 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
2688 Machine.incorporateFunction(F);
2694 printMetadataAttachments(MDs,
" ");
2711 Out << Attrs.
getAsString(AttributeList::ReturnIndex) <<
' ';
2735 if (Arg.getArgNo() != 0)
2751 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
2753 Out <<
" section \"";
2761 Out <<
" gc \"" << F->
getGC() <<
'"';
2767 Out <<
" prologue ";
2771 Out <<
" personality ";
2780 printMetadataAttachments(MDs,
" ");
2785 printBasicBlock(&BB);
2793 Machine.purgeFunction();
2800 TypePrinter.print(Arg->
getType(), Out);
2814 void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
2820 Out <<
"\n; <label>:";
2821 int Slot = Machine.getLocalSlot(BB);
2829 Out.PadToColumn(50);
2830 Out <<
"; Error: Block without parent!";
2833 Out.PadToColumn(50);
2838 Out <<
" No predecessors!";
2841 writeOperand(*PI,
false);
2842 for (++PI; PI != PE; ++PI) {
2844 writeOperand(*PI,
false);
2851 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
2855 printInstructionLine(I);
2858 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
2862 void AssemblyWriter::printInstructionLine(
const Instruction &I) {
2863 printInstruction(I);
2869 void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
2879 void AssemblyWriter::printInfoComment(
const Value &V) {
2880 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
2881 printGCRelocateComment(*Relocate);
2883 if (AnnotationWriter)
2884 AnnotationWriter->printInfoComment(V, Out);
2888 void AssemblyWriter::printInstruction(
const Instruction &I) {
2889 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
2900 int SlotNum = Machine.getLocalSlot(&I);
2902 Out <<
"<badref> = ";
2904 Out <<
'%' << SlotNum <<
" = ";
2907 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
2908 if (CI->isMustTailCall())
2910 else if (CI->isTailCall())
2912 else if (CI->isNoTailCall())
2920 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
2921 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
2924 if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isWeak())
2928 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isVolatile()) ||
2929 (isa<StoreInst>(I) && cast<StoreInst>(I).
isVolatile()) ||
2930 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isVolatile()) ||
2931 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).
isVolatile()))
2938 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
2939 Out <<
' ' << CmpInst::getPredicateName(CI->getPredicate());
2942 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
2949 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
2952 writeOperand(BI.getCondition(),
true);
2954 writeOperand(BI.getSuccessor(0),
true);
2956 writeOperand(BI.getSuccessor(1),
true);
2958 }
else if (isa<SwitchInst>(I)) {
2962 writeOperand(
SI.getCondition(),
true);
2964 writeOperand(
SI.getDefaultDest(),
true);
2966 for (
auto Case :
SI.cases()) {
2968 writeOperand(Case.getCaseValue(),
true);
2970 writeOperand(Case.getCaseSuccessor(),
true);
2973 }
else if (isa<IndirectBrInst>(I)) {
2976 writeOperand(Operand,
true);
2985 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
2987 TypePrinter.print(I.
getType(), Out);
2990 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
2991 if (
op) Out <<
", ";
2993 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
2994 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
2999 for (
const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
3001 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
3003 writeOperand(I.
getOperand(0),
true); Out <<
", ";
3005 for (
const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
3007 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
3009 TypePrinter.print(I.
getType(), Out);
3010 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
3013 if (LPI->isCleanup())
3016 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
3017 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
3018 if (LPI->isCatch(i))
3023 writeOperand(LPI->getClause(i),
true);
3025 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) {
3027 writeOperand(CatchSwitch->getParentPad(),
false);
3030 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
3033 writeOperand(PadBB,
true);
3037 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
3038 writeOperand(UnwindDest,
true);
3041 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&I)) {
3043 writeOperand(FPI->getParentPad(),
false);
3045 for (
unsigned Op = 0, NumOps = FPI->getNumArgOperands(); Op < NumOps;
3049 writeOperand(FPI->getArgOperand(Op),
true);
3052 }
else if (isa<ReturnInst>(I) && !Operand) {
3054 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
3056 writeOperand(CRI->getOperand(0),
false);
3059 writeOperand(CRI->getOperand(1),
true);
3060 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) {
3062 writeOperand(CRI->getOperand(0),
false);
3065 if (CRI->hasUnwindDest())
3066 writeOperand(CRI->getOperand(1),
true);
3069 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3076 Operand = CI->getCalledValue();
3082 Out <<
' ' << PAL.
getAsString(AttributeList::ReturnIndex);
3089 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3091 writeOperand(Operand,
false);
3093 for (
unsigned op = 0, Eop = CI->getNumArgOperands();
op < Eop; ++
op) {
3101 if (CI->isMustTailCall() && CI->getParent() &&
3102 CI->getParent()->getParent() &&
3103 CI->getParent()->getParent()->isVarArg())
3110 writeOperandBundles(CI);
3111 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
3112 Operand = II->getCalledValue();
3124 Out <<
' ' << PAL.
getAsString(AttributeList::ReturnIndex);
3131 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3133 writeOperand(Operand,
false);
3135 for (
unsigned op = 0, Eop = II->getNumArgOperands();
op < Eop; ++
op) {
3145 writeOperandBundles(II);
3148 writeOperand(II->getNormalDest(),
true);
3150 writeOperand(II->getUnwindDest(),
true);
3151 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
3153 if (AI->isUsedWithInAlloca())
3155 if (AI->isSwiftError())
3156 Out <<
"swifterror ";
3157 TypePrinter.print(AI->getAllocatedType(), Out);
3163 if (!AI->getArraySize() || AI->isArrayAllocation() ||
3164 !AI->getArraySize()->getType()->isIntegerTy(32)) {
3166 writeOperand(AI->getArraySize(),
true);
3168 if (AI->getAlignment()) {
3169 Out <<
", align " << AI->getAlignment();
3172 unsigned AddrSpace = AI->getType()->getAddressSpace();
3173 if (AddrSpace != 0) {
3174 Out <<
", addrspace(" << AddrSpace <<
')';
3176 }
else if (isa<CastInst>(I)) {
3179 writeOperand(Operand,
true);
3182 TypePrinter.print(I.
getType(), Out);
3183 }
else if (isa<VAArgInst>(I)) {
3186 writeOperand(Operand,
true);
3189 TypePrinter.print(I.
getType(), Out);
3190 }
else if (Operand) {
3191 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
3193 TypePrinter.print(
GEP->getSourceElementType(), Out);
3195 }
else if (
const auto *LI = dyn_cast<LoadInst>(&I)) {
3197 TypePrinter.print(LI->getType(), Out);
3204 bool PrintAllTypes =
false;
3208 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
3209 || isa<ReturnInst>(I)) {
3210 PrintAllTypes =
true;
3216 if (Operand && Operand->
getType() != TheType) {
3217 PrintAllTypes =
true;
3223 if (!PrintAllTypes) {
3225 TypePrinter.print(TheType, Out);
3231 writeOperand(I.
getOperand(i), PrintAllTypes);
3236 if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
3238 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
3239 if (LI->getAlignment())
3240 Out <<
", align " << LI->getAlignment();
3241 }
else if (
const StoreInst *
SI = dyn_cast<StoreInst>(&I)) {
3243 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
3244 if (
SI->getAlignment())
3245 Out <<
", align " <<
SI->getAlignment();
3247 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
3248 CXI->getFailureOrdering(), CXI->getSyncScopeID());
3249 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
3250 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
3251 RMWI->getSyncScopeID());
3252 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
3253 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
3259 printMetadataAttachments(InstMD,
", ");
3262 printInfoComment(I);
3265 void AssemblyWriter::printMetadataAttachments(
3271 if (MDNames.empty())
3272 MDs[0].
second->getContext().getMDKindNames(MDNames);
3274 for (
const auto &I : MDs) {
3275 unsigned Kind = I.first;
3277 if (Kind < MDNames.size()) {
3281 Out <<
"!<unknown kind #" << Kind <<
">";
3287 void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
3288 Out <<
'!' << Slot <<
" = ";
3289 printMDNodeBody(Node);
3293 void AssemblyWriter::writeAllMDNodes() {
3295 Nodes.
resize(Machine.mdn_size());
3298 Nodes[I->second] = cast<MDNode>(I->first);
3300 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
3301 writeMDNode(i, Nodes[i]);
3305 void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
3309 void AssemblyWriter::writeAllAttributeGroups() {
3310 std::vector<std::pair<AttributeSet, unsigned>> asVec;
3311 asVec.resize(Machine.as_size());
3315 asVec[I->second] = *I;
3317 for (
const auto &I : asVec)
3318 Out <<
"attributes #" << I.second <<
" = { "
3319 << I.first.getAsString(
true) <<
" }\n";
3322 void AssemblyWriter::printUseListOrder(
const UseListOrder &Order) {
3327 Out <<
"uselistorder";
3329 IsInFunction ?
nullptr : dyn_cast<BasicBlock>(Order.
V)) {
3331 writeOperand(BB->getParent(),
false);
3333 writeOperand(BB,
false);
3336 writeOperand(Order.
V,
true);
3342 for (
unsigned I = 1, E = Order.
Shuffle.size(); I !=
E; ++
I)
3343 Out <<
", " << Order.
Shuffle[I];
3347 void AssemblyWriter::printUseLists(
const Function *F) {
3349 [&]() {
return !UseListOrders.empty() && UseListOrders.back().F ==
F; };
3354 Out <<
"\n; uselistorder directives\n";
3356 printUseListOrder(UseListOrders.back());
3357 UseListOrders.pop_back();
3366 bool ShouldPreserveUseListOrder,
3367 bool IsForDebug)
const {
3370 AssemblyWriter W(OS, SlotTable, this->
getParent(), AAW,
3372 ShouldPreserveUseListOrder);
3373 W.printFunction(
this);
3377 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
3380 AssemblyWriter W(OS, SlotTable,
this, AAW, IsForDebug,
3381 ShouldPreserveUseListOrder);
3382 W.printModule(
this);
3388 AssemblyWriter W(OS, SlotTable,
getParent(),
nullptr, IsForDebug);
3389 W.printNamedMDNode(
this);
3393 bool IsForDebug)
const {
3400 SlotTable = &*LocalST;
3404 AssemblyWriter W(OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
3405 W.printNamedMDNode(
this);
3410 ROS <<
" = comdat ";
3417 ROS <<
"exactmatch";
3423 ROS <<
"noduplicates";
3435 TP.print(const_cast<Type*>(
this), OS);
3441 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
3444 TP.printStructBody(STy, OS);
3449 if (
const auto *CI = dyn_cast<CallInst>(&I))
3450 if (
Function *F = CI->getCalledFunction())
3453 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
3454 if (isa<MDNode>(V->getMetadata()))
3460 bool ShouldInitializeAllMetadata =
false;
3461 if (
auto *I = dyn_cast<Instruction>(
this))
3463 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
3464 ShouldInitializeAllMetadata =
true;
3467 print(ROS, MST, IsForDebug);
3471 bool IsForDebug)
const {
3473 SlotTracker EmptySlotTable(static_cast<const Module *>(
nullptr));
3476 auto incorporateFunction = [&](
const Function *
F) {
3481 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
3484 W.printInstruction(*I);
3485 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
3486 incorporateFunction(BB->getParent());
3487 AssemblyWriter W(OS, SlotTable,
getModuleFromVal(BB),
nullptr, IsForDebug);
3488 W.printBasicBlock(BB);
3489 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
3490 AssemblyWriter W(OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
3493 else if (
const Function *F = dyn_cast<Function>(GV))
3496 W.printIndirectSymbol(cast<GlobalIndirectSymbol>(GV));
3497 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
3499 }
else if (
const Constant *C = dyn_cast<Constant>(
this)) {
3500 TypePrinting TypePrinter;
3501 TypePrinter.print(C->getType(), OS);
3504 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
3516 if (V.
hasName() || isa<GlobalValue>(V) ||
3517 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
3526 TypePrinting TypePrinter;
3528 TypePrinter.incorporateTypes(*M);
3530 TypePrinter.print(V.
getType(), O);
3548 M, isa<MetadataAsValue>(
this));
3564 bool OnlyAsOperand) {
3567 TypePrinting TypePrinter;
3569 TypePrinter.incorporateTypes(*M);
3575 if (OnlyAsOperand || !N)
3599 const Module *M,
bool )
const {
3603 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Appends all attachments for the global to MDs, sorting by attachment ID.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Calling convention used for Mesa compute shaders.
static const fltSemantics & IEEEquad() LLVM_READNONE
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
static SlotTracker * createSlotTracker(const Value *V)
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
StringRef getName() const
void push_back(const T &Elt)
LinkageTypes getLinkage() const
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
This class is the base class for the comparison instructions.
iterator_range< use_iterator > uses()
VisibilityTypes getVisibility() const
*p = old <signed v ? old : v
unsigned getNumOperandBundles() const
This class represents an incoming formal argument to a Function.
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
Constant * getPrologueData() const
Get the prologue data associated with this function.
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.
Atomic ordering constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
void PrintEscapedString(StringRef Name, raw_ostream &Out)
PrintEscapedString - Print each character of the specified string, escaping it if it is not printable...
float convertToFloat() const
2: 32-bit floating point type
Calling convention used for AVR signal routines.
An instruction for ordering other memory operations.
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
static void writeAtomicRMWOperation(raw_ostream &Out, AtomicRMWInst::BinOp Op)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
UnnamedAddr getUnnamedAddr() const
Type * getValueType() const
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
*p = old <unsigned v ? old : v
static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)
*p = old >unsigned v ? old : v
void initialize()
This function does the actual initialization.
The data referenced by the COMDAT must be the same size.
PTX_Kernel - Call to a PTX kernel.
const Function * getParent() const
Return the enclosing method, or null if none.
bool hasPrologueData() const
Check whether this function has prologue data.
Calling convention used for Mesa geometry shaders.
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.
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
Get all metadata attached to this Instruction.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
X86_ThisCall - Similar to X86_StdCall.
This defines the Use class.
Type * getElementType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
*p = old >signed v ? old : v
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)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
StringRef getName() const
Return a constant reference to the value's name.
SlotTracker * getMachine()
Lazily creates a slot tracker.
static void predictValueUseListOrder(const Value *V, const Function *F, OrderMap &OM, UseListOrderStack &Stack)
static const char * getLinkagePrintName(GlobalValue::LinkageTypes LT)
AttributeList getAttributes() const
Return the attribute list for this Function.
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
X86_INTR - x86 hardware interrupt context.
The address of a basic block.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
Value * getDerivedPtr() const
std::vector< unsigned > Shuffle
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
static OrderMap orderModule(const Module *M)
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand)
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
param_iterator param_end() const
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
Constant * getPersonalityFn() const
Get the personality function associated with this function.
This file contains the simple types necessary to represent the attributes associated with functions a...
APInt bitcastToAPInt() const
The linker may choose any COMDAT.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
Type * getVectorElementType() const
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
StringRef getName() const
This file implements a class to represent arbitrary precision integral constant values and operations...
Calling convention used for Mesa hull shaders.
LLVM_NODISCARD bool empty() const
AtomicOrdering
Atomic ordering for LLVM's memory model.
void print(raw_ostream &OS, bool IsForDebug=false) const
Class to represent function types.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
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
Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Value * getBasePtr() const
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source...
StringRef getSection() const
Get the custom section of this global if it has one.
TypeID getTypeID() const
Return the type id for the type.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
AttributeSet getAttributes() const
Return the attribute set for this global.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
Structure to hold a use-list order.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
const char * getOpcodeName() const
Used for AVR interrupt routines.
Type * getElementType() const
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
Class to represent pointers.
bool hasOperandBundles() const
bool global_empty() const
iterator find(const_arg_type_t< KeyT > Val)
11: Arbitrary bit width integers
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool hasSection() const
Check if this global has a custom object file section.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
This class provides computation of slot numbers for LLVM Assembly writing.
Type * getParamType(unsigned i) const
Parameter type accessors.
Type * getReturnType() const
Returns the type of the ret val.
bool isExternallyInitialized() const
No other Module may specify this COMDAT.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
void dump() const
Dump the module to stderr (for debugging).
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
static void predictValueUseListOrderImpl(const Value *V, const Function *F, unsigned ID, const OrderMap &OM, UseListOrderStack &Stack)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
HHVM calling convention for invoking C/C++ helpers.
Conditional or Unconditional Branch instruction.
const Comdat * getComdat() const
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
param_iterator param_begin() const
std::vector< UseListOrder > UseListOrderStack
ConstantFP - Floating Point Values [float, double].
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
Check whether this function has a personality 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)
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
MDNode * getOperand(unsigned i) const
uint64_t getNumElements() const
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)
SelectionKind getSelectionKind() const
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
static const Module * getModuleFromVal(const Value *V)
The data referenced by the COMDAT must be the same.
X86_FastCall - 'fast' analog of X86_StdCall.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
void incorporateFunction(const Function &F)
Incorporate the given function.
Calling convention used for Mesa vertex shaders.
static bool isAtomic(Instruction *I)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
OperandBundleUse getOperandBundleAt(unsigned Index) const
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
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)
Turn the specified name into an 'LLVM name', which is either prefixed with % (if the string only cont...
reverse_iterator rbegin()
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool hasExternalLinkage() const
const MDOperand & getOperand(unsigned I) const
static const fltSemantics & IEEEsingle() LLVM_READNONE
Synchronized with respect to all concurrently executing threads.
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
16: SIMD 'packed' format, or other vector type
bool isMaterializable() const
static const char * Separator
std::string getAsString(bool InAttrGrp=false) const
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...
bool hasAttributes() const
Return true if attributes exists in this set.
Calling convention used for Mesa pixel shaders.
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)
Type::subtype_iterator param_iterator
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
virtual ~AssemblyAnnotationWriter()
The linker will choose the largest COMDAT.
static bool isReferencingMDNode(const Instruction &I)
const BasicBlock & getEntryBlock() const
AttributeSet getFnAttributes() const
The function attributes are returned.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class to represent vector types.
bool hasInitializer() const
Definitions have initializers, declarations don't.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
static const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
static bool isWeak(const MCSymbolELF &Sym)
LinkageTypes
An enumeration for the kinds of linkage for global values.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
StringRef getName() const
Return the name for this struct type if it has an identity.
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
double convertToDouble() const
The C convention as implemented on Windows/x86-64 and AArch64.
static char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
llvm_unreachable("Unknown RegBank!")
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
ThreadLocalMode getThreadLocalMode() const
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
PointerType * getType() const
Global values are always pointers.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static void orderValue(const Value *V, OrderMap &OM)
Establish a view to a call site for examination.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
const std::string & getGC() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
bool hasPrefixData() const
Check whether this function has prefix data.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
iterator_range< ifunc_iterator > ifuncs()
const std::string & getSourceFileName() const
Get the module's original source file name.
Constant * getPrefixData() const
Get the prefix data associated with this function.
PTX_Device - Call to a PTX device function.
const Module * getModule() const
const Constant * getIndirectSymbol() const
This file defines passes to print out IR in various granularities.
3: 64-bit floating point type
Type * getReturnType() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents calls to the gc.relocate intrinsic.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
A vector that has set insertion semantics.
DLLStorageClassTypes getDLLStorageClass() const
unsigned getNumOperands() const
This class implements an extremely fast bulk output stream that can only output to a stream...
void print(raw_ostream &ROS, bool IsForDebug=false) const
iterator_range< global_iterator > globals()
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.
Register calling convention used for parameters transfer optimization.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
static bool isVolatile(Instruction *Inst)
9: MMX vectors (64 bits, X86 specific)
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
void emplace(ArgTypes &&...Args)
Create a new object by constructing it in place with the given arguments.
Calling convention for AMDGPU code object kernels.
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
const fltSemantics & getSemantics() const
static UseListOrderStack predictUseListOrder(const Module *M)
const BasicBlock * getParent() const
int getAttributeGroupSlot(AttributeSet AS)
iterator_range< arg_iterator > args()
Module * getParent()
Get the module that holds this named metadata collection.
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
5: 128-bit floating point type (112-bit mantissa)
iterator_range< alias_iterator > aliases()