31#include "llvm/Config/llvm-config.h"
106 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V))
107 if (
const auto *VAM = dyn_cast<ValueAsMetadata>(MAV->getMetadata()))
108 return VAM->getValue();
116 if (
const Constant *
C = dyn_cast<Constant>(V))
117 if (
C->getNumOperands() && !isa<GlobalValue>(
C))
118 for (
const Value *
Op :
C->operands())
119 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
124 unsigned ID = OM.size() + 1;
132 if (
G.hasInitializer())
133 if (!isa<GlobalValue>(
G.getInitializer()))
138 if (!isa<GlobalValue>(
A.getAliasee()))
143 if (!isa<GlobalValue>(
I.getResolver()))
148 for (
const Use &U :
F.operands())
149 if (!isa<GlobalValue>(U.get()))
154 if (
F.isDeclaration())
162 for (
const Value *
Op :
I.operands()) {
164 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
175static std::vector<unsigned>
178 using Entry = std::pair<const Use *, unsigned>;
180 for (
const Use &U : V->uses())
182 if (OM.lookup(U.getUser()))
183 List.push_back(std::make_pair(&U,
List.size()));
192 bool GetsReversed = !isa<BasicBlock>(V);
193 if (
auto *BA = dyn_cast<BlockAddress>(V))
194 ID = OM.lookup(BA->getBasicBlock());
196 const Use *LU = L.first;
197 const Use *RU = R.first;
201 auto LID = OM.lookup(LU->getUser());
202 auto RID = OM.lookup(RU->getUser());
222 return LU->getOperandNo() < RU->getOperandNo();
223 return LU->getOperandNo() > RU->getOperandNo();
231 std::vector<unsigned> Shuffle(
List.size());
232 for (
size_t I = 0, E =
List.size();
I != E; ++
I)
233 Shuffle[
I] =
List[
I].second;
240 for (
const auto &Pair : OM) {
241 const Value *V = Pair.first;
242 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
245 std::vector<unsigned> Shuffle =
251 if (
auto *
I = dyn_cast<Instruction>(V))
252 F =
I->getFunction();
253 if (
auto *
A = dyn_cast<Argument>(V))
255 if (
auto *BB = dyn_cast<BasicBlock>(V))
257 ULOM[
F][V] = std::move(Shuffle);
263 if (
const Argument *MA = dyn_cast<Argument>(V))
264 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
266 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
267 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
270 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
271 return M ? M->getParent() :
nullptr;
274 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
275 return GV->getParent();
277 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
278 for (
const User *U : MAV->users())
279 if (isa<Instruction>(U))
291 return M ? M->getParent() :
nullptr;
300 default: Out <<
"cc" << cc;
break;
323 Out <<
"aarch64_sve_vector_pcs";
326 Out <<
"aarch64_sme_preservemost_from_x0";
329 Out <<
"aarch64_sme_preservemost_from_x1";
332 Out <<
"aarch64_sme_preservemost_from_x2";
360 Out <<
"amdgpu_cs_chain";
363 Out <<
"amdgpu_cs_chain_preserve";
369 Out <<
"riscv_vector_cc";
383 assert(!
Name.empty() &&
"Cannot get empty name!");
386 bool NeedsQuotes = isdigit(
static_cast<unsigned char>(
Name[0]));
388 for (
unsigned char C :
Name) {
393 if (!isalnum(
static_cast<unsigned char>(
C)) &&
C !=
'-' &&
C !=
'.' &&
410 printEscapedString(
Name,
OS);
446 if (isa<ScalableVectorType>(Ty))
448 Out << Mask.size() <<
" x i32> ";
449 bool FirstElt =
true;
450 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
451 Out <<
"zeroinitializer";
456 for (
int Elt : Mask) {
475 TypePrinting(
const Module *M =
nullptr) : DeferredM(
M) {}
477 TypePrinting(
const TypePrinting &) =
delete;
478 TypePrinting &operator=(
const TypePrinting &) =
delete;
484 std::vector<StructType *> &getNumberedTypes();
493 void incorporateTypes();
503 std::vector<StructType *> NumberedTypes;
513std::vector<StructType *> &TypePrinting::getNumberedTypes() {
519 if (NumberedTypes.size() == Type2Number.size())
520 return NumberedTypes;
522 NumberedTypes.resize(Type2Number.size());
523 for (
const auto &
P : Type2Number) {
524 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
525 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
526 NumberedTypes[
P.second] =
P.first;
528 return NumberedTypes;
531bool TypePrinting::empty() {
533 return NamedTypes.empty() && Type2Number.empty();
536void TypePrinting::incorporateTypes() {
540 NamedTypes.run(*DeferredM,
false);
545 unsigned NextNumber = 0;
547 std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();
550 if (STy->isLiteral())
553 if (STy->getName().empty())
554 Type2Number[STy] = NextNumber++;
559 NamedTypes.erase(NextToUse, NamedTypes.end());
581 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
586 print(FTy->getReturnType(),
OS);
589 for (
Type *Ty : FTy->params()) {
602 return printStructBody(STy,
OS);
608 const auto I = Type2Number.find(STy);
609 if (
I != Type2Number.end())
610 OS <<
'%' <<
I->second;
612 OS <<
"%\"type " << STy <<
'\"';
624 OS <<
'[' << ATy->getNumElements() <<
" x ";
625 print(ATy->getElementType(),
OS);
636 OS <<
EC.getKnownMinValue() <<
" x ";
637 print(PTy->getElementType(),
OS);
654 Inner->print(
OS,
false,
true);
657 OS <<
", " << IntParam;
708 const Function* TheFunction =
nullptr;
709 bool FunctionProcessed =
false;
710 bool ShouldInitializeAllMetadata;
715 ProcessFunctionHookFn;
730 unsigned mdnNext = 0;
738 unsigned ModulePathNext = 0;
742 unsigned GUIDNext = 0;
746 unsigned TypeIdNext = 0;
751 unsigned TypeIdCompatibleVtableNext = 0;
760 bool ShouldInitializeAllMetadata =
false);
768 bool ShouldInitializeAllMetadata =
false);
802 FunctionProcessed =
false;
841 void CreateMetadataSlot(
const MDNode *
N);
844 void CreateFunctionSlot(
const Value *V);
849 inline void CreateModulePathSlot(
StringRef Path);
852 void CreateTypeIdCompatibleVtableSlot(
StringRef Id);
856 void processModule();
861 void processFunction();
864 void processGlobalObjectMetadata(
const GlobalObject &GO);
867 void processFunctionMetadata(
const Function &
F);
873 void processDbgRecordMetadata(
const DbgRecord &DVR);
883 bool ShouldInitializeAllMetadata)
884 : ShouldCreateStorage(M),
885 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
890 if (!ShouldCreateStorage)
893 ShouldCreateStorage =
false;
895 std::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
896 Machine = MachineStorage.get();
897 if (ProcessModuleHookFn)
899 if (ProcessFunctionHookFn)
919 assert(F &&
"No function incorporated");
926 ProcessModuleHookFn = Fn;
932 ProcessFunctionHookFn = Fn;
936 if (
const Argument *FA = dyn_cast<Argument>(V))
943 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
949 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
952 if (
const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
955 if (
const Function *Func = dyn_cast<Function>(V))
962#define ST_DEBUG(X) dbgs() << X
970 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
975 : TheModule(
F ?
F->
getParent() : nullptr), TheFunction(
F),
976 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
979 : TheModule(nullptr), ShouldInitializeAllMetadata(
false), TheIndex(Index) {}
987 if (TheFunction && !FunctionProcessed)
994 int NumSlots = processIndex();
1001void SlotTracker::processModule() {
1002 ST_DEBUG(
"begin processModule!\n");
1007 CreateModuleSlot(&Var);
1008 processGlobalObjectMetadata(Var);
1009 auto Attrs = Var.getAttributes();
1010 if (Attrs.hasAttributes())
1011 CreateAttributeSetSlot(Attrs);
1016 CreateModuleSlot(&
A);
1021 CreateModuleSlot(&
I);
1026 for (
const MDNode *
N : NMD.operands())
1027 CreateMetadataSlot(
N);
1033 CreateModuleSlot(&
F);
1035 if (ShouldInitializeAllMetadata)
1036 processFunctionMetadata(
F);
1042 CreateAttributeSetSlot(FnAttrs);
1045 if (ProcessModuleHookFn)
1046 ProcessModuleHookFn(
this, TheModule, ShouldInitializeAllMetadata);
1052void SlotTracker::processFunction() {
1053 ST_DEBUG(
"begin processFunction!\n");
1057 if (!ShouldInitializeAllMetadata)
1058 processFunctionMetadata(*TheFunction);
1062 AE = TheFunction->
arg_end(); AI != AE; ++AI)
1064 CreateFunctionSlot(&*AI);
1066 ST_DEBUG(
"Inserting Instructions:\n");
1069 for (
auto &BB : *TheFunction) {
1071 CreateFunctionSlot(&BB);
1073 for (
auto &
I : BB) {
1074 if (!
I.getType()->isVoidTy() && !
I.hasName())
1075 CreateFunctionSlot(&
I);
1079 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1082 if (
Attrs.hasAttributes())
1083 CreateAttributeSetSlot(Attrs);
1088 if (ProcessFunctionHookFn)
1089 ProcessFunctionHookFn(
this, TheFunction, ShouldInitializeAllMetadata);
1091 FunctionProcessed =
true;
1093 ST_DEBUG(
"end processFunction!\n");
1097int SlotTracker::processIndex() {
1104 std::vector<StringRef> ModulePaths;
1106 ModulePaths.push_back(ModPath);
1107 llvm::sort(ModulePaths.begin(), ModulePaths.end());
1108 for (
auto &ModPath : ModulePaths)
1109 CreateModulePathSlot(ModPath);
1112 GUIDNext = ModulePathNext;
1114 for (
auto &GlobalList : *TheIndex)
1115 CreateGUIDSlot(GlobalList.first);
1118 TypeIdCompatibleVtableNext = GUIDNext;
1119 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1120 CreateTypeIdCompatibleVtableSlot(TId.first);
1123 TypeIdNext = TypeIdCompatibleVtableNext;
1124 for (
const auto &TID : TheIndex->typeIds())
1125 CreateTypeIdSlot(TID.second.first);
1131void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1134 for (
auto &MD : MDs)
1135 CreateMetadataSlot(MD.second);
1138void SlotTracker::processFunctionMetadata(
const Function &
F) {
1139 processGlobalObjectMetadata(
F);
1140 for (
auto &BB :
F) {
1141 for (
auto &
I : BB) {
1142 for (
const DbgRecord &DR :
I.getDbgRecordRange())
1143 processDbgRecordMetadata(DR);
1144 processInstructionMetadata(
I);
1149void SlotTracker::processDbgRecordMetadata(
const DbgRecord &DR) {
1155 if (
auto *Empty = dyn_cast<MDNode>(DVR->getRawLocation()))
1156 CreateMetadataSlot(Empty);
1157 CreateMetadataSlot(DVR->getRawVariable());
1158 if (DVR->isDbgAssign()) {
1159 CreateMetadataSlot(cast<MDNode>(DVR->getRawAssignID()));
1160 if (
auto *Empty = dyn_cast<MDNode>(DVR->getRawAddress()))
1161 CreateMetadataSlot(Empty);
1163 }
else if (
const DbgLabelRecord *DLR = dyn_cast<const DbgLabelRecord>(&DR)) {
1164 CreateMetadataSlot(DLR->getRawLabel());
1171void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1173 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
1174 if (
Function *
F = CI->getCalledFunction())
1175 if (
F->isIntrinsic())
1176 for (
auto &
Op :
I.operands())
1177 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1178 if (
MDNode *
N = dyn_cast<MDNode>(
V->getMetadata()))
1179 CreateMetadataSlot(
N);
1183 I.getAllMetadata(MDs);
1184 for (
auto &MD : MDs)
1185 CreateMetadataSlot(MD.second);
1192 ST_DEBUG(
"begin purgeFunction!\n");
1194 TheFunction =
nullptr;
1195 FunctionProcessed =
false;
1206 return MI == mMap.
end() ? -1 : (int)
MI->second;
1212 ProcessModuleHookFn = Fn;
1218 ProcessFunctionHookFn = Fn;
1231 return MI == mdnMap.
end() ? -1 : (int)
MI->second;
1236 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1242 return FI == fMap.
end() ? -1 : (int)FI->second;
1251 return AI == asMap.
end() ? -1 : (int)AI->second;
1259 auto I = ModulePathMap.
find(Path);
1260 return I == ModulePathMap.
end() ? -1 : (int)
I->second;
1269 return I == GUIDMap.
end() ? -1 : (int)
I->second;
1277 auto I = TypeIdMap.
find(Id);
1278 return I == TypeIdMap.
end() ? -1 : (int)
I->second;
1286 auto I = TypeIdCompatibleVtableMap.
find(Id);
1287 return I == TypeIdCompatibleVtableMap.
end() ? -1 : (int)
I->second;
1291void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1292 assert(V &&
"Can't insert a null Value into SlotTracker!");
1293 assert(!V->getType()->isVoidTy() &&
"Doesn't need a slot!");
1294 assert(!V->hasName() &&
"Doesn't need a slot!");
1296 unsigned DestSlot = mNext++;
1299 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1302 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1303 (isa<Function>(V) ?
'F' :
1304 (isa<GlobalAlias>(V) ?
'A' :
1305 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1309void SlotTracker::CreateFunctionSlot(
const Value *V) {
1310 assert(!V->getType()->isVoidTy() && !V->hasName() &&
"Doesn't need a slot!");
1312 unsigned DestSlot = fNext++;
1316 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1317 DestSlot <<
" [o]\n");
1321void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1322 assert(
N &&
"Can't insert a null Value into SlotTracker!");
1325 if (isa<DIExpression>(
N))
1328 unsigned DestSlot = mdnNext;
1329 if (!mdnMap.
insert(std::make_pair(
N, DestSlot)).second)
1334 for (
unsigned i = 0, e =
N->getNumOperands(); i != e; ++i)
1335 if (
const MDNode *
Op = dyn_cast_or_null<MDNode>(
N->getOperand(i)))
1336 CreateMetadataSlot(
Op);
1339void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1347void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1348 ModulePathMap[
Path] = ModulePathNext++;
1353 GUIDMap[
GUID] = GUIDNext++;
1357void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1358 TypeIdMap[
Id] = TypeIdNext++;
1362void SlotTracker::CreateTypeIdCompatibleVtableSlot(
StringRef Id) {
1363 TypeIdCompatibleVtableMap[
Id] = TypeIdCompatibleVtableNext++;
1368struct AsmWriterContext {
1369 TypePrinting *TypePrinter =
nullptr;
1371 const Module *Context =
nullptr;
1374 : TypePrinter(TP),
Machine(
ST), Context(
M) {}
1376 static AsmWriterContext &getEmpty() {
1377 static AsmWriterContext EmptyCtx(
nullptr,
nullptr);
1383 virtual void onWriteMetadataAsOperand(
const Metadata *) {}
1385 virtual ~AsmWriterContext() =
default;
1394 AsmWriterContext &WriterCtx);
1397 AsmWriterContext &WriterCtx,
1398 bool FromValue =
false);
1401 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U))
1402 Out << FPO->getFastMathFlags();
1405 dyn_cast<OverflowingBinaryOperator>(U)) {
1406 if (OBO->hasNoUnsignedWrap())
1408 if (OBO->hasNoSignedWrap())
1411 dyn_cast<PossiblyExactOperator>(U)) {
1415 dyn_cast<PossiblyDisjointInst>(U)) {
1416 if (PDI->isDisjoint())
1419 if (
GEP->isInBounds())
1421 else if (
GEP->hasNoUnsignedSignedWrap())
1423 if (
GEP->hasNoUnsignedWrap())
1426 Out <<
" inrange(" <<
InRange->getLower() <<
", " <<
InRange->getUpper()
1429 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(U)) {
1430 if (NNI->hasNonNeg())
1432 }
else if (
const auto *TI = dyn_cast<TruncInst>(U)) {
1433 if (TI->hasNoUnsignedWrap())
1435 if (TI->hasNoSignedWrap())
1437 }
else if (
const auto *ICmp = dyn_cast<ICmpInst>(U)) {
1438 if (ICmp->hasSameSign())
1454 bool isNaN = APF.
isNaN();
1456 if (!isInf && !isNaN) {
1465 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
isDigit(StrVal[1]))) &&
1466 "[-+]?[0-9] regex does not match!");
1478 static_assert(
sizeof(double) ==
sizeof(
uint64_t),
1479 "assuming that double is 64 bits!");
1537 AsmWriterContext &WriterCtx) {
1538 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1539 Type *Ty = CI->getType();
1548 Out << (CI->getZExtValue() ?
"true" :
"false");
1550 Out << CI->getValue();
1558 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1559 Type *Ty = CFP->getType();
1575 if (isa<ConstantAggregateZero>(CV) || isa<ConstantTargetNone>(CV)) {
1576 Out <<
"zeroinitializer";
1580 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1581 Out <<
"blockaddress(";
1589 if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV)) {
1590 Out <<
"dso_local_equivalent ";
1595 if (
const auto *
NC = dyn_cast<NoCFIValue>(CV)) {
1605 unsigned NumOpsToWrite = 2;
1606 if (!CPA->getOperand(2)->isNullValue())
1608 if (!CPA->getOperand(3)->isNullValue())
1612 for (
unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {
1614 WriterCtx.TypePrinter->print(CPA->getOperand(i)->getType(), Out);
1622 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1623 Type *ETy = CA->getType()->getElementType();
1625 WriterCtx.TypePrinter->print(ETy, Out);
1628 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1630 WriterCtx.TypePrinter->print(ETy, Out);
1641 if (CA->isString()) {
1643 printEscapedString(CA->getAsString(), Out);
1648 Type *ETy = CA->getType()->getElementType();
1650 WriterCtx.TypePrinter->print(ETy, Out);
1653 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1655 WriterCtx.TypePrinter->print(ETy, Out);
1664 if (CS->getType()->isPacked())
1667 unsigned N = CS->getNumOperands();
1670 WriterCtx.TypePrinter->print(CS->getOperand(0)->getType(), Out);
1675 for (
unsigned i = 1; i <
N; i++) {
1677 WriterCtx.TypePrinter->print(CS->getOperand(i)->getType(), Out);
1686 if (CS->getType()->isPacked())
1691 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1692 auto *CVVTy = cast<FixedVectorType>(CV->
getType());
1693 Type *ETy = CVVTy->getElementType();
1701 if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1703 WriterCtx.TypePrinter->print(ETy, Out);
1712 WriterCtx.TypePrinter->print(ETy, Out);
1715 for (
unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) {
1717 WriterCtx.TypePrinter->print(ETy, Out);
1725 if (isa<ConstantPointerNull>(CV)) {
1730 if (isa<ConstantTokenNone>(CV)) {
1735 if (isa<PoisonValue>(CV)) {
1740 if (isa<UndefValue>(CV)) {
1745 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1751 if (CE->getOpcode() == Instruction::ShuffleVector) {
1752 if (
auto *SplatVal = CE->getSplatValue()) {
1753 if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1755 WriterCtx.TypePrinter->print(SplatVal->getType(), Out);
1764 Out << CE->getOpcodeName();
1769 WriterCtx.TypePrinter->print(
GEP->getSourceElementType(), Out);
1775 WriterCtx.TypePrinter->print((*OI)->getType(), Out);
1778 if (OI+1 != CE->op_end())
1784 WriterCtx.TypePrinter->print(CE->getType(), Out);
1787 if (CE->getOpcode() == Instruction::ShuffleVector)
1794 Out <<
"<placeholder or erroneous Constant>";
1798 AsmWriterContext &WriterCtx) {
1800 for (
unsigned mi = 0, me =
Node->getNumOperands(); mi != me; ++mi) {
1804 else if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1805 Value *V = MDV->getValue();
1806 WriterCtx.TypePrinter->print(V->getType(), Out);
1811 WriterCtx.onWriteMetadataAsOperand(MD);
1822struct FieldSeparator {
1826 FieldSeparator(
const char *Sep =
", ") : Sep(Sep) {}
1834 return OS <<
FS.Sep;
1837struct MDFieldPrinter {
1840 AsmWriterContext &WriterCtx;
1843 : Out(Out), WriterCtx(AsmWriterContext::getEmpty()) {}
1844 MDFieldPrinter(
raw_ostream &Out, AsmWriterContext &Ctx)
1845 : Out(Out), WriterCtx(Ctx) {}
1847 void printTag(
const DINode *
N);
1851 bool ShouldSkipEmpty =
true);
1853 bool ShouldSkipNull =
true);
1854 template <
class IntTy>
1857 bool ShouldSkipZero);
1859 std::optional<bool>
Default = std::nullopt);
1862 template <
class IntTy,
class Stringifier>
1864 bool ShouldSkipZero =
true);
1872void MDFieldPrinter::printTag(
const DINode *
N) {
1873 Out <<
FS <<
"tag: ";
1881void MDFieldPrinter::printMacinfoType(
const DIMacroNode *
N) {
1882 Out <<
FS <<
"type: ";
1887 Out <<
N->getMacinfoType();
1890void MDFieldPrinter::printChecksum(
1893 printString(
"checksum", Checksum.
Value,
false);
1897 bool ShouldSkipEmpty) {
1898 if (ShouldSkipEmpty &&
Value.empty())
1901 Out <<
FS <<
Name <<
": \"";
1902 printEscapedString(
Value, Out);
1907 AsmWriterContext &WriterCtx) {
1913 WriterCtx.onWriteMetadataAsOperand(MD);
1917 bool ShouldSkipNull) {
1918 if (ShouldSkipNull && !MD)
1921 Out <<
FS <<
Name <<
": ";
1925template <
class IntTy>
1926void MDFieldPrinter::printInt(
StringRef Name, IntTy
Int,
bool ShouldSkipZero) {
1927 if (ShouldSkipZero && !
Int)
1934 bool IsUnsigned,
bool ShouldSkipZero) {
1935 if (ShouldSkipZero &&
Int.isZero())
1938 Out <<
FS <<
Name <<
": ";
1939 Int.print(Out, !IsUnsigned);
1943 std::optional<bool>
Default) {
1946 Out <<
FS <<
Name <<
": " << (
Value ?
"true" :
"false");
1953 Out <<
FS <<
Name <<
": ";
1958 FieldSeparator FlagsFS(
" | ");
1959 for (
auto F : SplitFlags) {
1961 assert(!StringF.empty() &&
"Expected valid flag");
1962 Out << FlagsFS << StringF;
1964 if (Extra || SplitFlags.empty())
1965 Out << FlagsFS << Extra;
1972 Out <<
FS <<
Name <<
": ";
1982 FieldSeparator FlagsFS(
" | ");
1983 for (
auto F : SplitFlags) {
1985 assert(!StringF.empty() &&
"Expected valid flag");
1986 Out << FlagsFS << StringF;
1988 if (Extra || SplitFlags.empty())
1989 Out << FlagsFS << Extra;
2004template <
class IntTy,
class Stringifier>
2006 Stringifier
toString,
bool ShouldSkipZero) {
2007 if (ShouldSkipZero && !
Value)
2010 Out <<
FS <<
Name <<
": ";
2019 AsmWriterContext &WriterCtx) {
2020 Out <<
"!GenericDINode(";
2021 MDFieldPrinter
Printer(Out, WriterCtx);
2023 Printer.printString(
"header",
N->getHeader());
2024 if (
N->getNumDwarfOperands()) {
2025 Out <<
Printer.FS <<
"operands: {";
2027 for (
auto &
I :
N->dwarf_operands()) {
2037 AsmWriterContext &WriterCtx) {
2038 Out <<
"!DILocation(";
2039 MDFieldPrinter
Printer(Out, WriterCtx);
2041 Printer.printInt(
"line",
DL->getLine(),
false);
2042 Printer.printInt(
"column",
DL->getColumn());
2043 Printer.printMetadata(
"scope",
DL->getRawScope(),
false);
2044 Printer.printMetadata(
"inlinedAt",
DL->getRawInlinedAt());
2045 Printer.printBool(
"isImplicitCode",
DL->isImplicitCode(),
2051 AsmWriterContext &WriterCtx) {
2052 Out <<
"!DIAssignID()";
2053 MDFieldPrinter
Printer(Out, WriterCtx);
2057 AsmWriterContext &WriterCtx) {
2058 Out <<
"!DISubrange(";
2059 MDFieldPrinter
Printer(Out, WriterCtx);
2061 auto *Count =
N->getRawCountNode();
2062 if (
auto *CE = dyn_cast_or_null<ConstantAsMetadata>(Count)) {
2063 auto *CV = cast<ConstantInt>(CE->getValue());
2064 Printer.printInt(
"count", CV->getSExtValue(),
2067 Printer.printMetadata(
"count", Count,
true);
2071 auto *LBound =
N->getRawLowerBound();
2072 if (
auto *LE = dyn_cast_or_null<ConstantAsMetadata>(LBound)) {
2073 auto *LV = cast<ConstantInt>(LE->getValue());
2074 Printer.printInt(
"lowerBound", LV->getSExtValue(),
2077 Printer.printMetadata(
"lowerBound", LBound,
true);
2079 auto *UBound =
N->getRawUpperBound();
2080 if (
auto *UE = dyn_cast_or_null<ConstantAsMetadata>(UBound)) {
2081 auto *UV = cast<ConstantInt>(UE->getValue());
2082 Printer.printInt(
"upperBound", UV->getSExtValue(),
2085 Printer.printMetadata(
"upperBound", UBound,
true);
2087 auto *Stride =
N->getRawStride();
2088 if (
auto *SE = dyn_cast_or_null<ConstantAsMetadata>(Stride)) {
2089 auto *SV = cast<ConstantInt>(SE->getValue());
2090 Printer.printInt(
"stride", SV->getSExtValue(),
false);
2092 Printer.printMetadata(
"stride", Stride,
true);
2098 AsmWriterContext &WriterCtx) {
2099 Out <<
"!DIGenericSubrange(";
2100 MDFieldPrinter
Printer(Out, WriterCtx);
2102 auto IsConstant = [&](
Metadata *Bound) ->
bool {
2103 if (
auto *BE = dyn_cast_or_null<DIExpression>(Bound)) {
2104 return BE->isConstant() &&
2111 auto GetConstant = [&](
Metadata *Bound) -> int64_t {
2112 assert(IsConstant(Bound) &&
"Expected constant");
2113 auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2114 return static_cast<int64_t
>(BE->getElement(1));
2117 auto *Count =
N->getRawCountNode();
2118 if (IsConstant(Count))
2119 Printer.printInt(
"count", GetConstant(Count),
2122 Printer.printMetadata(
"count", Count,
true);
2124 auto *LBound =
N->getRawLowerBound();
2125 if (IsConstant(LBound))
2126 Printer.printInt(
"lowerBound", GetConstant(LBound),
2129 Printer.printMetadata(
"lowerBound", LBound,
true);
2131 auto *UBound =
N->getRawUpperBound();
2132 if (IsConstant(UBound))
2133 Printer.printInt(
"upperBound", GetConstant(UBound),
2136 Printer.printMetadata(
"upperBound", UBound,
true);
2138 auto *Stride =
N->getRawStride();
2139 if (IsConstant(Stride))
2140 Printer.printInt(
"stride", GetConstant(Stride),
2143 Printer.printMetadata(
"stride", Stride,
true);
2149 AsmWriterContext &) {
2150 Out <<
"!DIEnumerator(";
2152 Printer.printString(
"name",
N->getName(),
false);
2153 Printer.printAPInt(
"value",
N->getValue(),
N->isUnsigned(),
2155 if (
N->isUnsigned())
2156 Printer.printBool(
"isUnsigned",
true);
2161 AsmWriterContext &) {
2162 Out <<
"!DIBasicType(";
2164 if (
N->getTag() != dwarf::DW_TAG_base_type)
2166 Printer.printString(
"name",
N->getName());
2167 Printer.printInt(
"size",
N->getSizeInBits());
2168 Printer.printInt(
"align",
N->getAlignInBits());
2169 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2171 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2172 Printer.printDIFlags(
"flags",
N->getFlags());
2177 AsmWriterContext &WriterCtx) {
2178 Out <<
"!DIStringType(";
2179 MDFieldPrinter
Printer(Out, WriterCtx);
2180 if (
N->getTag() != dwarf::DW_TAG_string_type)
2182 Printer.printString(
"name",
N->getName());
2183 Printer.printMetadata(
"stringLength",
N->getRawStringLength());
2184 Printer.printMetadata(
"stringLengthExpression",
N->getRawStringLengthExp());
2185 Printer.printMetadata(
"stringLocationExpression",
2186 N->getRawStringLocationExp());
2187 Printer.printInt(
"size",
N->getSizeInBits());
2188 Printer.printInt(
"align",
N->getAlignInBits());
2189 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2195 AsmWriterContext &WriterCtx) {
2196 Out <<
"!DIDerivedType(";
2197 MDFieldPrinter
Printer(Out, WriterCtx);
2199 Printer.printString(
"name",
N->getName());
2200 Printer.printMetadata(
"scope",
N->getRawScope());
2201 Printer.printMetadata(
"file",
N->getRawFile());
2202 Printer.printInt(
"line",
N->getLine());
2203 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2205 Printer.printInt(
"size",
N->getSizeInBits());
2206 Printer.printInt(
"align",
N->getAlignInBits());
2207 Printer.printInt(
"offset",
N->getOffsetInBits());
2208 Printer.printDIFlags(
"flags",
N->getFlags());
2209 Printer.printMetadata(
"extraData",
N->getRawExtraData());
2210 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2211 Printer.printInt(
"dwarfAddressSpace", *DWARFAddressSpace,
2213 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2214 if (
auto PtrAuthData =
N->getPtrAuthData()) {
2215 Printer.printInt(
"ptrAuthKey", PtrAuthData->key());
2216 Printer.printBool(
"ptrAuthIsAddressDiscriminated",
2217 PtrAuthData->isAddressDiscriminated());
2218 Printer.printInt(
"ptrAuthExtraDiscriminator",
2219 PtrAuthData->extraDiscriminator());
2220 Printer.printBool(
"ptrAuthIsaPointer", PtrAuthData->isaPointer());
2221 Printer.printBool(
"ptrAuthAuthenticatesNullValues",
2222 PtrAuthData->authenticatesNullValues());
2228 AsmWriterContext &WriterCtx) {
2229 Out <<
"!DICompositeType(";
2230 MDFieldPrinter
Printer(Out, WriterCtx);
2232 Printer.printString(
"name",
N->getName());
2233 Printer.printMetadata(
"scope",
N->getRawScope());
2234 Printer.printMetadata(
"file",
N->getRawFile());
2235 Printer.printInt(
"line",
N->getLine());
2236 Printer.printMetadata(
"baseType",
N->getRawBaseType());
2237 Printer.printInt(
"size",
N->getSizeInBits());
2238 Printer.printInt(
"align",
N->getAlignInBits());
2239 Printer.printInt(
"offset",
N->getOffsetInBits());
2240 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2241 Printer.printDIFlags(
"flags",
N->getFlags());
2242 Printer.printMetadata(
"elements",
N->getRawElements());
2243 Printer.printDwarfEnum(
"runtimeLang",
N->getRuntimeLang(),
2245 Printer.printMetadata(
"vtableHolder",
N->getRawVTableHolder());
2246 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2247 Printer.printString(
"identifier",
N->getIdentifier());
2248 Printer.printMetadata(
"discriminator",
N->getRawDiscriminator());
2249 Printer.printMetadata(
"dataLocation",
N->getRawDataLocation());
2250 Printer.printMetadata(
"associated",
N->getRawAssociated());
2251 Printer.printMetadata(
"allocated",
N->getRawAllocated());
2252 if (
auto *RankConst =
N->getRankConst())
2253 Printer.printInt(
"rank", RankConst->getSExtValue(),
2256 Printer.printMetadata(
"rank",
N->getRawRank(),
true);
2257 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2258 if (
auto *Specification =
N->getRawSpecification())
2259 Printer.printMetadata(
"specification", Specification);
2261 if (
auto EnumKind =
N->getEnumKind())
2269 AsmWriterContext &WriterCtx) {
2270 Out <<
"!DISubroutineType(";
2271 MDFieldPrinter
Printer(Out, WriterCtx);
2272 Printer.printDIFlags(
"flags",
N->getFlags());
2274 Printer.printMetadata(
"types",
N->getRawTypeArray(),
2282 Printer.printString(
"filename",
N->getFilename(),
2284 Printer.printString(
"directory",
N->getDirectory(),
2287 if (
N->getChecksum())
2288 Printer.printChecksum(*
N->getChecksum());
2295 AsmWriterContext &WriterCtx) {
2296 Out <<
"!DICompileUnit(";
2297 MDFieldPrinter
Printer(Out, WriterCtx);
2298 Printer.printDwarfEnum(
"language",
N->getSourceLanguage(),
2300 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2301 Printer.printString(
"producer",
N->getProducer());
2302 Printer.printBool(
"isOptimized",
N->isOptimized());
2303 Printer.printString(
"flags",
N->getFlags());
2304 Printer.printInt(
"runtimeVersion",
N->getRuntimeVersion(),
2306 Printer.printString(
"splitDebugFilename",
N->getSplitDebugFilename());
2307 Printer.printEmissionKind(
"emissionKind",
N->getEmissionKind());
2308 Printer.printMetadata(
"enums",
N->getRawEnumTypes());
2309 Printer.printMetadata(
"retainedTypes",
N->getRawRetainedTypes());
2310 Printer.printMetadata(
"globals",
N->getRawGlobalVariables());
2311 Printer.printMetadata(
"imports",
N->getRawImportedEntities());
2312 Printer.printMetadata(
"macros",
N->getRawMacros());
2313 Printer.printInt(
"dwoId",
N->getDWOId());
2314 Printer.printBool(
"splitDebugInlining",
N->getSplitDebugInlining(),
true);
2315 Printer.printBool(
"debugInfoForProfiling",
N->getDebugInfoForProfiling(),
2317 Printer.printNameTableKind(
"nameTableKind",
N->getNameTableKind());
2318 Printer.printBool(
"rangesBaseAddress",
N->getRangesBaseAddress(),
false);
2319 Printer.printString(
"sysroot",
N->getSysRoot());
2320 Printer.printString(
"sdk",
N->getSDK());
2325 AsmWriterContext &WriterCtx) {
2326 Out <<
"!DISubprogram(";
2327 MDFieldPrinter
Printer(Out, WriterCtx);
2328 Printer.printString(
"name",
N->getName());
2329 Printer.printString(
"linkageName",
N->getLinkageName());
2330 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2331 Printer.printMetadata(
"file",
N->getRawFile());
2332 Printer.printInt(
"line",
N->getLine());
2333 Printer.printMetadata(
"type",
N->getRawType());
2334 Printer.printInt(
"scopeLine",
N->getScopeLine());
2335 Printer.printMetadata(
"containingType",
N->getRawContainingType());
2336 if (
N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
2337 N->getVirtualIndex() != 0)
2338 Printer.printInt(
"virtualIndex",
N->getVirtualIndex(),
false);
2339 Printer.printInt(
"thisAdjustment",
N->getThisAdjustment());
2340 Printer.printDIFlags(
"flags",
N->getFlags());
2341 Printer.printDISPFlags(
"spFlags",
N->getSPFlags());
2342 Printer.printMetadata(
"unit",
N->getRawUnit());
2343 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2344 Printer.printMetadata(
"declaration",
N->getRawDeclaration());
2345 Printer.printMetadata(
"retainedNodes",
N->getRawRetainedNodes());
2346 Printer.printMetadata(
"thrownTypes",
N->getRawThrownTypes());
2347 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2348 Printer.printString(
"targetFuncName",
N->getTargetFuncName());
2353 AsmWriterContext &WriterCtx) {
2354 Out <<
"!DILexicalBlock(";
2355 MDFieldPrinter
Printer(Out, WriterCtx);
2356 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2357 Printer.printMetadata(
"file",
N->getRawFile());
2358 Printer.printInt(
"line",
N->getLine());
2359 Printer.printInt(
"column",
N->getColumn());
2365 AsmWriterContext &WriterCtx) {
2366 Out <<
"!DILexicalBlockFile(";
2367 MDFieldPrinter
Printer(Out, WriterCtx);
2368 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2369 Printer.printMetadata(
"file",
N->getRawFile());
2370 Printer.printInt(
"discriminator",
N->getDiscriminator(),
2376 AsmWriterContext &WriterCtx) {
2377 Out <<
"!DINamespace(";
2378 MDFieldPrinter
Printer(Out, WriterCtx);
2379 Printer.printString(
"name",
N->getName());
2380 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2381 Printer.printBool(
"exportSymbols",
N->getExportSymbols(),
false);
2386 AsmWriterContext &WriterCtx) {
2387 Out <<
"!DICommonBlock(";
2388 MDFieldPrinter
Printer(Out, WriterCtx);
2389 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2390 Printer.printMetadata(
"declaration",
N->getRawDecl(),
false);
2391 Printer.printString(
"name",
N->getName());
2392 Printer.printMetadata(
"file",
N->getRawFile());
2393 Printer.printInt(
"line",
N->getLineNo());
2398 AsmWriterContext &WriterCtx) {
2400 MDFieldPrinter
Printer(Out, WriterCtx);
2402 Printer.printInt(
"line",
N->getLine());
2403 Printer.printString(
"name",
N->getName());
2404 Printer.printString(
"value",
N->getValue());
2409 AsmWriterContext &WriterCtx) {
2410 Out <<
"!DIMacroFile(";
2411 MDFieldPrinter
Printer(Out, WriterCtx);
2412 Printer.printInt(
"line",
N->getLine());
2413 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2414 Printer.printMetadata(
"nodes",
N->getRawElements());
2419 AsmWriterContext &WriterCtx) {
2420 Out <<
"!DIModule(";
2421 MDFieldPrinter
Printer(Out, WriterCtx);
2422 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2423 Printer.printString(
"name",
N->getName());
2424 Printer.printString(
"configMacros",
N->getConfigurationMacros());
2425 Printer.printString(
"includePath",
N->getIncludePath());
2426 Printer.printString(
"apinotes",
N->getAPINotesFile());
2427 Printer.printMetadata(
"file",
N->getRawFile());
2428 Printer.printInt(
"line",
N->getLineNo());
2429 Printer.printBool(
"isDecl",
N->getIsDecl(),
false);
2435 AsmWriterContext &WriterCtx) {
2436 Out <<
"!DITemplateTypeParameter(";
2437 MDFieldPrinter
Printer(Out, WriterCtx);
2438 Printer.printString(
"name",
N->getName());
2439 Printer.printMetadata(
"type",
N->getRawType(),
false);
2440 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2446 AsmWriterContext &WriterCtx) {
2447 Out <<
"!DITemplateValueParameter(";
2448 MDFieldPrinter
Printer(Out, WriterCtx);
2449 if (
N->getTag() != dwarf::DW_TAG_template_value_parameter)
2451 Printer.printString(
"name",
N->getName());
2452 Printer.printMetadata(
"type",
N->getRawType());
2453 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2454 Printer.printMetadata(
"value",
N->getValue(),
false);
2459 AsmWriterContext &WriterCtx) {
2460 Out <<
"!DIGlobalVariable(";
2461 MDFieldPrinter
Printer(Out, WriterCtx);
2462 Printer.printString(
"name",
N->getName());
2463 Printer.printString(
"linkageName",
N->getLinkageName());
2464 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2465 Printer.printMetadata(
"file",
N->getRawFile());
2466 Printer.printInt(
"line",
N->getLine());
2467 Printer.printMetadata(
"type",
N->getRawType());
2468 Printer.printBool(
"isLocal",
N->isLocalToUnit());
2469 Printer.printBool(
"isDefinition",
N->isDefinition());
2470 Printer.printMetadata(
"declaration",
N->getRawStaticDataMemberDeclaration());
2471 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2472 Printer.printInt(
"align",
N->getAlignInBits());
2473 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2478 AsmWriterContext &WriterCtx) {
2479 Out <<
"!DILocalVariable(";
2480 MDFieldPrinter
Printer(Out, WriterCtx);
2481 Printer.printString(
"name",
N->getName());
2482 Printer.printInt(
"arg",
N->getArg());
2483 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2484 Printer.printMetadata(
"file",
N->getRawFile());
2485 Printer.printInt(
"line",
N->getLine());
2486 Printer.printMetadata(
"type",
N->getRawType());
2487 Printer.printDIFlags(
"flags",
N->getFlags());
2488 Printer.printInt(
"align",
N->getAlignInBits());
2489 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2494 AsmWriterContext &WriterCtx) {
2496 MDFieldPrinter
Printer(Out, WriterCtx);
2497 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2498 Printer.printString(
"name",
N->getName());
2499 Printer.printMetadata(
"file",
N->getRawFile());
2500 Printer.printInt(
"line",
N->getLine());
2505 AsmWriterContext &WriterCtx) {
2506 Out <<
"!DIExpression(";
2511 assert(!OpStr.empty() &&
"Expected valid opcode");
2515 Out << FS <<
Op.getArg(0);
2518 for (
unsigned A = 0, AE =
Op.getNumArgs();
A != AE; ++
A)
2519 Out << FS <<
Op.getArg(
A);
2523 for (
const auto &
I :
N->getElements())
2530 AsmWriterContext &WriterCtx,
2531 bool FromValue =
false) {
2533 "Unexpected DIArgList metadata outside of value argument");
2534 Out <<
"!DIArgList(";
2536 MDFieldPrinter
Printer(Out, WriterCtx);
2546 AsmWriterContext &WriterCtx) {
2547 Out <<
"!DIGlobalVariableExpression(";
2548 MDFieldPrinter
Printer(Out, WriterCtx);
2549 Printer.printMetadata(
"var",
N->getVariable());
2550 Printer.printMetadata(
"expr",
N->getExpression());
2555 AsmWriterContext &WriterCtx) {
2556 Out <<
"!DIObjCProperty(";
2557 MDFieldPrinter
Printer(Out, WriterCtx);
2558 Printer.printString(
"name",
N->getName());
2559 Printer.printMetadata(
"file",
N->getRawFile());
2560 Printer.printInt(
"line",
N->getLine());
2561 Printer.printString(
"setter",
N->getSetterName());
2562 Printer.printString(
"getter",
N->getGetterName());
2563 Printer.printInt(
"attributes",
N->getAttributes());
2564 Printer.printMetadata(
"type",
N->getRawType());
2569 AsmWriterContext &WriterCtx) {
2570 Out <<
"!DIImportedEntity(";
2571 MDFieldPrinter
Printer(Out, WriterCtx);
2573 Printer.printString(
"name",
N->getName());
2574 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2575 Printer.printMetadata(
"entity",
N->getRawEntity());
2576 Printer.printMetadata(
"file",
N->getRawFile());
2577 Printer.printInt(
"line",
N->getLine());
2578 Printer.printMetadata(
"elements",
N->getRawElements());
2583 AsmWriterContext &Ctx) {
2584 if (
Node->isDistinct())
2586 else if (
Node->isTemporary())
2587 Out <<
"<temporary!> ";
2589 switch (
Node->getMetadataID()) {
2592#define HANDLE_MDNODE_LEAF(CLASS) \
2593 case Metadata::CLASS##Kind: \
2594 write##CLASS(Out, cast<CLASS>(Node), Ctx); \
2596#include "llvm/IR/Metadata.def"
2603 AsmWriterContext &WriterCtx) {
2609 const Constant *CV = dyn_cast<Constant>(V);
2610 if (CV && !isa<GlobalValue>(CV)) {
2611 assert(WriterCtx.TypePrinter &&
"Constants require TypePrinting!");
2616 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2618 if (IA->hasSideEffects())
2619 Out <<
"sideeffect ";
2620 if (IA->isAlignStack())
2621 Out <<
"alignstack ";
2624 Out <<
"inteldialect ";
2628 printEscapedString(IA->getAsmString(), Out);
2630 printEscapedString(IA->getConstraintString(), Out);
2635 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2643 auto *
Machine = WriterCtx.Machine;
2646 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2647 Slot =
Machine->getGlobalSlot(GV);
2650 Slot =
Machine->getLocalSlot(V);
2657 Slot =
Machine->getLocalSlot(V);
2663 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2664 Slot =
Machine->getGlobalSlot(GV);
2667 Slot =
Machine->getLocalSlot(V);
2676 Out << Prefix << Slot;
2682 AsmWriterContext &WriterCtx,
2686 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2690 if (
const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) {
2695 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2696 std::unique_ptr<SlotTracker> MachineStorage;
2698 if (!WriterCtx.Machine) {
2699 MachineStorage = std::make_unique<SlotTracker>(WriterCtx.Context);
2700 WriterCtx.Machine = MachineStorage.get();
2702 int Slot = WriterCtx.Machine->getMetadataSlot(
N);
2704 if (
const DILocation *Loc = dyn_cast<DILocation>(
N)) {
2710 Out <<
"<" <<
N <<
">";
2716 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2718 printEscapedString(MDS->getString(), Out);
2723 auto *V = cast<ValueAsMetadata>(MD);
2724 assert(WriterCtx.TypePrinter &&
"TypePrinter required for metadata values");
2725 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2726 "Unexpected function-local metadata outside of value argument");
2728 WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);
2735class AssemblyWriter {
2737 const Module *TheModule =
nullptr;
2739 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2741 TypePrinting TypePrinter;
2745 bool ShouldPreserveUseListOrder;
2756 bool ShouldPreserveUseListOrder =
false);
2761 AsmWriterContext getContext() {
2762 return AsmWriterContext(&TypePrinter, &
Machine, TheModule);
2765 void printMDNodeBody(
const MDNode *MD);
2768 void printModule(
const Module *M);
2770 void writeOperand(
const Value *
Op,
bool PrintType);
2772 void writeOperandBundles(
const CallBase *Call);
2778 void writeAtomicCmpXchg(
const LLVMContext &Context,
2783 void writeAllMDNodes();
2784 void writeMDNode(
unsigned Slot,
const MDNode *
Node);
2785 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
2786 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
2787 void writeAllAttributeGroups();
2789 void printTypeIdentities();
2793 void printComdat(
const Comdat *
C);
2799 void printDbgMarker(
const DbgMarker &DPI);
2802 void printDbgRecord(
const DbgRecord &DR);
2803 void printDbgRecordLine(
const DbgRecord &DR);
2805 void printUseListOrder(
const Value *V,
const std::vector<unsigned> &Shuffle);
2808 void printModuleSummaryIndex();
2809 void printSummaryInfo(
unsigned Slot,
const ValueInfo &VI);
2817 void printArgs(
const std::vector<uint64_t> &Args);
2822 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> &VCallList,
2825 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> &VCallList,
2830 void printMetadataAttachments(
2836 void printInfoComment(
const Value &V);
2847 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2848 : Out(
o), TheModule(
M),
Machine(Mac), TypePrinter(
M), AnnotationWriter(AAW),
2849 IsForDebug(IsForDebug),
2850 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2853 for (
const GlobalObject &GO : TheModule->global_objects())
2860 : Out(
o), TheIndex(
Index),
Machine(Mac), TypePrinter(nullptr),
2861 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2863void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2865 Out <<
"<null operand!>";
2869 TypePrinter.print(Operand->
getType(), Out);
2872 auto WriterCtx = getContext();
2876void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2886 Out <<
" syncscope(\"";
2887 printEscapedString(SSNs[SSID], Out);
2894void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2897 if (Ordering == AtomicOrdering::NotAtomic)
2900 writeSyncScope(Context, SSID);
2904void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2908 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
2909 FailureOrdering != AtomicOrdering::NotAtomic);
2911 writeSyncScope(Context, SSID);
2916void AssemblyWriter::writeParamOperand(
const Value *Operand,
2919 Out <<
"<null operand!>";
2924 TypePrinter.print(Operand->
getType(), Out);
2926 if (
Attrs.hasAttributes()) {
2928 writeAttributeSet(Attrs);
2932 auto WriterCtx = getContext();
2936void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
2937 if (!
Call->hasOperandBundles())
2942 bool FirstBundle =
true;
2943 for (
unsigned i = 0, e =
Call->getNumOperandBundles(); i != e; ++i) {
2948 FirstBundle =
false;
2956 bool FirstInput =
true;
2957 auto WriterCtx = getContext();
2958 for (
const auto &Input : BU.
Inputs) {
2963 if (Input ==
nullptr)
2964 Out <<
"<null operand bundle!>";
2966 TypePrinter.print(Input->getType(), Out);
2978void AssemblyWriter::printModule(
const Module *M) {
2981 if (ShouldPreserveUseListOrder)
2984 if (!
M->getModuleIdentifier().empty() &&
2987 M->getModuleIdentifier().find(
'\n') == std::string::npos)
2988 Out <<
"; ModuleID = '" <<
M->getModuleIdentifier() <<
"'\n";
2990 if (!
M->getSourceFileName().empty()) {
2991 Out <<
"source_filename = \"";
2992 printEscapedString(
M->getSourceFileName(), Out);
2996 const std::string &
DL =
M->getDataLayoutStr();
2998 Out <<
"target datalayout = \"" <<
DL <<
"\"\n";
2999 if (!
M->getTargetTriple().empty())
3000 Out <<
"target triple = \"" <<
M->getTargetTriple() <<
"\"\n";
3002 if (!
M->getModuleInlineAsm().empty()) {
3009 std::tie(Front, Asm) =
Asm.split(
'\n');
3013 Out <<
"module asm \"";
3014 printEscapedString(Front, Out);
3016 }
while (!
Asm.empty());
3019 printTypeIdentities();
3022 if (!Comdats.empty())
3024 for (
const Comdat *
C : Comdats) {
3026 if (
C != Comdats.back())
3031 if (!
M->global_empty()) Out <<
'\n';
3033 printGlobal(&GV); Out <<
'\n';
3037 if (!
M->alias_empty()) Out <<
"\n";
3042 if (!
M->ifunc_empty()) Out <<
"\n";
3053 printUseLists(
nullptr);
3058 writeAllAttributeGroups();
3062 if (!
M->named_metadata_empty()) Out <<
'\n';
3065 printNamedMDNode(&
Node);
3074void AssemblyWriter::printModuleSummaryIndex() {
3076 int NumSlots =
Machine.initializeIndexIfNeeded();
3082 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
3083 std::string RegularLTOModuleName =
3085 moduleVec.resize(TheIndex->modulePaths().size());
3086 for (
auto &[ModPath, ModHash] : TheIndex->modulePaths())
3087 moduleVec[
Machine.getModulePathSlot(ModPath)] = std::make_pair(
3090 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
3093 for (
auto &ModPair : moduleVec) {
3094 Out <<
"^" << i++ <<
" = module: (";
3096 printEscapedString(ModPair.first, Out);
3097 Out <<
"\", hash: (";
3099 for (
auto Hash : ModPair.second)
3106 for (
auto &GlobalList : *TheIndex) {
3107 auto GUID = GlobalList.first;
3108 for (
auto &Summary : GlobalList.second.SummaryList)
3113 for (
auto &GlobalList : *TheIndex) {
3114 auto GUID = GlobalList.first;
3115 auto VI = TheIndex->getValueInfo(GlobalList);
3116 printSummaryInfo(
Machine.getGUIDSlot(GUID), VI);
3120 for (
const auto &TID : TheIndex->typeIds()) {
3121 Out <<
"^" <<
Machine.getTypeIdSlot(TID.second.first)
3122 <<
" = typeid: (name: \"" << TID.second.first <<
"\"";
3123 printTypeIdSummary(TID.second.second);
3124 Out <<
") ; guid = " << TID.first <<
"\n";
3128 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
3130 Out <<
"^" <<
Machine.getTypeIdCompatibleVtableSlot(TId.first)
3131 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
3132 printTypeIdCompatibleVtableSummary(TId.second);
3133 Out <<
") ; guid = " <<
GUID <<
"\n";
3137 if (TheIndex->getFlags()) {
3138 Out <<
"^" << NumSlots <<
" = flags: " << TheIndex->getFlags() <<
"\n";
3142 Out <<
"^" << NumSlots <<
" = blockcount: " << TheIndex->getBlockCount()
3152 return "singleImpl";
3154 return "branchFunnel";
3165 return "uniformRetVal";
3167 return "uniqueRetVal";
3169 return "virtualConstProp";
3199 Out <<
", alignLog2: " << TTRes.
AlignLog2;
3201 Out <<
", sizeM1: " << TTRes.
SizeM1;
3211void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
3212 Out <<
", summary: (";
3213 printTypeTestResolution(TIS.
TTRes);
3214 if (!TIS.
WPDRes.empty()) {
3215 Out <<
", wpdResolutions: (";
3217 for (
auto &WPDRes : TIS.
WPDRes) {
3219 Out <<
"(offset: " << WPDRes.first <<
", ";
3220 printWPDRes(WPDRes.second);
3228void AssemblyWriter::printTypeIdCompatibleVtableSummary(
3230 Out <<
", summary: (";
3232 for (
auto &
P : TI) {
3234 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
3235 Out <<
"^" <<
Machine.getGUIDSlot(
P.VTableVI.getGUID());
3241void AssemblyWriter::printArgs(
const std::vector<uint64_t> &Args) {
3244 for (
auto arg : Args) {
3252 Out <<
"wpdRes: (kind: ";
3259 Out <<
", resByArg: (";
3261 for (
auto &ResByArg : WPDRes.
ResByArg) {
3263 printArgs(ResByArg.first);
3264 Out <<
", byArg: (kind: ";
3266 if (ResByArg.second.TheKind ==
3268 ResByArg.second.TheKind ==
3270 Out <<
", info: " << ResByArg.second.Info;
3274 if (ResByArg.second.Byte || ResByArg.second.Bit)
3275 Out <<
", byte: " << ResByArg.second.Byte
3276 <<
", bit: " << ResByArg.second.Bit;
3297void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
3298 Out <<
", aliasee: ";
3309 auto VTableFuncs =
GS->vTableFuncs();
3310 Out <<
", varFlags: (readonly: " <<
GS->VarFlags.MaybeReadOnly <<
", "
3311 <<
"writeonly: " <<
GS->VarFlags.MaybeWriteOnly <<
", "
3312 <<
"constant: " <<
GS->VarFlags.Constant;
3313 if (!VTableFuncs.empty())
3315 <<
"vcall_visibility: " <<
GS->VarFlags.VCallVisibility;
3318 if (!VTableFuncs.empty()) {
3319 Out <<
", vTableFuncs: (";
3321 for (
auto &
P : VTableFuncs) {
3323 Out <<
"(virtFunc: ^" <<
Machine.getGUIDSlot(
P.FuncVI.getGUID())
3324 <<
", offset: " <<
P.VTableOffset;
3342 return "linkonce_odr";
3352 return "extern_weak";
3354 return "available_externally";
3383 return "definition";
3385 return "declaration";
3391 Out <<
", insts: " <<
FS->instCount();
3392 if (
FS->fflags().anyFlagSet())
3393 Out <<
", " <<
FS->fflags();
3395 if (!
FS->calls().empty()) {
3396 Out <<
", calls: (";
3398 for (
auto &Call :
FS->calls()) {
3400 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.first.getGUID());
3401 if (
Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)
3403 else if (
Call.second.RelBlockFreq)
3404 Out <<
", relbf: " <<
Call.second.RelBlockFreq;
3407 if (
Call.second.HasTailCall)
3414 if (
const auto *TIdInfo =
FS->getTypeIdInfo())
3415 printTypeIdInfo(*TIdInfo);
3419 auto AllocTypeName = [](
uint8_t Type) ->
const char * {
3421 case (
uint8_t)AllocationType::None:
3423 case (
uint8_t)AllocationType::NotCold:
3425 case (
uint8_t)AllocationType::Cold:
3427 case (
uint8_t)AllocationType::Hot:
3433 if (!
FS->allocs().empty()) {
3434 Out <<
", allocs: (";
3436 for (
auto &AI :
FS->allocs()) {
3438 Out <<
"(versions: (";
3440 for (
auto V : AI.Versions) {
3442 Out << AllocTypeName(V);
3444 Out <<
"), memProf: (";
3445 FieldSeparator MIBFS;
3446 for (
auto &MIB : AI.MIBs) {
3448 Out <<
"(type: " << AllocTypeName((
uint8_t)MIB.AllocType);
3449 Out <<
", stackIds: (";
3450 FieldSeparator SIDFS;
3451 for (
auto Id : MIB.StackIdIndices) {
3453 Out << TheIndex->getStackIdAtIndex(Id);
3462 if (!
FS->callsites().empty()) {
3463 Out <<
", callsites: (";
3464 FieldSeparator SNFS;
3465 for (
auto &CI :
FS->callsites()) {
3468 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(CI.Callee.getGUID());
3470 Out <<
"(callee: null";
3471 Out <<
", clones: (";
3473 for (
auto V : CI.Clones) {
3477 Out <<
"), stackIds: (";
3478 FieldSeparator SIDFS;
3479 for (
auto Id : CI.StackIdIndices) {
3481 Out << TheIndex->getStackIdAtIndex(Id);
3492 if (!
FS->paramAccesses().empty()) {
3493 Out <<
", params: (";
3495 for (
auto &PS :
FS->paramAccesses()) {
3497 Out <<
"(param: " << PS.ParamNo;
3498 Out <<
", offset: ";
3500 if (!PS.Calls.empty()) {
3501 Out <<
", calls: (";
3503 for (
auto &Call : PS.Calls) {
3505 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.Callee.getGUID());
3506 Out <<
", param: " <<
Call.ParamNo;
3507 Out <<
", offset: ";
3508 PrintRange(
Call.Offsets);
3519void AssemblyWriter::printTypeIdInfo(
3521 Out <<
", typeIdInfo: (";
3522 FieldSeparator TIDFS;
3525 Out <<
"typeTests: (";
3528 auto TidIter = TheIndex->typeIds().equal_range(GUID);
3529 if (TidIter.first == TidIter.second) {
3535 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3537 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3555 "typeTestAssumeConstVCalls");
3560 "typeCheckedLoadConstVCalls");
3566 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
3567 if (TidIter.first == TidIter.second) {
3568 Out <<
"vFuncId: (";
3569 Out <<
"guid: " << VFId.
GUID;
3570 Out <<
", offset: " << VFId.
Offset;
3576 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3578 Out <<
"vFuncId: (";
3579 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3582 Out <<
", offset: " << VFId.
Offset;
3587void AssemblyWriter::printNonConstVCalls(
3588 const std::vector<FunctionSummary::VFuncId> &VCallList,
const char *Tag) {
3589 Out <<
Tag <<
": (";
3591 for (
auto &VFuncId : VCallList) {
3593 printVFuncId(VFuncId);
3598void AssemblyWriter::printConstVCalls(
3599 const std::vector<FunctionSummary::ConstVCall> &VCallList,
3601 Out <<
Tag <<
": (";
3603 for (
auto &ConstVCall : VCallList) {
3606 printVFuncId(ConstVCall.VFunc);
3607 if (!ConstVCall.Args.empty()) {
3609 printArgs(ConstVCall.Args);
3620 Out <<
"(module: ^" <<
Machine.getModulePathSlot(
Summary.modulePath())
3623 Out <<
", visibility: "
3626 Out <<
", live: " << GVFlags.
Live;
3627 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3629 Out <<
", importType: "
3634 printAliasSummary(cast<AliasSummary>(&Summary));
3636 printFunctionSummary(cast<FunctionSummary>(&Summary));
3638 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3640 auto RefList =
Summary.refs();
3641 if (!RefList.empty()) {
3644 for (
auto &
Ref : RefList) {
3646 if (
Ref.isReadOnly())
3648 else if (
Ref.isWriteOnly())
3649 Out <<
"writeonly ";
3650 Out <<
"^" <<
Machine.getGUIDSlot(
Ref.getGUID());
3658void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &VI) {
3659 Out <<
"^" <<
Slot <<
" = gv: (";
3660 if (
VI.hasName() && !
VI.name().empty())
3661 Out <<
"name: \"" <<
VI.name() <<
"\"";
3663 Out <<
"guid: " <<
VI.getGUID();
3664 if (!
VI.getSummaryList().empty()) {
3665 Out <<
", summaries: (";
3667 for (
auto &Summary :
VI.getSummaryList()) {
3669 printSummary(*Summary);
3674 if (
VI.hasName() && !
VI.name().empty())
3675 Out <<
" ; guid = " <<
VI.getGUID();
3682 Out <<
"<empty name> ";
3684 unsigned char FirstC =
static_cast<unsigned char>(
Name[0]);
3685 if (isalpha(FirstC) || FirstC ==
'-' || FirstC ==
'$' || FirstC ==
'.' ||
3689 Out <<
'\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);
3690 for (
unsigned i = 1, e =
Name.size(); i != e; ++i) {
3691 unsigned char C =
Name[i];
3692 if (isalnum(
C) ||
C ==
'-' ||
C ==
'$' ||
C ==
'.' ||
C ==
'_')
3695 Out <<
'\\' << hexdigit(
C >> 4) << hexdigit(
C & 0x0F);
3700void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3711 if (
auto *Expr = dyn_cast<DIExpression>(
Op)) {
3737 Out <<
"dso_local ";
3752 case GlobalVariable::NotThreadLocal:
3754 case GlobalVariable::GeneralDynamicTLSModel:
3755 Out <<
"thread_local ";
3757 case GlobalVariable::LocalDynamicTLSModel:
3758 Out <<
"thread_local(localdynamic) ";
3760 case GlobalVariable::InitialExecTLSModel:
3761 Out <<
"thread_local(initialexec) ";
3763 case GlobalVariable::LocalExecTLSModel:
3764 Out <<
"thread_local(localexec) ";
3771 case GlobalVariable::UnnamedAddr::None:
3773 case GlobalVariable::UnnamedAddr::Local:
3774 return "local_unnamed_addr";
3775 case GlobalVariable::UnnamedAddr::Global:
3776 return "unnamed_addr";
3787 if (isa<GlobalVariable>(GO))
3801 Out <<
"; Materializable\n";
3822 Out << (GV->
isConstant() ?
"constant " :
"global ");
3831 Out <<
", section \"";
3836 Out <<
", partition \"";
3841 Out <<
", code_model \"";
3866 Out <<
", no_sanitize_address";
3868 Out <<
", no_sanitize_hwaddress";
3870 Out <<
", sanitize_memtag";
3872 Out <<
", sanitize_address_dyninit";
3877 Out <<
", align " <<
A->value();
3881 printMetadataAttachments(MDs,
", ");
3884 if (
Attrs.hasAttributes())
3885 Out <<
" #" <<
Machine.getAttributeGroupSlot(Attrs);
3887 printInfoComment(*GV);
3890void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
3892 Out <<
"; Materializable\n";
3913 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
3915 TypePrinter.print(GA->
getType(), Out);
3916 Out <<
" <<NULL ALIASEE>>";
3920 Out <<
", partition \"";
3925 printInfoComment(*GA);
3929void AssemblyWriter::printIFunc(
const GlobalIFunc *GI) {
3931 Out <<
"; Materializable\n";
3949 TypePrinter.print(GI->
getType(), Out);
3950 Out <<
" <<NULL RESOLVER>>";
3954 Out <<
", partition \"";
3959 printInfoComment(*GI);
3963void AssemblyWriter::printComdat(
const Comdat *
C) {
3967void AssemblyWriter::printTypeIdentities() {
3968 if (TypePrinter.empty())
3974 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3975 for (
unsigned I = 0, E = NumberedTypes.size();
I != E; ++
I) {
3976 Out <<
'%' <<
I <<
" = type ";
3980 TypePrinter.printStructBody(NumberedTypes[
I], Out);
3984 auto &NamedTypes = TypePrinter.getNamedTypes();
3991 TypePrinter.printStructBody(NamedType, Out);
3997void AssemblyWriter::printFunction(
const Function *
F) {
3998 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(
F, Out);
4000 if (
F->isMaterializable())
4001 Out <<
"; Materializable\n";
4004 if (
Attrs.hasFnAttrs()) {
4006 std::string AttrStr;
4009 if (!Attr.isStringAttribute()) {
4010 if (!AttrStr.empty()) AttrStr +=
' ';
4011 AttrStr += Attr.getAsString();
4015 if (!AttrStr.empty())
4016 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
4021 if (
F->isDeclaration()) {
4024 F->getAllMetadata(MDs);
4025 printMetadataAttachments(MDs,
" ");
4042 if (
Attrs.hasRetAttrs())
4044 TypePrinter.print(
F->getReturnType(), Out);
4045 AsmWriterContext WriterCtx(&TypePrinter, &
Machine,
F->getParent());
4051 if (
F->isDeclaration() && !IsForDebug) {
4053 for (
unsigned I = 0, E = FT->getNumParams();
I != E; ++
I) {
4058 TypePrinter.print(FT->getParamType(
I), Out);
4063 writeAttributeSet(ArgAttrs);
4070 if (Arg.getArgNo() != 0)
4072 printArgument(&Arg,
Attrs.getParamAttrs(Arg.getArgNo()));
4077 if (FT->isVarArg()) {
4078 if (FT->getNumParams()) Out <<
", ";
4089 if (
F->getAddressSpace() != 0 || !
Mod ||
4090 Mod->getDataLayout().getProgramAddressSpace() != 0)
4091 Out <<
" addrspace(" <<
F->getAddressSpace() <<
")";
4092 if (
Attrs.hasFnAttrs())
4093 Out <<
" #" <<
Machine.getAttributeGroupSlot(
Attrs.getFnAttrs());
4094 if (
F->hasSection()) {
4095 Out <<
" section \"";
4096 printEscapedString(
F->getSection(), Out);
4099 if (
F->hasPartition()) {
4100 Out <<
" partition \"";
4101 printEscapedString(
F->getPartition(), Out);
4106 Out <<
" align " <<
A->value();
4108 Out <<
" gc \"" <<
F->getGC() <<
'"';
4109 if (
F->hasPrefixData()) {
4111 writeOperand(
F->getPrefixData(),
true);
4113 if (
F->hasPrologueData()) {
4114 Out <<
" prologue ";
4115 writeOperand(
F->getPrologueData(),
true);
4117 if (
F->hasPersonalityFn()) {
4118 Out <<
" personality ";
4119 writeOperand(
F->getPersonalityFn(),
true);
4122 if (
F->isDeclaration()) {
4126 F->getAllMetadata(MDs);
4127 printMetadataAttachments(MDs,
" ");
4132 printBasicBlock(&BB);
4147 TypePrinter.print(Arg->
getType(), Out);
4150 if (
Attrs.hasAttributes()) {
4152 writeAttributeSet(Attrs);
4161 assert(Slot != -1 &&
"expect argument in function here");
4162 Out <<
" %" <<
Slot;
4167void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
4173 }
else if (!IsEntryBlock) {
4182 if (!IsEntryBlock) {
4184 Out.PadToColumn(50);
4189 Out <<
" No predecessors!";
4192 writeOperand(*PI,
false);
4193 for (++PI; PI != PE; ++PI) {
4195 writeOperand(*PI,
false);
4202 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
4206 for (
const DbgRecord &DR :
I.getDbgRecordRange())
4207 printDbgRecordLine(DR);
4208 printInstructionLine(
I);
4211 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
4215void AssemblyWriter::printInstructionLine(
const Instruction &
I) {
4216 printInstruction(
I);
4222void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
4232void AssemblyWriter::printInfoComment(
const Value &V) {
4233 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
4234 printGCRelocateComment(*Relocate);
4236 if (AnnotationWriter) {
4237 AnnotationWriter->printInfoComment(V, Out);
4244 if (Operand ==
nullptr) {
4245 Out <<
" <cannot get addrspace!>";
4249 bool PrintAddrSpace = CallAddrSpace != 0;
4250 if (!PrintAddrSpace) {
4255 if (!
Mod ||
Mod->getDataLayout().getProgramAddressSpace() != 0)
4256 PrintAddrSpace =
true;
4259 Out <<
" addrspace(" << CallAddrSpace <<
")";
4263void AssemblyWriter::printInstruction(
const Instruction &
I) {
4264 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&
I, Out);
4273 }
else if (!
I.getType()->isVoidTy()) {
4275 int SlotNum =
Machine.getLocalSlot(&
I);
4277 Out <<
"<badref> = ";
4279 Out <<
'%' << SlotNum <<
" = ";
4282 if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4283 if (CI->isMustTailCall())
4285 else if (CI->isTailCall())
4287 else if (CI->isNoTailCall())
4292 Out <<
I.getOpcodeName();
4295 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isAtomic()) ||
4296 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isAtomic()))
4299 if (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isWeak())
4303 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isVolatile()) ||
4304 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isVolatile()) ||
4305 (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isVolatile()) ||
4306 (isa<AtomicRMWInst>(
I) && cast<AtomicRMWInst>(
I).isVolatile()))
4313 if (
const CmpInst *CI = dyn_cast<CmpInst>(&
I))
4314 Out <<
' ' << CI->getPredicate();
4321 const Value *Operand =
I.getNumOperands() ?
I.getOperand(0) :
nullptr;
4324 if (isa<BranchInst>(
I) && cast<BranchInst>(
I).isConditional()) {
4327 writeOperand(BI.getCondition(),
true);
4329 writeOperand(BI.getSuccessor(0),
true);
4331 writeOperand(BI.getSuccessor(1),
true);
4333 }
else if (isa<SwitchInst>(
I)) {
4337 writeOperand(
SI.getCondition(),
true);
4339 writeOperand(
SI.getDefaultDest(),
true);
4341 for (
auto Case :
SI.cases()) {
4343 writeOperand(Case.getCaseValue(),
true);
4345 writeOperand(Case.getCaseSuccessor(),
true);
4348 }
else if (isa<IndirectBrInst>(
I)) {
4351 writeOperand(Operand,
true);
4354 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i) {
4357 writeOperand(
I.getOperand(i),
true);
4360 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&
I)) {
4362 TypePrinter.print(
I.getType(), Out);
4365 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
4366 if (
op) Out <<
", ";
4368 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
4369 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
4373 writeOperand(
I.getOperand(0),
true);
4374 for (
unsigned i : EVI->indices())
4378 writeOperand(
I.getOperand(0),
true); Out <<
", ";
4379 writeOperand(
I.getOperand(1),
true);
4380 for (
unsigned i : IVI->indices())
4382 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&
I)) {
4384 TypePrinter.print(
I.getType(), Out);
4385 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
4388 if (LPI->isCleanup())
4391 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
4392 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
4393 if (LPI->isCatch(i))
4398 writeOperand(LPI->getClause(i),
true);
4400 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&
I)) {
4402 writeOperand(CatchSwitch->getParentPad(),
false);
4405 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
4408 writeOperand(PadBB,
true);
4412 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
4413 writeOperand(UnwindDest,
true);
4416 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&
I)) {
4418 writeOperand(FPI->getParentPad(),
false);
4420 for (
unsigned Op = 0, NumOps = FPI->arg_size();
Op < NumOps; ++
Op) {
4423 writeOperand(FPI->getArgOperand(
Op),
true);
4426 }
else if (isa<ReturnInst>(
I) && !Operand) {
4428 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&
I)) {
4430 writeOperand(CRI->getOperand(0),
false);
4433 writeOperand(CRI->getOperand(1),
true);
4434 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&
I)) {
4436 writeOperand(CRI->getOperand(0),
false);
4439 if (CRI->hasUnwindDest())
4440 writeOperand(CRI->getOperand(1),
true);
4443 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4450 Operand = CI->getCalledOperand();
4465 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4467 writeOperand(Operand,
false);
4469 for (
unsigned op = 0, Eop = CI->arg_size();
op < Eop; ++
op) {
4477 if (CI->isMustTailCall() && CI->getParent() &&
4478 CI->getParent()->getParent() &&
4479 CI->getParent()->getParent()->isVarArg()) {
4480 if (CI->arg_size() > 0)
4489 writeOperandBundles(CI);
4490 }
else if (
const InvokeInst *
II = dyn_cast<InvokeInst>(&
I)) {
4491 Operand =
II->getCalledOperand();
4513 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4515 writeOperand(Operand,
false);
4517 for (
unsigned op = 0, Eop =
II->arg_size();
op < Eop; ++
op) {
4527 writeOperandBundles(
II);
4530 writeOperand(
II->getNormalDest(),
true);
4532 writeOperand(
II->getUnwindDest(),
true);
4533 }
else if (
const CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
4534 Operand = CBI->getCalledOperand();
4553 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4555 writeOperand(Operand,
false);
4557 for (
unsigned op = 0, Eop = CBI->arg_size();
op < Eop; ++
op) {
4567 writeOperandBundles(CBI);
4570 writeOperand(CBI->getDefaultDest(),
true);
4572 for (
unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i) {
4575 writeOperand(CBI->getIndirectDest(i),
true);
4578 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
4580 if (AI->isUsedWithInAlloca())
4582 if (AI->isSwiftError())
4583 Out <<
"swifterror ";
4584 TypePrinter.print(AI->getAllocatedType(), Out);
4590 if (!AI->getArraySize() || AI->isArrayAllocation() ||
4591 !AI->getArraySize()->getType()->isIntegerTy(32)) {
4593 writeOperand(AI->getArraySize(),
true);
4596 Out <<
", align " <<
A->value();
4599 unsigned AddrSpace = AI->getAddressSpace();
4600 if (AddrSpace != 0) {
4601 Out <<
", addrspace(" << AddrSpace <<
')';
4603 }
else if (isa<CastInst>(
I)) {
4606 writeOperand(Operand,
true);
4609 TypePrinter.print(
I.getType(), Out);
4610 }
else if (isa<VAArgInst>(
I)) {
4613 writeOperand(Operand,
true);
4616 TypePrinter.print(
I.getType(), Out);
4617 }
else if (Operand) {
4618 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&
I)) {
4620 TypePrinter.print(
GEP->getSourceElementType(), Out);
4622 }
else if (
const auto *LI = dyn_cast<LoadInst>(&
I)) {
4624 TypePrinter.print(LI->getType(), Out);
4631 bool PrintAllTypes =
false;
4636 if (isa<SelectInst>(
I) || isa<StoreInst>(
I) || isa<ShuffleVectorInst>(
I) ||
4637 isa<ReturnInst>(
I) || isa<AtomicCmpXchgInst>(
I) ||
4638 isa<AtomicRMWInst>(
I)) {
4639 PrintAllTypes =
true;
4641 for (
unsigned i = 1, E =
I.getNumOperands(); i != E; ++i) {
4642 Operand =
I.getOperand(i);
4645 if (Operand && Operand->
getType() != TheType) {
4646 PrintAllTypes =
true;
4652 if (!PrintAllTypes) {
4654 TypePrinter.print(TheType, Out);
4658 for (
unsigned i = 0, E =
I.getNumOperands(); i != E; ++i) {
4660 writeOperand(
I.getOperand(i), PrintAllTypes);
4665 if (
const LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
4667 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4669 Out <<
", align " <<
A->value();
4670 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(&
I)) {
4672 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4674 Out <<
", align " <<
A->value();
4676 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4677 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4678 Out <<
", align " << CXI->getAlign().value();
4679 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&
I)) {
4680 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4681 RMWI->getSyncScopeID());
4682 Out <<
", align " << RMWI->getAlign().value();
4683 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&
I)) {
4684 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
4691 I.getAllMetadata(InstMD);
4692 printMetadataAttachments(InstMD,
", ");
4695 printInfoComment(
I);
4698void AssemblyWriter::printDbgMarker(
const DbgMarker &Marker) {
4702 printDbgRecord(DPR);
4706 Out <<
" DbgMarker -> { ";
4711void AssemblyWriter::printDbgRecord(
const DbgRecord &DR) {
4712 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR))
4713 printDbgVariableRecord(*DVR);
4714 else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR))
4715 printDbgLabelRecord(*DLR);
4721 auto WriterCtx = getContext();
4724 case DbgVariableRecord::LocationType::Value:
4727 case DbgVariableRecord::LocationType::Declare:
4730 case DbgVariableRecord::LocationType::Assign:
4735 "Tried to print a DbgVariableRecord with an invalid LocationType!");
4758void AssemblyWriter::printDbgRecordLine(
const DbgRecord &DR) {
4765void AssemblyWriter::printDbgLabelRecord(
const DbgLabelRecord &Label) {
4766 auto WriterCtx = getContext();
4767 Out <<
"#dbg_label(";
4774void AssemblyWriter::printMetadataAttachments(
4780 if (MDNames.empty())
4781 MDs[0].second->getContext().getMDKindNames(MDNames);
4783 auto WriterCtx = getContext();
4784 for (
const auto &
I : MDs) {
4785 unsigned Kind =
I.first;
4787 if (Kind < MDNames.size()) {
4791 Out <<
"!<unknown kind #" <<
Kind <<
">";
4797void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *
Node) {
4798 Out <<
'!' <<
Slot <<
" = ";
4799 printMDNodeBody(
Node);
4803void AssemblyWriter::writeAllMDNodes() {
4807 Nodes[
I.second] = cast<MDNode>(
I.first);
4809 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
4810 writeMDNode(i, Nodes[i]);
4814void AssemblyWriter::printMDNodeBody(
const MDNode *
Node) {
4815 auto WriterCtx = getContext();
4819void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
4828 TypePrinter.print(Ty, Out);
4833void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
4835 bool FirstAttr =
true;
4836 for (
const auto &Attr : AttrSet) {
4839 writeAttribute(Attr, InAttrGroup);
4844void AssemblyWriter::writeAllAttributeGroups() {
4845 std::vector<std::pair<AttributeSet, unsigned>> asVec;
4846 asVec.resize(
Machine.as_size());
4849 asVec[
I.second] =
I;
4851 for (
const auto &
I : asVec)
4852 Out <<
"attributes #" <<
I.second <<
" = { "
4853 <<
I.first.getAsString(
true) <<
" }\n";
4856void AssemblyWriter::printUseListOrder(
const Value *V,
4857 const std::vector<unsigned> &Shuffle) {
4858 bool IsInFunction =
Machine.getFunction();
4862 Out <<
"uselistorder";
4863 if (
const BasicBlock *BB = IsInFunction ?
nullptr : dyn_cast<BasicBlock>(V)) {
4865 writeOperand(BB->getParent(),
false);
4867 writeOperand(BB,
false);
4870 writeOperand(V,
true);
4874 assert(Shuffle.size() >= 2 &&
"Shuffle too small");
4876 for (
unsigned I = 1, E = Shuffle.size();
I != E; ++
I)
4877 Out <<
", " << Shuffle[
I];
4881void AssemblyWriter::printUseLists(
const Function *
F) {
4882 auto It = UseListOrders.find(
F);
4883 if (It == UseListOrders.end())
4886 Out <<
"\n; uselistorder directives\n";
4887 for (
const auto &Pair : It->second)
4888 printUseListOrder(Pair.first, Pair.second);
4896 bool ShouldPreserveUseListOrder,
4897 bool IsForDebug)
const {
4900 AssemblyWriter W(
OS, SlotTable, this->
getParent(), AAW,
4902 ShouldPreserveUseListOrder);
4903 W.printFunction(
this);
4907 bool ShouldPreserveUseListOrder,
4908 bool IsForDebug)
const {
4911 AssemblyWriter W(
OS, SlotTable, this->
getModule(), AAW,
4913 ShouldPreserveUseListOrder);
4914 W.printBasicBlock(
this);
4918 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
4921 AssemblyWriter W(
OS, SlotTable,
this, AAW, IsForDebug,
4922 ShouldPreserveUseListOrder);
4923 W.printModule(
this);
4929 AssemblyWriter W(
OS, SlotTable,
getParent(),
nullptr, IsForDebug);
4930 W.printNamedMDNode(
this);
4934 bool IsForDebug)
const {
4935 std::optional<SlotTracker> LocalST;
4941 SlotTable = &*LocalST;
4945 AssemblyWriter W(
OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4946 W.printNamedMDNode(
this);
4951 ROS <<
" = comdat ";
4958 ROS <<
"exactmatch";
4964 ROS <<
"nodeduplicate";
4976 TP.print(
const_cast<Type*
>(
this),
OS);
4982 if (
StructType *STy = dyn_cast<StructType>(
const_cast<Type*
>(
this)))
4985 TP.printStructBody(STy,
OS);
4990 if (
const auto *CI = dyn_cast<CallInst>(&
I))
4991 if (
Function *
F = CI->getCalledFunction())
4992 if (
F->isIntrinsic())
4993 for (
auto &
Op :
I.operands())
4994 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4995 if (isa<MDNode>(V->getMetadata()))
5003 print(ROS, MST, IsForDebug);
5009 print(ROS, MST, IsForDebug);
5013 bool IsForDebug)
const {
5018 auto incorporateFunction = [&](
const Function *
F) {
5024 W.printDbgMarker(*
this);
5030 print(ROS, MST, IsForDebug);
5034 bool IsForDebug)
const {
5039 auto incorporateFunction = [&](
const Function *
F) {
5047 W.printDbgVariableRecord(*
this);
5051 bool IsForDebug)
const {
5056 auto incorporateFunction = [&](
const Function *
F) {
5063 W.printDbgLabelRecord(*
this);
5067 bool ShouldInitializeAllMetadata =
false;
5068 if (
auto *
I = dyn_cast<Instruction>(
this))
5070 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
5071 ShouldInitializeAllMetadata =
true;
5074 print(ROS, MST, IsForDebug);
5078 bool IsForDebug)
const {
5083 auto incorporateFunction = [&](
const Function *
F) {
5088 if (
const Instruction *
I = dyn_cast<Instruction>(
this)) {
5089 incorporateFunction(
I->getParent() ?
I->getParent()->getParent() :
nullptr);
5091 W.printInstruction(*
I);
5092 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
5093 incorporateFunction(BB->getParent());
5095 W.printBasicBlock(BB);
5096 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
5097 AssemblyWriter W(
OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
5100 else if (
const Function *
F = dyn_cast<Function>(GV))
5102 else if (
const GlobalAlias *
A = dyn_cast<GlobalAlias>(GV))
5104 else if (
const GlobalIFunc *
I = dyn_cast<GlobalIFunc>(GV))
5108 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
5110 }
else if (
const Constant *
C = dyn_cast<Constant>(
this)) {
5111 TypePrinting TypePrinter;
5112 TypePrinter.print(
C->getType(),
OS);
5114 AsmWriterContext WriterCtx(&TypePrinter, MST.
getMachine());
5116 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
5128 if (V.hasName() || isa<GlobalValue>(V) ||
5129 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
5130 AsmWriterContext WriterCtx(
nullptr,
Machine, M);
5139 TypePrinting TypePrinter(MST.
getModule());
5141 TypePrinter.print(V.getType(), O);
5159 M, isa<MetadataAsValue>(
this));
5175 AsmWriterContext &WriterCtx) {
5179 auto *
N = dyn_cast<MDNode>(&MD);
5180 if (!
N || isa<DIExpression>(MD))
5188struct MDTreeAsmWriterContext :
public AsmWriterContext {
5191 using EntryTy = std::pair<unsigned, std::string>;
5201 : AsmWriterContext(TP,
ST,
M), Level(0
U), Visited({InitMD}), MainOS(
OS) {}
5203 void onWriteMetadataAsOperand(
const Metadata *MD)
override {
5204 if (!Visited.
insert(MD).second)
5213 unsigned InsertIdx = Buffer.
size() - 1;
5216 Buffer[InsertIdx].second = std::move(
SS.str());
5220 ~MDTreeAsmWriterContext() {
5221 for (
const auto &Entry : Buffer) {
5223 unsigned NumIndent =
Entry.first * 2U;
5232 bool OnlyAsOperand,
bool PrintAsTree =
false) {
5235 TypePrinting TypePrinter(M);
5237 std::unique_ptr<AsmWriterContext> WriterCtx;
5238 if (PrintAsTree && !OnlyAsOperand)
5239 WriterCtx = std::make_unique<MDTreeAsmWriterContext>(
5243 std::make_unique<AsmWriterContext>(&TypePrinter, MST.
getMachine(), M);
5247 auto *
N = dyn_cast<MDNode>(&MD);
5248 if (OnlyAsOperand || !
N || isa<DIExpression>(MD))
5272 const Module *M,
bool )
const {
5291 AssemblyWriter W(
OS, SlotTable,
this, IsForDebug);
5292 W.printModuleSummaryIndex();
5296 unsigned UB)
const {
5302 if (
I.second >= LB &&
I.second < UB)
5303 L.push_back(std::make_pair(
I.second,
I.first));
5306#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
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...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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 const Module * getModuleFromDPI(const DbgMarker *Marker)
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 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 const char * getImportTypeName(GlobalValueSummary::ImportKind IK)
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")
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.
Module.h This file contains the declarations for the Module class.
This defines the Use class.
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
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.
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.
A signed pointer, in the ptrauth sense.
This class represents a range of values.
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
This is an important base class in LLVM.
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
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.
This class represents an Operation in the Expression.
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.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on DbgMarker.
const BasicBlock * getParent() const
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
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
DbgMarker * Marker
Marker that this DbgRecord is linked into.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LocationType getType() const
void print(raw_ostream &O, bool IsForDebug=false) const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
Metadata * getRawAssignID() const
MDNode * getRawVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAddress() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
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.
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()
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_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 EnumKindString(unsigned EnumKind)
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 ...
@ RISCV_VectorCall
Calling convention used for RISC-V V-extension.
@ 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...
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1
Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ 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.
@ 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.
auto pred_end(const MachineBasicBlock *BB)
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.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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)
auto pred_begin(const MachineBasicBlock *BB)
const char * toString(DWARFSectionKind Kind)
@ 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 ImportType
This field is written by the ThinLTO indexing step to postlink combined summary.
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:...