31#include "llvm/Config/llvm-config.h"
107 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V))
108 if (
const auto *VAM = dyn_cast<ValueAsMetadata>(MAV->getMetadata()))
109 return VAM->getValue();
117 if (
const Constant *
C = dyn_cast<Constant>(V))
118 if (
C->getNumOperands() && !isa<GlobalValue>(
C))
119 for (
const Value *
Op :
C->operands())
120 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
125 unsigned ID = OM.size() + 1;
133 if (
G.hasInitializer())
134 if (!isa<GlobalValue>(
G.getInitializer()))
139 if (!isa<GlobalValue>(
A.getAliasee()))
144 if (!isa<GlobalValue>(
I.getResolver()))
149 for (
const Use &U :
F.operands())
150 if (!isa<GlobalValue>(U.get()))
155 if (
F.isDeclaration())
163 for (
const Value *
Op :
I.operands()) {
165 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
176static std::vector<unsigned>
179 using Entry = std::pair<const Use *, unsigned>;
181 for (
const Use &U : V->uses())
183 if (OM.lookup(U.getUser()))
184 List.push_back(std::make_pair(&U,
List.size()));
193 bool GetsReversed = !isa<BasicBlock>(V);
194 if (
auto *BA = dyn_cast<BlockAddress>(V))
195 ID = OM.lookup(BA->getBasicBlock());
197 const Use *LU = L.first;
198 const Use *RU = R.first;
202 auto LID = OM.lookup(LU->getUser());
203 auto RID = OM.lookup(RU->getUser());
223 return LU->getOperandNo() < RU->getOperandNo();
224 return LU->getOperandNo() > RU->getOperandNo();
232 std::vector<unsigned> Shuffle(
List.size());
233 for (
size_t I = 0,
E =
List.size();
I !=
E; ++
I)
234 Shuffle[
I] =
List[
I].second;
241 for (
const auto &Pair : OM) {
242 const Value *V = Pair.first;
243 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
246 std::vector<unsigned> Shuffle =
252 if (
auto *
I = dyn_cast<Instruction>(V))
253 F =
I->getFunction();
254 if (
auto *
A = dyn_cast<Argument>(V))
256 if (
auto *BB = dyn_cast<BasicBlock>(V))
258 ULOM[
F][V] = std::move(Shuffle);
264 if (
const Argument *MA = dyn_cast<Argument>(V))
265 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
267 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
268 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
271 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
272 return M ? M->getParent() :
nullptr;
275 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
276 return GV->getParent();
278 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
279 for (
const User *U : MAV->users())
280 if (isa<Instruction>(U))
292 return M ? M->getParent() :
nullptr;
301 default: Out <<
"cc" << cc;
break;
324 Out <<
"aarch64_sve_vector_pcs";
327 Out <<
"aarch64_sme_preservemost_from_x0";
330 Out <<
"aarch64_sme_preservemost_from_x2";
358 Out <<
"amdgpu_cs_chain";
361 Out <<
"amdgpu_cs_chain_preserve";
378 assert(!
Name.empty() &&
"Cannot get empty name!");
381 bool NeedsQuotes = isdigit(
static_cast<unsigned char>(
Name[0]));
383 for (
unsigned char C :
Name) {
388 if (!isalnum(
static_cast<unsigned char>(
C)) &&
C !=
'-' &&
C !=
'.' &&
405 printEscapedString(
Name,
OS);
441 if (isa<ScalableVectorType>(Ty))
443 Out << Mask.size() <<
" x i32> ";
444 bool FirstElt =
true;
445 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
446 Out <<
"zeroinitializer";
451 for (
int Elt : Mask) {
470 TypePrinting(
const Module *M =
nullptr) : DeferredM(
M) {}
472 TypePrinting(
const TypePrinting &) =
delete;
473 TypePrinting &operator=(
const TypePrinting &) =
delete;
479 std::vector<StructType *> &getNumberedTypes();
488 void incorporateTypes();
498 std::vector<StructType *> NumberedTypes;
508std::vector<StructType *> &TypePrinting::getNumberedTypes() {
514 if (NumberedTypes.size() == Type2Number.size())
515 return NumberedTypes;
517 NumberedTypes.resize(Type2Number.size());
518 for (
const auto &
P : Type2Number) {
519 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
520 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
521 NumberedTypes[
P.second] =
P.first;
523 return NumberedTypes;
526bool TypePrinting::empty() {
528 return NamedTypes.empty() && Type2Number.empty();
531void TypePrinting::incorporateTypes() {
535 NamedTypes.run(*DeferredM,
false);
540 unsigned NextNumber = 0;
542 std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();
545 if (STy->isLiteral())
548 if (STy->getName().empty())
549 Type2Number[STy] = NextNumber++;
554 NamedTypes.erase(NextToUse, NamedTypes.end());
575 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
580 print(FTy->getReturnType(),
OS);
583 for (
Type *Ty : FTy->params()) {
596 return printStructBody(STy,
OS);
602 const auto I = Type2Number.find(STy);
603 if (
I != Type2Number.end())
604 OS <<
'%' <<
I->second;
606 OS <<
"%\"type " << STy <<
'\"';
618 OS <<
'[' << ATy->getNumElements() <<
" x ";
619 print(ATy->getElementType(),
OS);
630 OS <<
EC.getKnownMinValue() <<
" x ";
631 print(PTy->getElementType(),
OS);
647 OS <<
", " << *Inner;
649 OS <<
", " << IntParam;
700 const Function* TheFunction =
nullptr;
701 bool FunctionProcessed =
false;
702 bool ShouldInitializeAllMetadata;
707 ProcessFunctionHookFn;
722 unsigned mdnNext = 0;
730 unsigned ModulePathNext = 0;
734 unsigned GUIDNext = 0;
738 unsigned TypeIdNext = 0;
743 unsigned TypeIdCompatibleVtableNext = 0;
752 bool ShouldInitializeAllMetadata =
false);
760 bool ShouldInitializeAllMetadata =
false);
794 FunctionProcessed =
false;
833 void CreateMetadataSlot(
const MDNode *
N);
836 void CreateFunctionSlot(
const Value *V);
841 inline void CreateModulePathSlot(
StringRef Path);
844 void CreateTypeIdCompatibleVtableSlot(
StringRef Id);
848 void processModule();
853 void processFunction();
856 void processGlobalObjectMetadata(
const GlobalObject &GO);
859 void processFunctionMetadata(
const Function &
F);
865 void processDbgRecordMetadata(
const DbgRecord &DPV);
875 bool ShouldInitializeAllMetadata)
876 : ShouldCreateStorage(M),
877 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
882 if (!ShouldCreateStorage)
885 ShouldCreateStorage =
false;
887 std::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
888 Machine = MachineStorage.get();
889 if (ProcessModuleHookFn)
891 if (ProcessFunctionHookFn)
911 assert(F &&
"No function incorporated");
918 ProcessModuleHookFn = Fn;
924 ProcessFunctionHookFn = Fn;
928 if (
const Argument *FA = dyn_cast<Argument>(V))
935 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
941 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
944 if (
const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
947 if (
const Function *Func = dyn_cast<Function>(V))
954#define ST_DEBUG(X) dbgs() << X
962 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
967 : TheModule(
F ?
F->
getParent() : nullptr), TheFunction(
F),
968 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
971 : TheModule(nullptr), ShouldInitializeAllMetadata(
false), TheIndex(
Index) {}
979 if (TheFunction && !FunctionProcessed)
986 int NumSlots = processIndex();
993void SlotTracker::processModule() {
999 CreateModuleSlot(&Var);
1000 processGlobalObjectMetadata(Var);
1001 auto Attrs = Var.getAttributes();
1002 if (Attrs.hasAttributes())
1003 CreateAttributeSetSlot(Attrs);
1008 CreateModuleSlot(&
A);
1013 CreateModuleSlot(&
I);
1018 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
1019 CreateMetadataSlot(NMD.getOperand(i));
1025 CreateModuleSlot(&
F);
1027 if (ShouldInitializeAllMetadata)
1028 processFunctionMetadata(
F);
1034 CreateAttributeSetSlot(FnAttrs);
1037 if (ProcessModuleHookFn)
1038 ProcessModuleHookFn(
this, TheModule, ShouldInitializeAllMetadata);
1044void SlotTracker::processFunction() {
1045 ST_DEBUG(
"begin processFunction!\n");
1049 if (!ShouldInitializeAllMetadata)
1050 processFunctionMetadata(*TheFunction);
1054 AE = TheFunction->
arg_end(); AI != AE; ++AI)
1056 CreateFunctionSlot(&*AI);
1058 ST_DEBUG(
"Inserting Instructions:\n");
1061 for (
auto &BB : *TheFunction) {
1063 CreateFunctionSlot(&BB);
1065 for (
auto &
I : BB) {
1066 if (!
I.getType()->isVoidTy() && !
I.hasName())
1067 CreateFunctionSlot(&
I);
1071 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1074 if (
Attrs.hasAttributes())
1075 CreateAttributeSetSlot(Attrs);
1080 if (ProcessFunctionHookFn)
1081 ProcessFunctionHookFn(
this, TheFunction, ShouldInitializeAllMetadata);
1083 FunctionProcessed =
true;
1085 ST_DEBUG(
"end processFunction!\n");
1089int SlotTracker::processIndex() {
1096 std::vector<StringRef> ModulePaths;
1098 ModulePaths.push_back(ModPath);
1099 llvm::sort(ModulePaths.begin(), ModulePaths.end());
1100 for (
auto &ModPath : ModulePaths)
1101 CreateModulePathSlot(ModPath);
1104 GUIDNext = ModulePathNext;
1106 for (
auto &GlobalList : *TheIndex)
1107 CreateGUIDSlot(GlobalList.first);
1110 TypeIdCompatibleVtableNext = GUIDNext;
1111 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1112 CreateTypeIdCompatibleVtableSlot(TId.first);
1115 TypeIdNext = TypeIdCompatibleVtableNext;
1116 for (
const auto &TID : TheIndex->typeIds())
1117 CreateTypeIdSlot(TID.second.first);
1123void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1126 for (
auto &MD : MDs)
1127 CreateMetadataSlot(MD.second);
1130void SlotTracker::processFunctionMetadata(
const Function &
F) {
1131 processGlobalObjectMetadata(
F);
1132 for (
auto &BB :
F) {
1133 for (
auto &
I : BB) {
1134 for (
const DbgRecord &DR :
I.getDbgRecordRange())
1135 processDbgRecordMetadata(DR);
1136 processInstructionMetadata(
I);
1141void SlotTracker::processDbgRecordMetadata(
const DbgRecord &DR) {
1142 if (
const DPValue *DPV = dyn_cast<const DPValue>(&DR)) {
1146 CreateMetadataSlot(DPV->getRawVariable());
1147 if (DPV->isDbgAssign())
1148 CreateMetadataSlot(cast<MDNode>(DPV->getRawAssignID()));
1149 }
else if (
const DPLabel *DPL = dyn_cast<const DPLabel>(&DR)) {
1150 CreateMetadataSlot(DPL->getRawLabel());
1157void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1159 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
1160 if (
Function *
F = CI->getCalledFunction())
1161 if (
F->isIntrinsic())
1162 for (
auto &
Op :
I.operands())
1163 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1164 if (
MDNode *
N = dyn_cast<MDNode>(
V->getMetadata()))
1165 CreateMetadataSlot(
N);
1169 I.getAllMetadata(MDs);
1170 for (
auto &MD : MDs)
1171 CreateMetadataSlot(MD.second);
1178 ST_DEBUG(
"begin purgeFunction!\n");
1180 TheFunction =
nullptr;
1181 FunctionProcessed =
false;
1192 return MI == mMap.
end() ? -1 : (int)
MI->second;
1198 ProcessModuleHookFn = Fn;
1204 ProcessFunctionHookFn = Fn;
1217 return MI == mdnMap.
end() ? -1 : (int)
MI->second;
1222 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1228 return FI == fMap.
end() ? -1 : (int)FI->second;
1237 return AI == asMap.
end() ? -1 : (int)AI->second;
1245 auto I = ModulePathMap.
find(Path);
1246 return I == ModulePathMap.
end() ? -1 : (int)
I->second;
1255 return I == GUIDMap.
end() ? -1 : (int)
I->second;
1263 auto I = TypeIdMap.
find(Id);
1264 return I == TypeIdMap.
end() ? -1 : (int)
I->second;
1272 auto I = TypeIdCompatibleVtableMap.
find(Id);
1273 return I == TypeIdCompatibleVtableMap.
end() ? -1 : (int)
I->second;
1277void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1278 assert(V &&
"Can't insert a null Value into SlotTracker!");
1279 assert(!V->getType()->isVoidTy() &&
"Doesn't need a slot!");
1280 assert(!V->hasName() &&
"Doesn't need a slot!");
1282 unsigned DestSlot = mNext++;
1285 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1288 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1289 (isa<Function>(V) ?
'F' :
1290 (isa<GlobalAlias>(V) ?
'A' :
1291 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1295void SlotTracker::CreateFunctionSlot(
const Value *V) {
1296 assert(!V->getType()->isVoidTy() && !V->hasName() &&
"Doesn't need a slot!");
1298 unsigned DestSlot = fNext++;
1302 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1303 DestSlot <<
" [o]\n");
1307void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1308 assert(
N &&
"Can't insert a null Value into SlotTracker!");
1311 if (isa<DIExpression>(
N))
1314 unsigned DestSlot = mdnNext;
1315 if (!mdnMap.
insert(std::make_pair(
N, DestSlot)).second)
1320 for (
unsigned i = 0, e =
N->getNumOperands(); i != e; ++i)
1321 if (
const MDNode *
Op = dyn_cast_or_null<MDNode>(
N->getOperand(i)))
1322 CreateMetadataSlot(
Op);
1325void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1329 if (
I != asMap.
end())
1332 unsigned DestSlot = asNext++;
1333 asMap[AS] = DestSlot;
1337void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1338 ModulePathMap[
Path] = ModulePathNext++;
1343 GUIDMap[GUID] = GUIDNext++;
1347void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1348 TypeIdMap[
Id] = TypeIdNext++;
1352void SlotTracker::CreateTypeIdCompatibleVtableSlot(
StringRef Id) {
1353 TypeIdCompatibleVtableMap[
Id] = TypeIdCompatibleVtableNext++;
1358struct AsmWriterContext {
1359 TypePrinting *TypePrinter =
nullptr;
1366 static AsmWriterContext &getEmpty() {
1367 static AsmWriterContext EmptyCtx(
nullptr,
nullptr);
1373 virtual void onWriteMetadataAsOperand(
const Metadata *) {}
1375 virtual ~AsmWriterContext() =
default;
1384 AsmWriterContext &WriterCtx);
1387 AsmWriterContext &WriterCtx,
1388 bool FromValue =
false);
1391 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U))
1392 Out << FPO->getFastMathFlags();
1395 dyn_cast<OverflowingBinaryOperator>(U)) {
1396 if (OBO->hasNoUnsignedWrap())
1398 if (OBO->hasNoSignedWrap())
1401 dyn_cast<PossiblyExactOperator>(U)) {
1405 dyn_cast<PossiblyDisjointInst>(U)) {
1406 if (PDI->isDisjoint())
1409 if (
GEP->isInBounds())
1411 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(U)) {
1412 if (NNI->hasNonNeg())
1428 bool isNaN = APF.
isNaN();
1430 if (!isInf && !isNaN) {
1439 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
isDigit(StrVal[1]))) &&
1440 "[-+]?[0-9] regex does not match!");
1452 static_assert(
sizeof(double) ==
sizeof(
uint64_t),
1453 "assuming that double is 64 bits!");
1511 AsmWriterContext &WriterCtx) {
1512 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1513 Type *Ty = CI->getType();
1522 Out << (CI->getZExtValue() ?
"true" :
"false");
1524 Out << CI->getValue();
1532 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1533 Type *Ty = CFP->getType();
1549 if (isa<ConstantAggregateZero>(CV) || isa<ConstantTargetNone>(CV)) {
1550 Out <<
"zeroinitializer";
1554 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1555 Out <<
"blockaddress(";
1563 if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV)) {
1564 Out <<
"dso_local_equivalent ";
1569 if (
const auto *
NC = dyn_cast<NoCFIValue>(CV)) {
1575 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1576 Type *ETy = CA->getType()->getElementType();
1578 WriterCtx.TypePrinter->print(ETy, Out);
1581 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1583 WriterCtx.TypePrinter->print(ETy, Out);
1594 if (CA->isString()) {
1596 printEscapedString(CA->getAsString(), Out);
1601 Type *ETy = CA->getType()->getElementType();
1603 WriterCtx.TypePrinter->print(ETy, Out);
1606 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1608 WriterCtx.TypePrinter->print(ETy, Out);
1617 if (CS->getType()->isPacked())
1620 unsigned N = CS->getNumOperands();
1623 WriterCtx.TypePrinter->print(CS->getOperand(0)->getType(), Out);
1628 for (
unsigned i = 1; i <
N; i++) {
1630 WriterCtx.TypePrinter->print(CS->getOperand(i)->getType(), Out);
1639 if (CS->getType()->isPacked())
1644 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1645 auto *CVVTy = cast<FixedVectorType>(CV->
getType());
1646 Type *ETy = CVVTy->getElementType();
1648 WriterCtx.TypePrinter->print(ETy, Out);
1651 for (
unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) {
1653 WriterCtx.TypePrinter->print(ETy, Out);
1661 if (isa<ConstantPointerNull>(CV)) {
1666 if (isa<ConstantTokenNone>(CV)) {
1671 if (isa<PoisonValue>(CV)) {
1676 if (isa<UndefValue>(CV)) {
1681 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1682 Out << CE->getOpcodeName();
1684 if (CE->isCompare())
1685 Out << ' ' << static_cast<CmpInst::Predicate>(CE->getPredicate());
1688 std::optional<unsigned> InRangeOp;
1690 WriterCtx.TypePrinter->print(
GEP->getSourceElementType(), Out);
1692 InRangeOp =
GEP->getInRangeIndex();
1698 if (InRangeOp &&
unsigned(OI - CE->op_begin()) == *InRangeOp)
1700 WriterCtx.TypePrinter->print((*OI)->getType(), Out);
1703 if (OI+1 != CE->op_end())
1709 WriterCtx.TypePrinter->print(CE->getType(), Out);
1712 if (CE->getOpcode() == Instruction::ShuffleVector)
1719 Out <<
"<placeholder or erroneous Constant>";
1723 AsmWriterContext &WriterCtx) {
1725 for (
unsigned mi = 0, me =
Node->getNumOperands(); mi != me; ++mi) {
1729 else if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1730 Value *V = MDV->getValue();
1731 WriterCtx.TypePrinter->print(V->getType(), Out);
1736 WriterCtx.onWriteMetadataAsOperand(MD);
1747struct FieldSeparator {
1751 FieldSeparator(
const char *Sep =
", ") : Sep(Sep) {}
1759 return OS <<
FS.Sep;
1762struct MDFieldPrinter {
1765 AsmWriterContext &WriterCtx;
1768 : Out(Out), WriterCtx(AsmWriterContext::getEmpty()) {}
1769 MDFieldPrinter(
raw_ostream &Out, AsmWriterContext &Ctx)
1770 : Out(Out), WriterCtx(Ctx) {}
1772 void printTag(
const DINode *
N);
1776 bool ShouldSkipEmpty =
true);
1778 bool ShouldSkipNull =
true);
1779 template <
class IntTy>
1782 bool ShouldSkipZero);
1784 std::optional<bool>
Default = std::nullopt);
1787 template <
class IntTy,
class Stringifier>
1789 bool ShouldSkipZero =
true);
1797void MDFieldPrinter::printTag(
const DINode *
N) {
1798 Out <<
FS <<
"tag: ";
1806void MDFieldPrinter::printMacinfoType(
const DIMacroNode *
N) {
1807 Out <<
FS <<
"type: ";
1812 Out <<
N->getMacinfoType();
1815void MDFieldPrinter::printChecksum(
1818 printString(
"checksum", Checksum.
Value,
false);
1822 bool ShouldSkipEmpty) {
1823 if (ShouldSkipEmpty &&
Value.empty())
1826 Out <<
FS <<
Name <<
": \"";
1827 printEscapedString(
Value, Out);
1832 AsmWriterContext &WriterCtx) {
1838 WriterCtx.onWriteMetadataAsOperand(MD);
1842 bool ShouldSkipNull) {
1843 if (ShouldSkipNull && !MD)
1846 Out <<
FS <<
Name <<
": ";
1850template <
class IntTy>
1851void MDFieldPrinter::printInt(
StringRef Name, IntTy
Int,
bool ShouldSkipZero) {
1852 if (ShouldSkipZero && !
Int)
1859 bool IsUnsigned,
bool ShouldSkipZero) {
1860 if (ShouldSkipZero &&
Int.isZero())
1863 Out <<
FS <<
Name <<
": ";
1864 Int.print(Out, !IsUnsigned);
1868 std::optional<bool>
Default) {
1871 Out <<
FS <<
Name <<
": " << (
Value ?
"true" :
"false");
1878 Out <<
FS <<
Name <<
": ";
1883 FieldSeparator FlagsFS(
" | ");
1884 for (
auto F : SplitFlags) {
1886 assert(!StringF.empty() &&
"Expected valid flag");
1887 Out << FlagsFS << StringF;
1889 if (Extra || SplitFlags.empty())
1890 Out << FlagsFS << Extra;
1897 Out <<
FS <<
Name <<
": ";
1907 FieldSeparator FlagsFS(
" | ");
1908 for (
auto F : SplitFlags) {
1910 assert(!StringF.empty() &&
"Expected valid flag");
1911 Out << FlagsFS << StringF;
1913 if (Extra || SplitFlags.empty())
1914 Out << FlagsFS << Extra;
1929template <
class IntTy,
class Stringifier>
1931 Stringifier
toString,
bool ShouldSkipZero) {
1935 Out <<
FS <<
Name <<
": ";
1944 AsmWriterContext &WriterCtx) {
1945 Out <<
"!GenericDINode(";
1946 MDFieldPrinter
Printer(Out, WriterCtx);
1948 Printer.printString(
"header",
N->getHeader());
1949 if (
N->getNumDwarfOperands()) {
1950 Out <<
Printer.FS <<
"operands: {";
1952 for (
auto &
I :
N->dwarf_operands()) {
1962 AsmWriterContext &WriterCtx) {
1963 Out <<
"!DILocation(";
1964 MDFieldPrinter
Printer(Out, WriterCtx);
1966 Printer.printInt(
"line",
DL->getLine(),
false);
1967 Printer.printInt(
"column",
DL->getColumn());
1968 Printer.printMetadata(
"scope",
DL->getRawScope(),
false);
1969 Printer.printMetadata(
"inlinedAt",
DL->getRawInlinedAt());
1970 Printer.printBool(
"isImplicitCode",
DL->isImplicitCode(),
1976 AsmWriterContext &WriterCtx) {
1977 Out <<
"!DIAssignID()";
1978 MDFieldPrinter
Printer(Out, WriterCtx);
1982 AsmWriterContext &WriterCtx) {
1983 Out <<
"!DISubrange(";
1984 MDFieldPrinter
Printer(Out, WriterCtx);
1986 auto *Count =
N->getRawCountNode();
1987 if (
auto *CE = dyn_cast_or_null<ConstantAsMetadata>(Count)) {
1988 auto *CV = cast<ConstantInt>(CE->getValue());
1989 Printer.printInt(
"count", CV->getSExtValue(),
1992 Printer.printMetadata(
"count", Count,
true);
1996 auto *LBound =
N->getRawLowerBound();
1997 if (
auto *LE = dyn_cast_or_null<ConstantAsMetadata>(LBound)) {
1998 auto *LV = cast<ConstantInt>(LE->getValue());
1999 Printer.printInt(
"lowerBound", LV->getSExtValue(),
2002 Printer.printMetadata(
"lowerBound", LBound,
true);
2004 auto *UBound =
N->getRawUpperBound();
2005 if (
auto *UE = dyn_cast_or_null<ConstantAsMetadata>(UBound)) {
2006 auto *UV = cast<ConstantInt>(UE->getValue());
2007 Printer.printInt(
"upperBound", UV->getSExtValue(),
2010 Printer.printMetadata(
"upperBound", UBound,
true);
2012 auto *Stride =
N->getRawStride();
2013 if (
auto *SE = dyn_cast_or_null<ConstantAsMetadata>(Stride)) {
2014 auto *SV = cast<ConstantInt>(SE->getValue());
2015 Printer.printInt(
"stride", SV->getSExtValue(),
false);
2017 Printer.printMetadata(
"stride", Stride,
true);
2023 AsmWriterContext &WriterCtx) {
2024 Out <<
"!DIGenericSubrange(";
2025 MDFieldPrinter
Printer(Out, WriterCtx);
2027 auto IsConstant = [&](
Metadata *Bound) ->
bool {
2028 if (
auto *BE = dyn_cast_or_null<DIExpression>(Bound)) {
2029 return BE->isConstant() &&
2036 auto GetConstant = [&](
Metadata *Bound) -> int64_t {
2037 assert(IsConstant(Bound) &&
"Expected constant");
2038 auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2039 return static_cast<int64_t
>(BE->getElement(1));
2042 auto *Count =
N->getRawCountNode();
2043 if (IsConstant(Count))
2044 Printer.printInt(
"count", GetConstant(Count),
2047 Printer.printMetadata(
"count", Count,
true);
2049 auto *LBound =
N->getRawLowerBound();
2050 if (IsConstant(LBound))
2051 Printer.printInt(
"lowerBound", GetConstant(LBound),
2054 Printer.printMetadata(
"lowerBound", LBound,
true);
2056 auto *UBound =
N->getRawUpperBound();
2057 if (IsConstant(UBound))
2058 Printer.printInt(
"upperBound", GetConstant(UBound),
2061 Printer.printMetadata(
"upperBound", UBound,
true);
2063 auto *Stride =
N->getRawStride();
2064 if (IsConstant(Stride))
2065 Printer.printInt(
"stride", GetConstant(Stride),
2068 Printer.printMetadata(
"stride", Stride,
true);
2074 AsmWriterContext &) {
2075 Out <<
"!DIEnumerator(";
2077 Printer.printString(
"name",
N->getName(),
false);
2078 Printer.printAPInt(
"value",
N->getValue(),
N->isUnsigned(),
2080 if (
N->isUnsigned())
2081 Printer.printBool(
"isUnsigned",
true);
2086 AsmWriterContext &) {
2087 Out <<
"!DIBasicType(";
2089 if (
N->getTag() != dwarf::DW_TAG_base_type)
2091 Printer.printString(
"name",
N->getName());
2092 Printer.printInt(
"size",
N->getSizeInBits());
2093 Printer.printInt(
"align",
N->getAlignInBits());
2094 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2096 Printer.printDIFlags(
"flags",
N->getFlags());
2101 AsmWriterContext &WriterCtx) {
2102 Out <<
"!DIStringType(";
2103 MDFieldPrinter
Printer(Out, WriterCtx);
2104 if (
N->getTag() != dwarf::DW_TAG_string_type)
2106 Printer.printString(
"name",
N->getName());
2107 Printer.printMetadata(
"stringLength",
N->getRawStringLength());
2108 Printer.printMetadata(
"stringLengthExpression",
N->getRawStringLengthExp());
2109 Printer.printMetadata(
"stringLocationExpression",
2110 N->getRawStringLocationExp());
2111 Printer.printInt(
"size",
N->getSizeInBits());
2112 Printer.printInt(
"align",
N->getAlignInBits());
2113 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2119 AsmWriterContext &WriterCtx) {
2120 Out <<
"!DIDerivedType(";
2121 MDFieldPrinter
Printer(Out, WriterCtx);
2123 Printer.printString(
"name",
N->getName());
2124 Printer.printMetadata(
"scope",
N->getRawScope());
2125 Printer.printMetadata(
"file",
N->getRawFile());
2126 Printer.printInt(
"line",
N->getLine());
2127 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2129 Printer.printInt(
"size",
N->getSizeInBits());
2130 Printer.printInt(
"align",
N->getAlignInBits());
2131 Printer.printInt(
"offset",
N->getOffsetInBits());
2132 Printer.printDIFlags(
"flags",
N->getFlags());
2133 Printer.printMetadata(
"extraData",
N->getRawExtraData());
2134 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2135 Printer.printInt(
"dwarfAddressSpace", *DWARFAddressSpace,
2137 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2142 AsmWriterContext &WriterCtx) {
2143 Out <<
"!DICompositeType(";
2144 MDFieldPrinter
Printer(Out, WriterCtx);
2146 Printer.printString(
"name",
N->getName());
2147 Printer.printMetadata(
"scope",
N->getRawScope());
2148 Printer.printMetadata(
"file",
N->getRawFile());
2149 Printer.printInt(
"line",
N->getLine());
2150 Printer.printMetadata(
"baseType",
N->getRawBaseType());
2151 Printer.printInt(
"size",
N->getSizeInBits());
2152 Printer.printInt(
"align",
N->getAlignInBits());
2153 Printer.printInt(
"offset",
N->getOffsetInBits());
2154 Printer.printDIFlags(
"flags",
N->getFlags());
2155 Printer.printMetadata(
"elements",
N->getRawElements());
2156 Printer.printDwarfEnum(
"runtimeLang",
N->getRuntimeLang(),
2158 Printer.printMetadata(
"vtableHolder",
N->getRawVTableHolder());
2159 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2160 Printer.printString(
"identifier",
N->getIdentifier());
2161 Printer.printMetadata(
"discriminator",
N->getRawDiscriminator());
2162 Printer.printMetadata(
"dataLocation",
N->getRawDataLocation());
2163 Printer.printMetadata(
"associated",
N->getRawAssociated());
2164 Printer.printMetadata(
"allocated",
N->getRawAllocated());
2165 if (
auto *RankConst =
N->getRankConst())
2166 Printer.printInt(
"rank", RankConst->getSExtValue(),
2169 Printer.printMetadata(
"rank",
N->getRawRank(),
true);
2170 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2175 AsmWriterContext &WriterCtx) {
2176 Out <<
"!DISubroutineType(";
2177 MDFieldPrinter
Printer(Out, WriterCtx);
2178 Printer.printDIFlags(
"flags",
N->getFlags());
2180 Printer.printMetadata(
"types",
N->getRawTypeArray(),
2188 Printer.printString(
"filename",
N->getFilename(),
2190 Printer.printString(
"directory",
N->getDirectory(),
2193 if (
N->getChecksum())
2194 Printer.printChecksum(*
N->getChecksum());
2201 AsmWriterContext &WriterCtx) {
2202 Out <<
"!DICompileUnit(";
2203 MDFieldPrinter
Printer(Out, WriterCtx);
2204 Printer.printDwarfEnum(
"language",
N->getSourceLanguage(),
2206 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2207 Printer.printString(
"producer",
N->getProducer());
2208 Printer.printBool(
"isOptimized",
N->isOptimized());
2209 Printer.printString(
"flags",
N->getFlags());
2210 Printer.printInt(
"runtimeVersion",
N->getRuntimeVersion(),
2212 Printer.printString(
"splitDebugFilename",
N->getSplitDebugFilename());
2213 Printer.printEmissionKind(
"emissionKind",
N->getEmissionKind());
2214 Printer.printMetadata(
"enums",
N->getRawEnumTypes());
2215 Printer.printMetadata(
"retainedTypes",
N->getRawRetainedTypes());
2216 Printer.printMetadata(
"globals",
N->getRawGlobalVariables());
2217 Printer.printMetadata(
"imports",
N->getRawImportedEntities());
2218 Printer.printMetadata(
"macros",
N->getRawMacros());
2219 Printer.printInt(
"dwoId",
N->getDWOId());
2220 Printer.printBool(
"splitDebugInlining",
N->getSplitDebugInlining(),
true);
2221 Printer.printBool(
"debugInfoForProfiling",
N->getDebugInfoForProfiling(),
2223 Printer.printNameTableKind(
"nameTableKind",
N->getNameTableKind());
2224 Printer.printBool(
"rangesBaseAddress",
N->getRangesBaseAddress(),
false);
2225 Printer.printString(
"sysroot",
N->getSysRoot());
2226 Printer.printString(
"sdk",
N->getSDK());
2231 AsmWriterContext &WriterCtx) {
2232 Out <<
"!DISubprogram(";
2233 MDFieldPrinter
Printer(Out, WriterCtx);
2234 Printer.printString(
"name",
N->getName());
2235 Printer.printString(
"linkageName",
N->getLinkageName());
2236 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2237 Printer.printMetadata(
"file",
N->getRawFile());
2238 Printer.printInt(
"line",
N->getLine());
2239 Printer.printMetadata(
"type",
N->getRawType());
2240 Printer.printInt(
"scopeLine",
N->getScopeLine());
2241 Printer.printMetadata(
"containingType",
N->getRawContainingType());
2242 if (
N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
2243 N->getVirtualIndex() != 0)
2244 Printer.printInt(
"virtualIndex",
N->getVirtualIndex(),
false);
2245 Printer.printInt(
"thisAdjustment",
N->getThisAdjustment());
2246 Printer.printDIFlags(
"flags",
N->getFlags());
2247 Printer.printDISPFlags(
"spFlags",
N->getSPFlags());
2248 Printer.printMetadata(
"unit",
N->getRawUnit());
2249 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2250 Printer.printMetadata(
"declaration",
N->getRawDeclaration());
2251 Printer.printMetadata(
"retainedNodes",
N->getRawRetainedNodes());
2252 Printer.printMetadata(
"thrownTypes",
N->getRawThrownTypes());
2253 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2254 Printer.printString(
"targetFuncName",
N->getTargetFuncName());
2259 AsmWriterContext &WriterCtx) {
2260 Out <<
"!DILexicalBlock(";
2261 MDFieldPrinter
Printer(Out, WriterCtx);
2262 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2263 Printer.printMetadata(
"file",
N->getRawFile());
2264 Printer.printInt(
"line",
N->getLine());
2265 Printer.printInt(
"column",
N->getColumn());
2271 AsmWriterContext &WriterCtx) {
2272 Out <<
"!DILexicalBlockFile(";
2273 MDFieldPrinter
Printer(Out, WriterCtx);
2274 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2275 Printer.printMetadata(
"file",
N->getRawFile());
2276 Printer.printInt(
"discriminator",
N->getDiscriminator(),
2282 AsmWriterContext &WriterCtx) {
2283 Out <<
"!DINamespace(";
2284 MDFieldPrinter
Printer(Out, WriterCtx);
2285 Printer.printString(
"name",
N->getName());
2286 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2287 Printer.printBool(
"exportSymbols",
N->getExportSymbols(),
false);
2292 AsmWriterContext &WriterCtx) {
2293 Out <<
"!DICommonBlock(";
2294 MDFieldPrinter
Printer(Out, WriterCtx);
2295 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2296 Printer.printMetadata(
"declaration",
N->getRawDecl(),
false);
2297 Printer.printString(
"name",
N->getName());
2298 Printer.printMetadata(
"file",
N->getRawFile());
2299 Printer.printInt(
"line",
N->getLineNo());
2304 AsmWriterContext &WriterCtx) {
2306 MDFieldPrinter
Printer(Out, WriterCtx);
2308 Printer.printInt(
"line",
N->getLine());
2309 Printer.printString(
"name",
N->getName());
2310 Printer.printString(
"value",
N->getValue());
2315 AsmWriterContext &WriterCtx) {
2316 Out <<
"!DIMacroFile(";
2317 MDFieldPrinter
Printer(Out, WriterCtx);
2318 Printer.printInt(
"line",
N->getLine());
2319 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2320 Printer.printMetadata(
"nodes",
N->getRawElements());
2325 AsmWriterContext &WriterCtx) {
2326 Out <<
"!DIModule(";
2327 MDFieldPrinter
Printer(Out, WriterCtx);
2328 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2329 Printer.printString(
"name",
N->getName());
2330 Printer.printString(
"configMacros",
N->getConfigurationMacros());
2331 Printer.printString(
"includePath",
N->getIncludePath());
2332 Printer.printString(
"apinotes",
N->getAPINotesFile());
2333 Printer.printMetadata(
"file",
N->getRawFile());
2334 Printer.printInt(
"line",
N->getLineNo());
2335 Printer.printBool(
"isDecl",
N->getIsDecl(),
false);
2341 AsmWriterContext &WriterCtx) {
2342 Out <<
"!DITemplateTypeParameter(";
2343 MDFieldPrinter
Printer(Out, WriterCtx);
2344 Printer.printString(
"name",
N->getName());
2345 Printer.printMetadata(
"type",
N->getRawType(),
false);
2346 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2352 AsmWriterContext &WriterCtx) {
2353 Out <<
"!DITemplateValueParameter(";
2354 MDFieldPrinter
Printer(Out, WriterCtx);
2355 if (
N->getTag() != dwarf::DW_TAG_template_value_parameter)
2357 Printer.printString(
"name",
N->getName());
2358 Printer.printMetadata(
"type",
N->getRawType());
2359 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2360 Printer.printMetadata(
"value",
N->getValue(),
false);
2365 AsmWriterContext &WriterCtx) {
2366 Out <<
"!DIGlobalVariable(";
2367 MDFieldPrinter
Printer(Out, WriterCtx);
2368 Printer.printString(
"name",
N->getName());
2369 Printer.printString(
"linkageName",
N->getLinkageName());
2370 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2371 Printer.printMetadata(
"file",
N->getRawFile());
2372 Printer.printInt(
"line",
N->getLine());
2373 Printer.printMetadata(
"type",
N->getRawType());
2374 Printer.printBool(
"isLocal",
N->isLocalToUnit());
2375 Printer.printBool(
"isDefinition",
N->isDefinition());
2376 Printer.printMetadata(
"declaration",
N->getRawStaticDataMemberDeclaration());
2377 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2378 Printer.printInt(
"align",
N->getAlignInBits());
2379 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2384 AsmWriterContext &WriterCtx) {
2385 Out <<
"!DILocalVariable(";
2386 MDFieldPrinter
Printer(Out, WriterCtx);
2387 Printer.printString(
"name",
N->getName());
2388 Printer.printInt(
"arg",
N->getArg());
2389 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2390 Printer.printMetadata(
"file",
N->getRawFile());
2391 Printer.printInt(
"line",
N->getLine());
2392 Printer.printMetadata(
"type",
N->getRawType());
2393 Printer.printDIFlags(
"flags",
N->getFlags());
2394 Printer.printInt(
"align",
N->getAlignInBits());
2395 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2400 AsmWriterContext &WriterCtx) {
2402 MDFieldPrinter
Printer(Out, WriterCtx);
2403 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2404 Printer.printString(
"name",
N->getName());
2405 Printer.printMetadata(
"file",
N->getRawFile());
2406 Printer.printInt(
"line",
N->getLine());
2411 AsmWriterContext &WriterCtx) {
2412 Out <<
"!DIExpression(";
2417 assert(!OpStr.empty() &&
"Expected valid opcode");
2421 Out << FS <<
Op.getArg(0);
2424 for (
unsigned A = 0, AE =
Op.getNumArgs();
A != AE; ++
A)
2425 Out << FS <<
Op.getArg(
A);
2429 for (
const auto &
I :
N->getElements())
2436 AsmWriterContext &WriterCtx,
2437 bool FromValue =
false) {
2439 "Unexpected DIArgList metadata outside of value argument");
2440 Out <<
"!DIArgList(";
2442 MDFieldPrinter
Printer(Out, WriterCtx);
2452 AsmWriterContext &WriterCtx) {
2453 Out <<
"!DIGlobalVariableExpression(";
2454 MDFieldPrinter
Printer(Out, WriterCtx);
2455 Printer.printMetadata(
"var",
N->getVariable());
2456 Printer.printMetadata(
"expr",
N->getExpression());
2461 AsmWriterContext &WriterCtx) {
2462 Out <<
"!DIObjCProperty(";
2463 MDFieldPrinter
Printer(Out, WriterCtx);
2464 Printer.printString(
"name",
N->getName());
2465 Printer.printMetadata(
"file",
N->getRawFile());
2466 Printer.printInt(
"line",
N->getLine());
2467 Printer.printString(
"setter",
N->getSetterName());
2468 Printer.printString(
"getter",
N->getGetterName());
2469 Printer.printInt(
"attributes",
N->getAttributes());
2470 Printer.printMetadata(
"type",
N->getRawType());
2475 AsmWriterContext &WriterCtx) {
2476 Out <<
"!DIImportedEntity(";
2477 MDFieldPrinter
Printer(Out, WriterCtx);
2479 Printer.printString(
"name",
N->getName());
2480 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2481 Printer.printMetadata(
"entity",
N->getRawEntity());
2482 Printer.printMetadata(
"file",
N->getRawFile());
2483 Printer.printInt(
"line",
N->getLine());
2484 Printer.printMetadata(
"elements",
N->getRawElements());
2489 AsmWriterContext &Ctx) {
2490 if (
Node->isDistinct())
2492 else if (
Node->isTemporary())
2493 Out <<
"<temporary!> ";
2495 switch (
Node->getMetadataID()) {
2498#define HANDLE_MDNODE_LEAF(CLASS) \
2499 case Metadata::CLASS##Kind: \
2500 write##CLASS(Out, cast<CLASS>(Node), Ctx); \
2502#include "llvm/IR/Metadata.def"
2509 AsmWriterContext &WriterCtx) {
2515 const Constant *CV = dyn_cast<Constant>(V);
2516 if (CV && !isa<GlobalValue>(CV)) {
2517 assert(WriterCtx.TypePrinter &&
"Constants require TypePrinting!");
2522 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2524 if (IA->hasSideEffects())
2525 Out <<
"sideeffect ";
2526 if (IA->isAlignStack())
2527 Out <<
"alignstack ";
2530 Out <<
"inteldialect ";
2534 printEscapedString(IA->getAsmString(), Out);
2536 printEscapedString(IA->getConstraintString(), Out);
2541 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2549 auto *
Machine = WriterCtx.Machine;
2552 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2553 Slot =
Machine->getGlobalSlot(GV);
2556 Slot =
Machine->getLocalSlot(V);
2563 Slot =
Machine->getLocalSlot(V);
2569 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2570 Slot =
Machine->getGlobalSlot(GV);
2573 Slot =
Machine->getLocalSlot(V);
2582 Out << Prefix << Slot;
2588 AsmWriterContext &WriterCtx,
2592 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2596 if (
const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) {
2601 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2602 std::unique_ptr<SlotTracker> MachineStorage;
2604 if (!WriterCtx.Machine) {
2605 MachineStorage = std::make_unique<SlotTracker>(WriterCtx.Context);
2606 WriterCtx.Machine = MachineStorage.get();
2608 int Slot = WriterCtx.Machine->getMetadataSlot(
N);
2610 if (
const DILocation *Loc = dyn_cast<DILocation>(
N)) {
2616 Out <<
"<" <<
N <<
">";
2622 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2624 printEscapedString(MDS->getString(), Out);
2629 auto *V = cast<ValueAsMetadata>(MD);
2630 assert(WriterCtx.TypePrinter &&
"TypePrinter required for metadata values");
2631 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2632 "Unexpected function-local metadata outside of value argument");
2634 WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);
2641class AssemblyWriter {
2643 const Module *TheModule =
nullptr;
2645 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2647 TypePrinting TypePrinter;
2651 bool ShouldPreserveUseListOrder;
2662 bool ShouldPreserveUseListOrder =
false);
2667 AsmWriterContext getContext() {
2668 return AsmWriterContext(&TypePrinter, &
Machine, TheModule);
2671 void printMDNodeBody(
const MDNode *MD);
2674 void printModule(
const Module *M);
2676 void writeOperand(
const Value *
Op,
bool PrintType);
2678 void writeOperandBundles(
const CallBase *Call);
2684 void writeAtomicCmpXchg(
const LLVMContext &Context,
2689 void writeAllMDNodes();
2690 void writeMDNode(
unsigned Slot,
const MDNode *
Node);
2691 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
2692 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
2693 void writeAllAttributeGroups();
2695 void printTypeIdentities();
2699 void printComdat(
const Comdat *
C);
2705 void printDPMarker(
const DPMarker &DPI);
2706 void printDPValue(
const DPValue &DPI);
2707 void printDPLabel(
const DPLabel &DPL);
2708 void printDbgRecord(
const DbgRecord &DPI);
2709 void printDbgRecordLine(
const DbgRecord &DPI);
2711 void printUseListOrder(
const Value *V,
const std::vector<unsigned> &Shuffle);
2714 void printModuleSummaryIndex();
2715 void printSummaryInfo(
unsigned Slot,
const ValueInfo &VI);
2723 void printArgs(
const std::vector<uint64_t> &Args);
2728 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> &VCallList,
2731 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> &VCallList,
2736 void printMetadataAttachments(
2742 void printInfoComment(
const Value &V);
2753 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2754 : Out(
o), TheModule(
M),
Machine(Mac), TypePrinter(
M), AnnotationWriter(AAW),
2755 IsForDebug(IsForDebug),
2756 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2759 for (
const GlobalObject &GO : TheModule->global_objects())
2766 : Out(
o), TheIndex(
Index),
Machine(Mac), TypePrinter(nullptr),
2767 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2769void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2771 Out <<
"<null operand!>";
2775 TypePrinter.print(Operand->
getType(), Out);
2778 auto WriterCtx = getContext();
2782void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2792 Out <<
" syncscope(\"";
2793 printEscapedString(SSNs[SSID], Out);
2800void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2803 if (Ordering == AtomicOrdering::NotAtomic)
2806 writeSyncScope(Context, SSID);
2810void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2814 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
2815 FailureOrdering != AtomicOrdering::NotAtomic);
2817 writeSyncScope(Context, SSID);
2822void AssemblyWriter::writeParamOperand(
const Value *Operand,
2825 Out <<
"<null operand!>";
2830 TypePrinter.print(Operand->
getType(), Out);
2832 if (
Attrs.hasAttributes()) {
2834 writeAttributeSet(Attrs);
2838 auto WriterCtx = getContext();
2842void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
2843 if (!
Call->hasOperandBundles())
2848 bool FirstBundle =
true;
2849 for (
unsigned i = 0, e =
Call->getNumOperandBundles(); i != e; ++i) {
2854 FirstBundle =
false;
2862 bool FirstInput =
true;
2863 auto WriterCtx = getContext();
2864 for (
const auto &Input : BU.
Inputs) {
2869 if (Input ==
nullptr)
2870 Out <<
"<null operand bundle!>";
2872 TypePrinter.print(Input->getType(), Out);
2884void AssemblyWriter::printModule(
const Module *M) {
2887 if (ShouldPreserveUseListOrder)
2890 if (!
M->getModuleIdentifier().empty() &&
2893 M->getModuleIdentifier().find(
'\n') == std::string::npos)
2894 Out <<
"; ModuleID = '" <<
M->getModuleIdentifier() <<
"'\n";
2896 if (!
M->getSourceFileName().empty()) {
2897 Out <<
"source_filename = \"";
2898 printEscapedString(
M->getSourceFileName(), Out);
2902 const std::string &
DL =
M->getDataLayoutStr();
2904 Out <<
"target datalayout = \"" <<
DL <<
"\"\n";
2905 if (!
M->getTargetTriple().empty())
2906 Out <<
"target triple = \"" <<
M->getTargetTriple() <<
"\"\n";
2908 if (!
M->getModuleInlineAsm().empty()) {
2915 std::tie(Front, Asm) =
Asm.split(
'\n');
2919 Out <<
"module asm \"";
2920 printEscapedString(Front, Out);
2922 }
while (!
Asm.empty());
2925 printTypeIdentities();
2928 if (!Comdats.empty())
2930 for (
const Comdat *
C : Comdats) {
2932 if (
C != Comdats.back())
2937 if (!
M->global_empty()) Out <<
'\n';
2939 printGlobal(&GV); Out <<
'\n';
2943 if (!
M->alias_empty()) Out <<
"\n";
2948 if (!
M->ifunc_empty()) Out <<
"\n";
2959 printUseLists(
nullptr);
2964 writeAllAttributeGroups();
2968 if (!
M->named_metadata_empty()) Out <<
'\n';
2971 printNamedMDNode(&
Node);
2980void AssemblyWriter::printModuleSummaryIndex() {
2982 int NumSlots =
Machine.initializeIndexIfNeeded();
2988 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
2989 std::string RegularLTOModuleName =
2991 moduleVec.resize(TheIndex->modulePaths().size());
2992 for (
auto &[ModPath, ModHash] : TheIndex->modulePaths())
2993 moduleVec[
Machine.getModulePathSlot(ModPath)] = std::make_pair(
2996 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
2999 for (
auto &ModPair : moduleVec) {
3000 Out <<
"^" << i++ <<
" = module: (";
3002 printEscapedString(ModPair.first, Out);
3003 Out <<
"\", hash: (";
3005 for (
auto Hash : ModPair.second)
3012 for (
auto &GlobalList : *TheIndex) {
3013 auto GUID = GlobalList.first;
3014 for (
auto &Summary : GlobalList.second.SummaryList)
3015 SummaryToGUIDMap[
Summary.get()] = GUID;
3019 for (
auto &GlobalList : *TheIndex) {
3020 auto GUID = GlobalList.first;
3021 auto VI = TheIndex->getValueInfo(GlobalList);
3022 printSummaryInfo(
Machine.getGUIDSlot(GUID), VI);
3026 for (
const auto &TID : TheIndex->typeIds()) {
3027 Out <<
"^" <<
Machine.getTypeIdSlot(TID.second.first)
3028 <<
" = typeid: (name: \"" << TID.second.first <<
"\"";
3029 printTypeIdSummary(TID.second.second);
3030 Out <<
") ; guid = " << TID.first <<
"\n";
3034 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
3036 Out <<
"^" <<
Machine.getTypeIdCompatibleVtableSlot(TId.first)
3037 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
3038 printTypeIdCompatibleVtableSummary(TId.second);
3039 Out <<
") ; guid = " << GUID <<
"\n";
3043 if (TheIndex->getFlags()) {
3044 Out <<
"^" << NumSlots <<
" = flags: " << TheIndex->getFlags() <<
"\n";
3048 Out <<
"^" << NumSlots <<
" = blockcount: " << TheIndex->getBlockCount()
3058 return "singleImpl";
3060 return "branchFunnel";
3071 return "uniformRetVal";
3073 return "uniqueRetVal";
3075 return "virtualConstProp";
3105 Out <<
", alignLog2: " << TTRes.
AlignLog2;
3107 Out <<
", sizeM1: " << TTRes.
SizeM1;
3117void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
3118 Out <<
", summary: (";
3119 printTypeTestResolution(TIS.
TTRes);
3120 if (!TIS.
WPDRes.empty()) {
3121 Out <<
", wpdResolutions: (";
3123 for (
auto &WPDRes : TIS.
WPDRes) {
3125 Out <<
"(offset: " << WPDRes.first <<
", ";
3126 printWPDRes(WPDRes.second);
3134void AssemblyWriter::printTypeIdCompatibleVtableSummary(
3136 Out <<
", summary: (";
3138 for (
auto &
P : TI) {
3140 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
3141 Out <<
"^" <<
Machine.getGUIDSlot(
P.VTableVI.getGUID());
3147void AssemblyWriter::printArgs(
const std::vector<uint64_t> &Args) {
3150 for (
auto arg : Args) {
3158 Out <<
"wpdRes: (kind: ";
3165 Out <<
", resByArg: (";
3167 for (
auto &ResByArg : WPDRes.
ResByArg) {
3169 printArgs(ResByArg.first);
3170 Out <<
", byArg: (kind: ";
3172 if (ResByArg.second.TheKind ==
3174 ResByArg.second.TheKind ==
3176 Out <<
", info: " << ResByArg.second.Info;
3180 if (ResByArg.second.Byte || ResByArg.second.Bit)
3181 Out <<
", byte: " << ResByArg.second.Byte
3182 <<
", bit: " << ResByArg.second.Bit;
3203void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
3204 Out <<
", aliasee: ";
3215 auto VTableFuncs =
GS->vTableFuncs();
3216 Out <<
", varFlags: (readonly: " <<
GS->VarFlags.MaybeReadOnly <<
", "
3217 <<
"writeonly: " <<
GS->VarFlags.MaybeWriteOnly <<
", "
3218 <<
"constant: " <<
GS->VarFlags.Constant;
3219 if (!VTableFuncs.empty())
3221 <<
"vcall_visibility: " <<
GS->VarFlags.VCallVisibility;
3224 if (!VTableFuncs.empty()) {
3225 Out <<
", vTableFuncs: (";
3227 for (
auto &
P : VTableFuncs) {
3229 Out <<
"(virtFunc: ^" <<
Machine.getGUIDSlot(
P.FuncVI.getGUID())
3230 <<
", offset: " <<
P.VTableOffset;
3248 return "linkonce_odr";
3258 return "extern_weak";
3260 return "available_externally";
3287 Out <<
", insts: " <<
FS->instCount();
3288 if (
FS->fflags().anyFlagSet())
3289 Out <<
", " <<
FS->fflags();
3291 if (!
FS->calls().empty()) {
3292 Out <<
", calls: (";
3294 for (
auto &Call :
FS->calls()) {
3296 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.first.getGUID());
3297 if (
Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)
3299 else if (
Call.second.RelBlockFreq)
3300 Out <<
", relbf: " <<
Call.second.RelBlockFreq;
3303 if (
Call.second.HasTailCall)
3310 if (
const auto *TIdInfo =
FS->getTypeIdInfo())
3311 printTypeIdInfo(*TIdInfo);
3315 auto AllocTypeName = [](uint8_t
Type) ->
const char * {
3317 case (uint8_t)AllocationType::None:
3319 case (uint8_t)AllocationType::NotCold:
3321 case (uint8_t)AllocationType::Cold:
3323 case (uint8_t)AllocationType::Hot:
3329 if (!
FS->allocs().empty()) {
3330 Out <<
", allocs: (";
3332 for (
auto &AI :
FS->allocs()) {
3334 Out <<
"(versions: (";
3336 for (
auto V : AI.Versions) {
3338 Out << AllocTypeName(V);
3340 Out <<
"), memProf: (";
3341 FieldSeparator MIBFS;
3342 for (
auto &MIB : AI.MIBs) {
3344 Out <<
"(type: " << AllocTypeName((uint8_t)MIB.AllocType);
3345 Out <<
", stackIds: (";
3346 FieldSeparator SIDFS;
3347 for (
auto Id : MIB.StackIdIndices) {
3349 Out << TheIndex->getStackIdAtIndex(Id);
3358 if (!
FS->callsites().empty()) {
3359 Out <<
", callsites: (";
3360 FieldSeparator SNFS;
3361 for (
auto &CI :
FS->callsites()) {
3364 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(CI.Callee.getGUID());
3366 Out <<
"(callee: null";
3367 Out <<
", clones: (";
3369 for (
auto V : CI.Clones) {
3373 Out <<
"), stackIds: (";
3374 FieldSeparator SIDFS;
3375 for (
auto Id : CI.StackIdIndices) {
3377 Out << TheIndex->getStackIdAtIndex(Id);
3385 Out <<
"[" <<
Range.getSignedMin() <<
", " <<
Range.getSignedMax() <<
"]";
3388 if (!
FS->paramAccesses().empty()) {
3389 Out <<
", params: (";
3391 for (
auto &PS :
FS->paramAccesses()) {
3393 Out <<
"(param: " << PS.ParamNo;
3394 Out <<
", offset: ";
3396 if (!PS.Calls.empty()) {
3397 Out <<
", calls: (";
3399 for (
auto &Call : PS.Calls) {
3401 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.Callee.getGUID());
3402 Out <<
", param: " <<
Call.ParamNo;
3403 Out <<
", offset: ";
3404 PrintRange(
Call.Offsets);
3415void AssemblyWriter::printTypeIdInfo(
3417 Out <<
", typeIdInfo: (";
3418 FieldSeparator TIDFS;
3421 Out <<
"typeTests: (";
3424 auto TidIter = TheIndex->typeIds().equal_range(GUID);
3425 if (TidIter.first == TidIter.second) {
3431 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3433 auto Slot =
Machine.getTypeIdSlot(It->second.first);
3451 "typeTestAssumeConstVCalls");
3456 "typeCheckedLoadConstVCalls");
3462 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
3463 if (TidIter.first == TidIter.second) {
3464 Out <<
"vFuncId: (";
3465 Out <<
"guid: " << VFId.
GUID;
3466 Out <<
", offset: " << VFId.
Offset;
3472 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3474 Out <<
"vFuncId: (";
3475 auto Slot =
Machine.getTypeIdSlot(It->second.first);
3478 Out <<
", offset: " << VFId.
Offset;
3483void AssemblyWriter::printNonConstVCalls(
3484 const std::vector<FunctionSummary::VFuncId> &VCallList,
const char *
Tag) {
3485 Out <<
Tag <<
": (";
3487 for (
auto &VFuncId : VCallList) {
3489 printVFuncId(VFuncId);
3494void AssemblyWriter::printConstVCalls(
3495 const std::vector<FunctionSummary::ConstVCall> &VCallList,
3497 Out <<
Tag <<
": (";
3499 for (
auto &ConstVCall : VCallList) {
3502 printVFuncId(ConstVCall.VFunc);
3503 if (!ConstVCall.Args.empty()) {
3505 printArgs(ConstVCall.Args);
3516 Out <<
"(module: ^" <<
Machine.getModulePathSlot(
Summary.modulePath())
3519 Out <<
", visibility: "
3522 Out <<
", live: " << GVFlags.
Live;
3523 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3528 printAliasSummary(cast<AliasSummary>(&Summary));
3530 printFunctionSummary(cast<FunctionSummary>(&Summary));
3532 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3534 auto RefList =
Summary.refs();
3535 if (!RefList.empty()) {
3538 for (
auto &
Ref : RefList) {
3540 if (
Ref.isReadOnly())
3542 else if (
Ref.isWriteOnly())
3543 Out <<
"writeonly ";
3544 Out <<
"^" <<
Machine.getGUIDSlot(
Ref.getGUID());
3552void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &VI) {
3553 Out <<
"^" <<
Slot <<
" = gv: (";
3554 if (!
VI.name().empty())
3555 Out <<
"name: \"" <<
VI.name() <<
"\"";
3557 Out <<
"guid: " <<
VI.getGUID();
3558 if (!
VI.getSummaryList().empty()) {
3559 Out <<
", summaries: (";
3561 for (
auto &Summary :
VI.getSummaryList()) {
3563 printSummary(*Summary);
3568 if (!
VI.name().empty())
3569 Out <<
" ; guid = " <<
VI.getGUID();
3576 Out <<
"<empty name> ";
3578 unsigned char FirstC =
static_cast<unsigned char>(
Name[0]);
3579 if (isalpha(FirstC) || FirstC ==
'-' || FirstC ==
'$' || FirstC ==
'.' ||
3583 Out <<
'\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);
3584 for (
unsigned i = 1, e =
Name.size(); i != e; ++i) {
3585 unsigned char C =
Name[i];
3586 if (isalnum(
C) ||
C ==
'-' ||
C ==
'$' ||
C ==
'.' ||
C ==
'_')
3589 Out <<
'\\' << hexdigit(
C >> 4) << hexdigit(
C & 0x0F);
3594void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3605 if (
auto *Expr = dyn_cast<DIExpression>(
Op)) {
3631 Out <<
"dso_local ";
3646 case GlobalVariable::NotThreadLocal:
3648 case GlobalVariable::GeneralDynamicTLSModel:
3649 Out <<
"thread_local ";
3651 case GlobalVariable::LocalDynamicTLSModel:
3652 Out <<
"thread_local(localdynamic) ";
3654 case GlobalVariable::InitialExecTLSModel:
3655 Out <<
"thread_local(initialexec) ";
3657 case GlobalVariable::LocalExecTLSModel:
3658 Out <<
"thread_local(localexec) ";
3665 case GlobalVariable::UnnamedAddr::None:
3667 case GlobalVariable::UnnamedAddr::Local:
3668 return "local_unnamed_addr";
3669 case GlobalVariable::UnnamedAddr::Global:
3670 return "unnamed_addr";
3681 if (isa<GlobalVariable>(GO))
3695 Out <<
"; Materializable\n";
3716 Out << (GV->
isConstant() ?
"constant " :
"global ");
3725 Out <<
", section \"";
3730 Out <<
", partition \"";
3735 Out <<
", code_model \"";
3760 Out <<
", no_sanitize_address";
3762 Out <<
", no_sanitize_hwaddress";
3764 Out <<
", sanitize_memtag";
3766 Out <<
", sanitize_address_dyninit";
3771 Out <<
", align " <<
A->value();
3775 printMetadataAttachments(MDs,
", ");
3778 if (
Attrs.hasAttributes())
3779 Out <<
" #" <<
Machine.getAttributeGroupSlot(Attrs);
3781 printInfoComment(*GV);
3784void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
3786 Out <<
"; Materializable\n";
3807 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
3809 TypePrinter.print(GA->
getType(), Out);
3810 Out <<
" <<NULL ALIASEE>>";
3814 Out <<
", partition \"";
3819 printInfoComment(*GA);
3823void AssemblyWriter::printIFunc(
const GlobalIFunc *GI) {
3825 Out <<
"; Materializable\n";
3843 TypePrinter.print(GI->
getType(), Out);
3844 Out <<
" <<NULL RESOLVER>>";
3848 Out <<
", partition \"";
3853 printInfoComment(*GI);
3857void AssemblyWriter::printComdat(
const Comdat *
C) {
3861void AssemblyWriter::printTypeIdentities() {
3862 if (TypePrinter.empty())
3868 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3869 for (
unsigned I = 0,
E = NumberedTypes.size();
I !=
E; ++
I) {
3870 Out <<
'%' <<
I <<
" = type ";
3874 TypePrinter.printStructBody(NumberedTypes[
I], Out);
3878 auto &NamedTypes = TypePrinter.getNamedTypes();
3885 TypePrinter.printStructBody(NamedType, Out);
3891void AssemblyWriter::printFunction(
const Function *
F) {
3892 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(
F, Out);
3894 if (
F->isMaterializable())
3895 Out <<
"; Materializable\n";
3898 if (
Attrs.hasFnAttrs()) {
3900 std::string AttrStr;
3903 if (!Attr.isStringAttribute()) {
3904 if (!AttrStr.empty()) AttrStr +=
' ';
3905 AttrStr += Attr.getAsString();
3909 if (!AttrStr.empty())
3910 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
3915 if (
F->isDeclaration()) {
3918 F->getAllMetadata(MDs);
3919 printMetadataAttachments(MDs,
" ");
3936 if (
Attrs.hasRetAttrs())
3938 TypePrinter.print(
F->getReturnType(), Out);
3939 AsmWriterContext WriterCtx(&TypePrinter, &
Machine,
F->getParent());
3945 if (
F->isDeclaration() && !IsForDebug) {
3947 for (
unsigned I = 0,
E = FT->getNumParams();
I !=
E; ++
I) {
3952 TypePrinter.print(FT->getParamType(
I), Out);
3957 writeAttributeSet(ArgAttrs);
3964 if (Arg.getArgNo() != 0)
3966 printArgument(&Arg,
Attrs.getParamAttrs(Arg.getArgNo()));
3971 if (FT->isVarArg()) {
3972 if (FT->getNumParams()) Out <<
", ";
3983 if (
F->getAddressSpace() != 0 || !
Mod ||
3985 Out <<
" addrspace(" <<
F->getAddressSpace() <<
")";
3986 if (
Attrs.hasFnAttrs())
3987 Out <<
" #" <<
Machine.getAttributeGroupSlot(
Attrs.getFnAttrs());
3988 if (
F->hasSection()) {
3989 Out <<
" section \"";
3990 printEscapedString(
F->getSection(), Out);
3993 if (
F->hasPartition()) {
3994 Out <<
" partition \"";
3995 printEscapedString(
F->getPartition(), Out);
4000 Out <<
" align " <<
A->value();
4002 Out <<
" gc \"" <<
F->getGC() <<
'"';
4003 if (
F->hasPrefixData()) {
4005 writeOperand(
F->getPrefixData(),
true);
4007 if (
F->hasPrologueData()) {
4008 Out <<
" prologue ";
4009 writeOperand(
F->getPrologueData(),
true);
4011 if (
F->hasPersonalityFn()) {
4012 Out <<
" personality ";
4013 writeOperand(
F->getPersonalityFn(),
true);
4016 if (
F->isDeclaration()) {
4020 F->getAllMetadata(MDs);
4021 printMetadataAttachments(MDs,
" ");
4026 printBasicBlock(&BB);
4041 TypePrinter.print(Arg->
getType(), Out);
4044 if (
Attrs.hasAttributes()) {
4046 writeAttributeSet(Attrs);
4055 assert(Slot != -1 &&
"expect argument in function here");
4056 Out <<
" %" <<
Slot;
4061void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
4067 }
else if (!IsEntryBlock) {
4076 if (!IsEntryBlock) {
4078 Out.PadToColumn(50);
4083 Out <<
" No predecessors!";
4086 writeOperand(*PI,
false);
4087 for (++PI; PI != PE; ++PI) {
4089 writeOperand(*PI,
false);
4096 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
4100 for (
const DbgRecord &DR :
I.getDbgRecordRange())
4101 printDbgRecordLine(DR);
4102 printInstructionLine(
I);
4105 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
4109void AssemblyWriter::printInstructionLine(
const Instruction &
I) {
4110 printInstruction(
I);
4116void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
4126void AssemblyWriter::printInfoComment(
const Value &V) {
4127 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
4128 printGCRelocateComment(*Relocate);
4130 if (AnnotationWriter) {
4131 AnnotationWriter->printInfoComment(V, Out);
4138 if (Operand ==
nullptr) {
4139 Out <<
" <cannot get addrspace!>";
4143 bool PrintAddrSpace = CallAddrSpace != 0;
4144 if (!PrintAddrSpace) {
4150 PrintAddrSpace =
true;
4153 Out <<
" addrspace(" << CallAddrSpace <<
")";
4157void AssemblyWriter::printInstruction(
const Instruction &
I) {
4158 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&
I, Out);
4167 }
else if (!
I.getType()->isVoidTy()) {
4169 int SlotNum =
Machine.getLocalSlot(&
I);
4171 Out <<
"<badref> = ";
4173 Out <<
'%' << SlotNum <<
" = ";
4176 if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4177 if (CI->isMustTailCall())
4179 else if (CI->isTailCall())
4181 else if (CI->isNoTailCall())
4186 Out <<
I.getOpcodeName();
4189 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isAtomic()) ||
4190 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isAtomic()))
4193 if (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isWeak())
4197 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isVolatile()) ||
4198 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isVolatile()) ||
4199 (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isVolatile()) ||
4200 (isa<AtomicRMWInst>(
I) && cast<AtomicRMWInst>(
I).isVolatile()))
4207 if (
const CmpInst *CI = dyn_cast<CmpInst>(&
I))
4208 Out <<
' ' << CI->getPredicate();
4215 const Value *Operand =
I.getNumOperands() ?
I.getOperand(0) :
nullptr;
4218 if (isa<BranchInst>(
I) && cast<BranchInst>(
I).isConditional()) {
4221 writeOperand(BI.getCondition(),
true);
4223 writeOperand(BI.getSuccessor(0),
true);
4225 writeOperand(BI.getSuccessor(1),
true);
4227 }
else if (isa<SwitchInst>(
I)) {
4231 writeOperand(
SI.getCondition(),
true);
4233 writeOperand(
SI.getDefaultDest(),
true);
4235 for (
auto Case :
SI.cases()) {
4237 writeOperand(Case.getCaseValue(),
true);
4239 writeOperand(Case.getCaseSuccessor(),
true);
4242 }
else if (isa<IndirectBrInst>(
I)) {
4245 writeOperand(Operand,
true);
4248 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i) {
4251 writeOperand(
I.getOperand(i),
true);
4254 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&
I)) {
4256 TypePrinter.print(
I.getType(), Out);
4259 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
4260 if (
op) Out <<
", ";
4262 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
4263 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
4267 writeOperand(
I.getOperand(0),
true);
4268 for (
unsigned i : EVI->indices())
4272 writeOperand(
I.getOperand(0),
true); Out <<
", ";
4273 writeOperand(
I.getOperand(1),
true);
4274 for (
unsigned i : IVI->indices())
4276 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&
I)) {
4278 TypePrinter.print(
I.getType(), Out);
4279 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
4282 if (LPI->isCleanup())
4285 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
4286 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
4287 if (LPI->isCatch(i))
4292 writeOperand(LPI->getClause(i),
true);
4294 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&
I)) {
4296 writeOperand(CatchSwitch->getParentPad(),
false);
4299 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
4302 writeOperand(PadBB,
true);
4306 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
4307 writeOperand(UnwindDest,
true);
4310 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&
I)) {
4312 writeOperand(FPI->getParentPad(),
false);
4314 for (
unsigned Op = 0, NumOps = FPI->arg_size();
Op < NumOps; ++
Op) {
4317 writeOperand(FPI->getArgOperand(
Op),
true);
4320 }
else if (isa<ReturnInst>(
I) && !Operand) {
4322 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&
I)) {
4324 writeOperand(CRI->getOperand(0),
false);
4327 writeOperand(CRI->getOperand(1),
true);
4328 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&
I)) {
4330 writeOperand(CRI->getOperand(0),
false);
4333 if (CRI->hasUnwindDest())
4334 writeOperand(CRI->getOperand(1),
true);
4337 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4344 Operand = CI->getCalledOperand();
4359 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4361 writeOperand(Operand,
false);
4363 for (
unsigned op = 0, Eop = CI->arg_size();
op < Eop; ++
op) {
4371 if (CI->isMustTailCall() && CI->getParent() &&
4372 CI->getParent()->getParent() &&
4373 CI->getParent()->getParent()->isVarArg()) {
4374 if (CI->arg_size() > 0)
4383 writeOperandBundles(CI);
4384 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&
I)) {
4385 Operand = II->getCalledOperand();
4407 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4409 writeOperand(Operand,
false);
4411 for (
unsigned op = 0, Eop = II->arg_size();
op < Eop; ++
op) {
4421 writeOperandBundles(II);
4424 writeOperand(II->getNormalDest(),
true);
4426 writeOperand(II->getUnwindDest(),
true);
4427 }
else if (
const CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
4428 Operand = CBI->getCalledOperand();
4447 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4449 writeOperand(Operand,
false);
4451 for (
unsigned op = 0, Eop = CBI->arg_size();
op < Eop; ++
op) {
4461 writeOperandBundles(CBI);
4464 writeOperand(CBI->getDefaultDest(),
true);
4466 for (
unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i) {
4469 writeOperand(CBI->getIndirectDest(i),
true);
4472 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
4474 if (AI->isUsedWithInAlloca())
4476 if (AI->isSwiftError())
4477 Out <<
"swifterror ";
4478 TypePrinter.print(AI->getAllocatedType(), Out);
4484 if (!AI->getArraySize() || AI->isArrayAllocation() ||
4485 !AI->getArraySize()->getType()->isIntegerTy(32)) {
4487 writeOperand(AI->getArraySize(),
true);
4490 Out <<
", align " <<
A->value();
4493 unsigned AddrSpace = AI->getAddressSpace();
4494 if (AddrSpace != 0) {
4495 Out <<
", addrspace(" << AddrSpace <<
')';
4497 }
else if (isa<CastInst>(
I)) {
4500 writeOperand(Operand,
true);
4503 TypePrinter.print(
I.getType(), Out);
4504 }
else if (isa<VAArgInst>(
I)) {
4507 writeOperand(Operand,
true);
4510 TypePrinter.print(
I.getType(), Out);
4511 }
else if (Operand) {
4512 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&
I)) {
4514 TypePrinter.print(
GEP->getSourceElementType(), Out);
4516 }
else if (
const auto *LI = dyn_cast<LoadInst>(&
I)) {
4518 TypePrinter.print(LI->getType(), Out);
4525 bool PrintAllTypes =
false;
4530 if (isa<SelectInst>(
I) || isa<StoreInst>(
I) || isa<ShuffleVectorInst>(
I) ||
4531 isa<ReturnInst>(
I) || isa<AtomicCmpXchgInst>(
I) ||
4532 isa<AtomicRMWInst>(
I)) {
4533 PrintAllTypes =
true;
4535 for (
unsigned i = 1,
E =
I.getNumOperands(); i !=
E; ++i) {
4536 Operand =
I.getOperand(i);
4539 if (Operand && Operand->
getType() != TheType) {
4540 PrintAllTypes =
true;
4546 if (!PrintAllTypes) {
4548 TypePrinter.print(TheType, Out);
4552 for (
unsigned i = 0,
E =
I.getNumOperands(); i !=
E; ++i) {
4554 writeOperand(
I.getOperand(i), PrintAllTypes);
4559 if (
const LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
4561 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4563 Out <<
", align " <<
A->value();
4564 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(&
I)) {
4566 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4568 Out <<
", align " <<
A->value();
4570 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4571 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4572 Out <<
", align " << CXI->getAlign().value();
4573 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&
I)) {
4574 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4575 RMWI->getSyncScopeID());
4576 Out <<
", align " << RMWI->getAlign().value();
4577 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&
I)) {
4578 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
4585 I.getAllMetadata(InstMD);
4586 printMetadataAttachments(InstMD,
", ");
4589 printInfoComment(
I);
4592void AssemblyWriter::printDPMarker(
const DPMarker &Marker) {
4596 printDbgRecord(DPR);
4600 Out <<
" DPMarker -> { ";
4606void AssemblyWriter::printDbgRecord(
const DbgRecord &DR) {
4607 if (
auto *DPV = dyn_cast<DPValue>(&DR))
4609 else if (
auto *DPL = dyn_cast<DPLabel>(&DR))
4615void AssemblyWriter::printDPValue(
const DPValue &DPV) {
4616 auto WriterCtx = getContext();
4619 case DPValue::LocationType::Value:
4622 case DPValue::LocationType::Declare:
4625 case DPValue::LocationType::Assign:
4629 llvm_unreachable(
"Tried to print a DPValue with an invalid LocationType!");
4652void AssemblyWriter::printDbgRecordLine(
const DbgRecord &DR) {
4659void AssemblyWriter::printDPLabel(
const DPLabel &Label) {
4660 auto WriterCtx = getContext();
4661 Out <<
"#dbg_label(";
4668void AssemblyWriter::printMetadataAttachments(
4674 if (MDNames.empty())
4675 MDs[0].second->getContext().getMDKindNames(MDNames);
4677 auto WriterCtx = getContext();
4678 for (
const auto &
I : MDs) {
4679 unsigned Kind =
I.first;
4681 if (Kind < MDNames.size()) {
4685 Out <<
"!<unknown kind #" <<
Kind <<
">";
4691void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *
Node) {
4692 Out <<
'!' <<
Slot <<
" = ";
4693 printMDNodeBody(
Node);
4697void AssemblyWriter::writeAllMDNodes() {
4701 Nodes[
I.second] = cast<MDNode>(
I.first);
4703 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
4704 writeMDNode(i, Nodes[i]);
4708void AssemblyWriter::printMDNodeBody(
const MDNode *
Node) {
4709 auto WriterCtx = getContext();
4713void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
4722 TypePrinter.print(Ty, Out);
4727void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
4729 bool FirstAttr =
true;
4730 for (
const auto &Attr : AttrSet) {
4733 writeAttribute(Attr, InAttrGroup);
4738void AssemblyWriter::writeAllAttributeGroups() {
4739 std::vector<std::pair<AttributeSet, unsigned>> asVec;
4740 asVec.resize(
Machine.as_size());
4743 asVec[
I.second] =
I;
4745 for (
const auto &
I : asVec)
4746 Out <<
"attributes #" <<
I.second <<
" = { "
4747 <<
I.first.getAsString(
true) <<
" }\n";
4750void AssemblyWriter::printUseListOrder(
const Value *V,
4751 const std::vector<unsigned> &Shuffle) {
4752 bool IsInFunction =
Machine.getFunction();
4756 Out <<
"uselistorder";
4757 if (
const BasicBlock *BB = IsInFunction ?
nullptr : dyn_cast<BasicBlock>(V)) {
4759 writeOperand(BB->getParent(),
false);
4761 writeOperand(BB,
false);
4764 writeOperand(V,
true);
4768 assert(Shuffle.size() >= 2 &&
"Shuffle too small");
4770 for (
unsigned I = 1,
E = Shuffle.size();
I !=
E; ++
I)
4771 Out <<
", " << Shuffle[
I];
4775void AssemblyWriter::printUseLists(
const Function *
F) {
4776 auto It = UseListOrders.find(
F);
4777 if (It == UseListOrders.end())
4780 Out <<
"\n; uselistorder directives\n";
4781 for (
const auto &Pair : It->second)
4782 printUseListOrder(Pair.first, Pair.second);
4790 bool ShouldPreserveUseListOrder,
4791 bool IsForDebug)
const {
4794 AssemblyWriter W(
OS, SlotTable, this->
getParent(), AAW,
4796 ShouldPreserveUseListOrder);
4797 W.printFunction(
this);
4801 bool ShouldPreserveUseListOrder,
4802 bool IsForDebug)
const {
4805 AssemblyWriter W(
OS, SlotTable, this->
getModule(), AAW,
4807 ShouldPreserveUseListOrder);
4808 W.printBasicBlock(
this);
4812 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
4815 AssemblyWriter W(
OS, SlotTable,
this, AAW, IsForDebug,
4816 ShouldPreserveUseListOrder);
4817 W.printModule(
this);
4823 AssemblyWriter W(
OS, SlotTable,
getParent(),
nullptr, IsForDebug);
4824 W.printNamedMDNode(
this);
4828 bool IsForDebug)
const {
4829 std::optional<SlotTracker> LocalST;
4835 SlotTable = &*LocalST;
4839 AssemblyWriter W(
OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4840 W.printNamedMDNode(
this);
4845 ROS <<
" = comdat ";
4852 ROS <<
"exactmatch";
4858 ROS <<
"nodeduplicate";
4870 TP.print(
const_cast<Type*
>(
this),
OS);
4876 if (
StructType *STy = dyn_cast<StructType>(
const_cast<Type*
>(
this)))
4879 TP.printStructBody(STy,
OS);
4884 if (
const auto *CI = dyn_cast<CallInst>(&
I))
4885 if (
Function *
F = CI->getCalledFunction())
4886 if (
F->isIntrinsic())
4887 for (
auto &
Op :
I.operands())
4888 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4889 if (isa<MDNode>(V->getMetadata()))
4897 print(ROS, MST, IsForDebug);
4903 print(ROS, MST, IsForDebug);
4907 bool IsForDebug)
const {
4912 auto incorporateFunction = [&](
const Function *
F) {
4918 W.printDPMarker(*
this);
4924 print(ROS, MST, IsForDebug);
4928 bool IsForDebug)
const {
4933 auto incorporateFunction = [&](
const Function *
F) {
4941 W.printDPValue(*
this);
4945 bool IsForDebug)
const {
4950 auto incorporateFunction = [&](
const Function *
F) {
4957 W.printDPLabel(*
this);
4961 bool ShouldInitializeAllMetadata =
false;
4962 if (
auto *
I = dyn_cast<Instruction>(
this))
4964 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
4965 ShouldInitializeAllMetadata =
true;
4968 print(ROS, MST, IsForDebug);
4972 bool IsForDebug)
const {
4977 auto incorporateFunction = [&](
const Function *
F) {
4982 if (
const Instruction *
I = dyn_cast<Instruction>(
this)) {
4983 incorporateFunction(
I->getParent() ?
I->getParent()->getParent() :
nullptr);
4985 W.printInstruction(*
I);
4986 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
4987 incorporateFunction(BB->getParent());
4989 W.printBasicBlock(BB);
4990 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
4991 AssemblyWriter W(
OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
4994 else if (
const Function *
F = dyn_cast<Function>(GV))
4996 else if (
const GlobalAlias *
A = dyn_cast<GlobalAlias>(GV))
4998 else if (
const GlobalIFunc *
I = dyn_cast<GlobalIFunc>(GV))
5002 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
5004 }
else if (
const Constant *
C = dyn_cast<Constant>(
this)) {
5005 TypePrinting TypePrinter;
5006 TypePrinter.print(
C->getType(),
OS);
5008 AsmWriterContext WriterCtx(&TypePrinter, MST.
getMachine());
5010 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
5022 if (V.hasName() || isa<GlobalValue>(V) ||
5023 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
5024 AsmWriterContext WriterCtx(
nullptr,
Machine, M);
5033 TypePrinting TypePrinter(MST.
getModule());
5035 TypePrinter.print(V.getType(), O);
5053 M, isa<MetadataAsValue>(
this));
5069 AsmWriterContext &WriterCtx) {
5073 auto *
N = dyn_cast<MDNode>(&MD);
5074 if (!
N || isa<DIExpression>(MD))
5082struct MDTreeAsmWriterContext :
public AsmWriterContext {
5085 using EntryTy = std::pair<unsigned, std::string>;
5095 : AsmWriterContext(TP,
ST,
M), Level(0
U), Visited({InitMD}), MainOS(
OS) {}
5097 void onWriteMetadataAsOperand(
const Metadata *MD)
override {
5098 if (!Visited.
insert(MD).second)
5107 unsigned InsertIdx = Buffer.
size() - 1;
5110 Buffer[InsertIdx].second = std::move(
SS.str());
5114 ~MDTreeAsmWriterContext() {
5115 for (
const auto &Entry : Buffer) {
5117 unsigned NumIndent = Entry.first * 2U;
5118 MainOS.
indent(NumIndent) << Entry.second;
5126 bool OnlyAsOperand,
bool PrintAsTree =
false) {
5129 TypePrinting TypePrinter(M);
5131 std::unique_ptr<AsmWriterContext> WriterCtx;
5132 if (PrintAsTree && !OnlyAsOperand)
5133 WriterCtx = std::make_unique<MDTreeAsmWriterContext>(
5137 std::make_unique<AsmWriterContext>(&TypePrinter, MST.
getMachine(), M);
5141 auto *
N = dyn_cast<MDNode>(&MD);
5142 if (OnlyAsOperand || !
N || isa<DIExpression>(MD))
5166 const Module *M,
bool )
const {
5185 AssemblyWriter W(
OS, SlotTable,
this, IsForDebug);
5186 W.printModuleSummaryIndex();
5190 unsigned UB)
const {
5196 if (
I.second >= LB &&
I.second < UB)
5197 L.push_back(std::make_pair(
I.second,
I.first));
5200#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
MapVector< const Value *, unsigned > OrderMap
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand, bool PrintAsTree=false)
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT)
static std::vector< unsigned > predictValueUseListOrder(const Value *V, unsigned ID, const OrderMap &OM)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void orderValue(const Value *V, OrderMap &OM)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
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...
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)
static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef< int > Mask)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static bool isReferencingMDNode(const Instruction &I)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, AsmWriterContext &Ctx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, ModuleSlotTracker &MST)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static const char * getSummaryKindName(GlobalValueSummary::SummaryKind SK)
static OrderMap orderModule(const Module *M)
static const char * getVisibilityName(GlobalValue::VisibilityTypes Vis)
static void printMetadataImplRec(raw_ostream &ROS, const Metadata &MD, AsmWriterContext &WriterCtx)
Recursive version of printMetadataImpl.
static SlotTracker * createSlotTracker(const Value *V)
static void WriteAPFloatInternal(raw_ostream &Out, const APFloat &APF)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static const Module * getModuleFromDPI(const DPMarker *Marker)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static UseListOrderMap predictUseListOrder(const Module *M)
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, AsmWriterContext &WriterCtx)
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, AsmWriterContext &WriterCtx)
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static const char * getTTResKindName(TypeTestResolution::Kind K)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static const Module * getModuleFromVal(const Value *V)
static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I, raw_ostream &Out)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void PrintDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
static bool printWithoutType(const Value &V, raw_ostream &O, SlotTracker *Machine, const Module *M)
Print without a type, skipping the TypePrinting object.
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static const Value * skipMetadataWrapper(const Value *V)
Look for a value that might be wrapped as metadata, e.g.
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
COFF::MachineTypes Machine
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil pretty DXIL Metadata Pretty Printer
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file contains an interface for creating legacy passes to print out IR in various granularities.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides utility classes that use RAII to save and restore values.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
This defines the Use class.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
const fltSemantics & getSemantics() const
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
Abstract interface of slot tracker storage.
virtual ~AbstractSlotTrackerStorage()
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
virtual ~AssemblyAnnotationWriter()
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
static StringRef getOperationName(BinOp Op)
AttributeSet getFnAttrs() const
The function attributes are returned.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
bool hasRetAttrs() const
Return true if attributes exist for the return value.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
bool hasFnAttrs() const
Return true the attributes exist for the function.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
bool hasAttributes() const
Return true if attributes exists in this set.
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM Basic Block Representation.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the basic block to an output stream with an optional AssemblyAnnotationWriter.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const Function * getParent() const
Return the enclosing method, or null if none.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
The address of a basic block.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
void print(raw_ostream &OS, bool IsForDebug=false) const
StringRef getName() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
SelectionKind getSelectionKind() const
ConstantArray - Constant Array Declarations.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
This is an important base class in LLVM.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
static const char * nameTableKindString(DebugNameTableKind PK)
static const char * emissionKindString(DebugEmissionKind EK)
A lightweight wrapper around an expression operand.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Macro Info DWARF-like metadata node.
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Tagged DWARF-like metadata node.
static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static StringRef getFlagString(DIFlags Flag)
String type, Fortran CHARACTER(n)
static DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static StringRef getFlagString(DISPFlags Flag)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
Records a position in IR for a source label (DILabel).
void print(raw_ostream &O, bool IsForDebug=false) const
Per-instruction record of debug-info.
const BasicBlock * getParent() const
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on DPMarker.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
MDNode * getRawVariable() const
void print(raw_ostream &O, bool IsForDebug=false) const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
LocationType getType() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAssignID() const
Metadata * getRawAddress() const
This class represents an Operation in the Expression.
unsigned getProgramAddressSpace() const
Base class for non-instruction debug metadata records that have positions within IR.
void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
DPMarker * Marker
Marker that this DbgRecord is linked into.
MDNode * getAsMDNode() const
Return this as a bar MDNode.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Utility class for floating point operations which can have information about relaxed accuracy require...
An instruction for ordering other memory operations.
Function summary information to aid decisions and implementation of importing.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter.
Represents calls to the gc.relocate intrinsic.
Value * getBasePtr() const
Value * getDerivedPtr() const
Generic tagged DWARF-like metadata node.
const Constant * getAliasee() const
const Constant * getResolver() const
StringRef getSection() const
Get the custom section of this global if it has one.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
const Comdat * getComdat() const
bool hasSection() const
Check if this global has a custom object file section.
Function and variable summary information to aid decisions and implementation of importing.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
bool hasPartition() const
const SanitizerMetadata & getSanitizerMetadata() const
bool hasExternalLinkage() const
VisibilityTypes getVisibility() const
bool isImplicitDSOLocal() const
LinkageTypes getLinkage() const
ThreadLocalMode getThreadLocalMode() const
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
bool hasSanitizerMetadata() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
StringRef getPartition() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Type * getValueType() const
Global variable summary information to aid decisions and implementation of importing.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isExternallyInitialized() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
AttributeSet getAttributes() const
Return the attribute set for this global.
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
This instruction inserts a struct field of array element value into an aggregate value.
This is an important class for using LLVM in a threaded context.
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
void printTree(raw_ostream &OS, const Module *M=nullptr) const
Print in tree shape.
void dumpTree() const
User-friendly dump in tree shape.
This class implements a map that also provides access to all stored values in a deterministic order.
Manage lifetime of a slot tracker for printing IR.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
const Module * getModule() const
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
virtual ~ModuleSlotTracker()
Destructor to clean up storage.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
SlotTracker * getMachine()
Lazily creates a slot tracker.
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
void incorporateFunction(const Function &F)
Incorporate the given function.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr const char * getRegularLTOModuleName()
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
void dump() const
Dump to stderr (for debugging).
void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
A Module instance is used to store all the information related to an LLVM module.
iterator_range< ifunc_iterator > ifuncs()
iterator_range< named_metadata_iterator > named_metadata()
iterator_range< alias_iterator > aliases()
iterator_range< global_iterator > globals()
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void dump() const
Dump the module to stderr (for debugging).
StringRef getName() const
void print(raw_ostream &ROS, bool IsForDebug=false) const
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
Module * getParent()
Get the module that holds this named metadata collection.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
A vector that has set insertion semantics.
This instruction constructs a fixed permutation of two input vectors.
This class provides computation of slot numbers for LLVM Assembly writing.
int getMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
int getTypeIdCompatibleVtableSlot(StringRef Id)
int getModulePathSlot(StringRef Path)
unsigned mdn_size() const
SlotTracker(const SlotTracker &)=delete
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
int getTypeIdSlot(StringRef Id)
void initializeIfNeeded()
These functions do the actual initialization.
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
const Function * getFunction() const
unsigned getNextMetadataSlot() override
void incorporateFunction(const Function *F)
If you'd like to deal with a function instead of just a module, use this method to get its data into ...
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
int getAttributeGroupSlot(AttributeSet AS)
SlotTracker(const Module *M, bool ShouldInitializeAllMetadata=false)
Construct from a module.
void createMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
SlotTracker & operator=(const SlotTracker &)=delete
int getGUIDSlot(GlobalValue::GUID GUID)
int initializeIndexIfNeeded()
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Class to represent struct types.
ArrayRef< Type * > elements() const
unsigned getNumElements() const
Random access to the elements.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
StringRef getName() const
Return the name for this struct type if it has an identity.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
ArrayRef< Type * > type_params() const
Return the type parameters for this particular target extension type.
ArrayRef< unsigned > int_params() const
Return the integer parameters for this particular target extension type.
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
StringRef getTargetExtName() const
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
A few GPU targets, such as DXIL and SPIR-V, have typed pointers.
Type * getElementType() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
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.
StringRef getName() const
Return a constant reference to the value's name.
void dump() const
Support for debugging, callable in GDB: V->dump()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
StringRef LanguageString(unsigned Language)
StringRef AttributeEncodingString(unsigned Encoding)
StringRef ConventionString(unsigned Convention)
StringRef MacinfoString(unsigned Encoding)
StringRef OperationEncodingString(unsigned Encoding)
StringRef TagString(unsigned Tag)
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AVR_SIGNAL
Used for AVR signal routines.
@ Swift
Calling convention for Swift.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
@ AVR_INTR
Used for AVR interrupt routines.
@ PreserveMost
Used for runtime calls that preserves most registers.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ DUMMY_HHVM
Placeholders for HHVM calling conventions (deprecated, removed).
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2
Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ CXX_FAST_TLS
Used for access functions.
@ X86_INTR
x86 hardware interrupt context.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0
Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ X86_ThisCall
Similar to X86_StdCall.
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
@ X86_StdCall
stdcall is mostly used by the Win32 API.
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ MSP430_INTR
Used for MSP430 interrupt routines.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ PreserveNone
Used for runtime calls that preserves none general registers.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
@ M68k_RTD
Used for M68k rtd-based CC (similar to X86's stdcall).
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
@ System
Synchronized with respect to all concurrently executing threads.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
const char * getHotnessName(CalleeInfo::HotnessType HT)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
Interval::pred_iterator pred_end(Interval *I)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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 is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
constexpr int PoisonMaskElem
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Ref
The access may reference the value stored in memory.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
@ Default
The result values are uniform if and only if all operands are uniform.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
static const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & IEEEhalf() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
A single checksum, represented by a Kind and a Value (a string).
T Value
The string value of the checksum.
StringRef getKindAsString() const
All type identifier related information.
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
std::vector< VFuncId > TypeCheckedLoadVCalls
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
An "identifier" for a virtual function.
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
unsigned Linkage
The linkage type of the associated global value.
unsigned Visibility
Indicates the visibility.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
A lightweight accessor for an operand bundle meant to be passed around by value.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
A utility class that uses RAII to save and restore the value of a variable.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
Kind
Specifies which kind of type check we should emit for this byte array.
@ Unknown
Unknown (analysis not performed, don't lower)
@ Single
Single element (last example in "Short Inline Bit Vectors")
@ Inline
Inlined bit vector ("Short Inline Bit Vectors")
@ Unsat
Unsatisfiable type (i.e. no global has this type metadata)
@ AllOnes
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors")
@ ByteArray
Test a byte array (first example)
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
Struct that holds a reference to a particular GUID in a global value summary.
@ UniformRetVal
Uniform return value optimization.
@ VirtualConstProp
Virtual constant propagation.
@ UniqueRetVal
Unique return value optimization.
@ Indir
Just do a regular virtual call.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName
@ SingleImpl
Single implementation devirtualization.
@ Indir
Just do a regular virtual call.
@ BranchFunnel
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module.
Function object to check whether the second component of a container supported by std::get (like std:...