31#include "llvm/Config/llvm-config.h"
107 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V))
108 if (
const auto *VAM = dyn_cast<ValueAsMetadata>(MAV->getMetadata()))
109 return VAM->getValue();
117 if (
const Constant *
C = dyn_cast<Constant>(V))
118 if (
C->getNumOperands() && !isa<GlobalValue>(
C))
119 for (
const Value *
Op :
C->operands())
120 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
125 unsigned ID = OM.size() + 1;
133 if (
G.hasInitializer())
134 if (!isa<GlobalValue>(
G.getInitializer()))
139 if (!isa<GlobalValue>(
A.getAliasee()))
144 if (!isa<GlobalValue>(
I.getResolver()))
149 for (
const Use &U :
F.operands())
150 if (!isa<GlobalValue>(U.get()))
155 if (
F.isDeclaration())
163 for (
const Value *
Op :
I.operands()) {
165 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
176static std::vector<unsigned>
179 using Entry = std::pair<const Use *, unsigned>;
181 for (
const Use &U : V->uses())
183 if (OM.lookup(U.getUser()))
184 List.push_back(std::make_pair(&U,
List.size()));
193 bool GetsReversed = !isa<BasicBlock>(V);
194 if (
auto *BA = dyn_cast<BlockAddress>(V))
195 ID = OM.lookup(BA->getBasicBlock());
197 const Use *LU = L.first;
198 const Use *RU = R.first;
202 auto LID = OM.lookup(LU->getUser());
203 auto RID = OM.lookup(RU->getUser());
223 return LU->getOperandNo() < RU->getOperandNo();
224 return LU->getOperandNo() > RU->getOperandNo();
232 std::vector<unsigned> Shuffle(
List.size());
233 for (
size_t I = 0, E =
List.size();
I != E; ++
I)
234 Shuffle[
I] =
List[
I].second;
241 for (
const auto &Pair : OM) {
242 const Value *V = Pair.first;
243 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
246 std::vector<unsigned> Shuffle =
252 if (
auto *
I = dyn_cast<Instruction>(V))
253 F =
I->getFunction();
254 if (
auto *
A = dyn_cast<Argument>(V))
256 if (
auto *BB = dyn_cast<BasicBlock>(V))
258 ULOM[
F][V] = std::move(Shuffle);
264 if (
const Argument *MA = dyn_cast<Argument>(V))
265 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
267 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
268 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
271 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
272 return M ? M->getParent() :
nullptr;
275 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
276 return GV->getParent();
278 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
279 for (
const User *U : MAV->users())
280 if (isa<Instruction>(U))
292 return M ? M->getParent() :
nullptr;
301 default: Out <<
"cc" << cc;
break;
324 Out <<
"aarch64_sve_vector_pcs";
327 Out <<
"aarch64_sme_preservemost_from_x0";
330 Out <<
"aarch64_sme_preservemost_from_x1";
333 Out <<
"aarch64_sme_preservemost_from_x2";
361 Out <<
"amdgpu_cs_chain";
364 Out <<
"amdgpu_cs_chain_preserve";
370 Out <<
"riscv_vector_cc";
384 assert(!
Name.empty() &&
"Cannot get empty name!");
387 bool NeedsQuotes = isdigit(
static_cast<unsigned char>(
Name[0]));
389 for (
unsigned char C :
Name) {
394 if (!isalnum(
static_cast<unsigned char>(
C)) &&
C !=
'-' &&
C !=
'.' &&
411 printEscapedString(
Name,
OS);
447 if (isa<ScalableVectorType>(Ty))
449 Out << Mask.size() <<
" x i32> ";
450 bool FirstElt =
true;
451 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
452 Out <<
"zeroinitializer";
457 for (
int Elt : Mask) {
476 TypePrinting(
const Module *M =
nullptr) : DeferredM(
M) {}
478 TypePrinting(
const TypePrinting &) =
delete;
479 TypePrinting &operator=(
const TypePrinting &) =
delete;
485 std::vector<StructType *> &getNumberedTypes();
494 void incorporateTypes();
504 std::vector<StructType *> NumberedTypes;
514std::vector<StructType *> &TypePrinting::getNumberedTypes() {
520 if (NumberedTypes.size() == Type2Number.size())
521 return NumberedTypes;
523 NumberedTypes.resize(Type2Number.size());
524 for (
const auto &
P : Type2Number) {
525 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
526 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
527 NumberedTypes[
P.second] =
P.first;
529 return NumberedTypes;
532bool TypePrinting::empty() {
534 return NamedTypes.empty() && Type2Number.empty();
537void TypePrinting::incorporateTypes() {
541 NamedTypes.run(*DeferredM,
false);
546 unsigned NextNumber = 0;
548 std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();
551 if (STy->isLiteral())
554 if (STy->getName().empty())
555 Type2Number[STy] = NextNumber++;
560 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);
653 OS <<
", " << *Inner;
655 OS <<
", " << IntParam;
706 const Function* TheFunction =
nullptr;
707 bool FunctionProcessed =
false;
708 bool ShouldInitializeAllMetadata;
713 ProcessFunctionHookFn;
728 unsigned mdnNext = 0;
736 unsigned ModulePathNext = 0;
740 unsigned GUIDNext = 0;
744 unsigned TypeIdNext = 0;
749 unsigned TypeIdCompatibleVtableNext = 0;
758 bool ShouldInitializeAllMetadata =
false);
766 bool ShouldInitializeAllMetadata =
false);
800 FunctionProcessed =
false;
839 void CreateMetadataSlot(
const MDNode *
N);
842 void CreateFunctionSlot(
const Value *V);
847 inline void CreateModulePathSlot(
StringRef Path);
850 void CreateTypeIdCompatibleVtableSlot(
StringRef Id);
854 void processModule();
859 void processFunction();
862 void processGlobalObjectMetadata(
const GlobalObject &GO);
865 void processFunctionMetadata(
const Function &
F);
871 void processDbgRecordMetadata(
const DbgRecord &DVR);
881 bool ShouldInitializeAllMetadata)
882 : ShouldCreateStorage(M),
883 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
888 if (!ShouldCreateStorage)
891 ShouldCreateStorage =
false;
893 std::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
894 Machine = MachineStorage.get();
895 if (ProcessModuleHookFn)
897 if (ProcessFunctionHookFn)
917 assert(F &&
"No function incorporated");
924 ProcessModuleHookFn = Fn;
930 ProcessFunctionHookFn = Fn;
934 if (
const Argument *FA = dyn_cast<Argument>(V))
941 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
947 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
950 if (
const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
953 if (
const Function *Func = dyn_cast<Function>(V))
960#define ST_DEBUG(X) dbgs() << X
968 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
973 : TheModule(
F ?
F->
getParent() : nullptr), TheFunction(
F),
974 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
977 : TheModule(nullptr), ShouldInitializeAllMetadata(
false), TheIndex(
Index) {}
985 if (TheFunction && !FunctionProcessed)
992 int NumSlots = processIndex();
999void SlotTracker::processModule() {
1000 ST_DEBUG(
"begin processModule!\n");
1005 CreateModuleSlot(&Var);
1006 processGlobalObjectMetadata(Var);
1007 auto Attrs = Var.getAttributes();
1008 if (Attrs.hasAttributes())
1009 CreateAttributeSetSlot(Attrs);
1014 CreateModuleSlot(&
A);
1019 CreateModuleSlot(&
I);
1024 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
1025 CreateMetadataSlot(NMD.getOperand(i));
1031 CreateModuleSlot(&
F);
1033 if (ShouldInitializeAllMetadata)
1034 processFunctionMetadata(
F);
1040 CreateAttributeSetSlot(FnAttrs);
1043 if (ProcessModuleHookFn)
1044 ProcessModuleHookFn(
this, TheModule, ShouldInitializeAllMetadata);
1050void SlotTracker::processFunction() {
1051 ST_DEBUG(
"begin processFunction!\n");
1055 if (!ShouldInitializeAllMetadata)
1056 processFunctionMetadata(*TheFunction);
1060 AE = TheFunction->
arg_end(); AI != AE; ++AI)
1062 CreateFunctionSlot(&*AI);
1064 ST_DEBUG(
"Inserting Instructions:\n");
1067 for (
auto &BB : *TheFunction) {
1069 CreateFunctionSlot(&BB);
1071 for (
auto &
I : BB) {
1072 if (!
I.getType()->isVoidTy() && !
I.hasName())
1073 CreateFunctionSlot(&
I);
1077 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1080 if (
Attrs.hasAttributes())
1081 CreateAttributeSetSlot(Attrs);
1086 if (ProcessFunctionHookFn)
1087 ProcessFunctionHookFn(
this, TheFunction, ShouldInitializeAllMetadata);
1089 FunctionProcessed =
true;
1091 ST_DEBUG(
"end processFunction!\n");
1095int SlotTracker::processIndex() {
1102 std::vector<StringRef> ModulePaths;
1104 ModulePaths.push_back(ModPath);
1105 llvm::sort(ModulePaths.begin(), ModulePaths.end());
1106 for (
auto &ModPath : ModulePaths)
1107 CreateModulePathSlot(ModPath);
1110 GUIDNext = ModulePathNext;
1112 for (
auto &GlobalList : *TheIndex)
1113 CreateGUIDSlot(GlobalList.first);
1116 TypeIdCompatibleVtableNext = GUIDNext;
1117 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1118 CreateTypeIdCompatibleVtableSlot(TId.first);
1121 TypeIdNext = TypeIdCompatibleVtableNext;
1122 for (
const auto &TID : TheIndex->typeIds())
1123 CreateTypeIdSlot(TID.second.first);
1129void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1132 for (
auto &MD : MDs)
1133 CreateMetadataSlot(MD.second);
1136void SlotTracker::processFunctionMetadata(
const Function &
F) {
1137 processGlobalObjectMetadata(
F);
1138 for (
auto &BB :
F) {
1139 for (
auto &
I : BB) {
1140 for (
const DbgRecord &DR :
I.getDbgRecordRange())
1141 processDbgRecordMetadata(DR);
1142 processInstructionMetadata(
I);
1147void SlotTracker::processDbgRecordMetadata(
const DbgRecord &DR) {
1153 if (
auto *
Empty = dyn_cast<MDNode>(DVR->getRawLocation()))
1154 CreateMetadataSlot(
Empty);
1155 CreateMetadataSlot(DVR->getRawVariable());
1156 if (DVR->isDbgAssign()) {
1157 CreateMetadataSlot(cast<MDNode>(DVR->getRawAssignID()));
1158 if (
auto *
Empty = dyn_cast<MDNode>(DVR->getRawAddress()))
1159 CreateMetadataSlot(
Empty);
1161 }
else if (
const DbgLabelRecord *DLR = dyn_cast<const DbgLabelRecord>(&DR)) {
1162 CreateMetadataSlot(DLR->getRawLabel());
1169void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1171 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
1172 if (
Function *
F = CI->getCalledFunction())
1173 if (
F->isIntrinsic())
1174 for (
auto &
Op :
I.operands())
1175 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1176 if (
MDNode *
N = dyn_cast<MDNode>(
V->getMetadata()))
1177 CreateMetadataSlot(
N);
1181 I.getAllMetadata(MDs);
1182 for (
auto &MD : MDs)
1183 CreateMetadataSlot(MD.second);
1190 ST_DEBUG(
"begin purgeFunction!\n");
1192 TheFunction =
nullptr;
1193 FunctionProcessed =
false;
1204 return MI == mMap.
end() ? -1 : (int)
MI->second;
1210 ProcessModuleHookFn = Fn;
1216 ProcessFunctionHookFn = Fn;
1229 return MI == mdnMap.
end() ? -1 : (int)
MI->second;
1234 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1240 return FI == fMap.
end() ? -1 : (int)FI->second;
1249 return AI == asMap.
end() ? -1 : (int)AI->second;
1257 auto I = ModulePathMap.
find(Path);
1258 return I == ModulePathMap.
end() ? -1 : (int)
I->second;
1267 return I == GUIDMap.
end() ? -1 : (int)
I->second;
1275 auto I = TypeIdMap.
find(Id);
1276 return I == TypeIdMap.
end() ? -1 : (int)
I->second;
1284 auto I = TypeIdCompatibleVtableMap.
find(Id);
1285 return I == TypeIdCompatibleVtableMap.
end() ? -1 : (int)
I->second;
1289void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1290 assert(V &&
"Can't insert a null Value into SlotTracker!");
1291 assert(!V->getType()->isVoidTy() &&
"Doesn't need a slot!");
1292 assert(!V->hasName() &&
"Doesn't need a slot!");
1294 unsigned DestSlot = mNext++;
1297 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1300 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1301 (isa<Function>(V) ?
'F' :
1302 (isa<GlobalAlias>(V) ?
'A' :
1303 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1307void SlotTracker::CreateFunctionSlot(
const Value *V) {
1308 assert(!V->getType()->isVoidTy() && !V->hasName() &&
"Doesn't need a slot!");
1310 unsigned DestSlot = fNext++;
1314 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1315 DestSlot <<
" [o]\n");
1319void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1320 assert(
N &&
"Can't insert a null Value into SlotTracker!");
1323 if (isa<DIExpression>(
N))
1326 unsigned DestSlot = mdnNext;
1327 if (!mdnMap.
insert(std::make_pair(
N, DestSlot)).second)
1332 for (
unsigned i = 0, e =
N->getNumOperands(); i != e; ++i)
1333 if (
const MDNode *
Op = dyn_cast_or_null<MDNode>(
N->getOperand(i)))
1334 CreateMetadataSlot(
Op);
1337void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1341 if (
I != asMap.
end())
1344 unsigned DestSlot = asNext++;
1345 asMap[AS] = DestSlot;
1349void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1350 ModulePathMap[
Path] = ModulePathNext++;
1355 GUIDMap[
GUID] = GUIDNext++;
1359void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1360 TypeIdMap[
Id] = TypeIdNext++;
1364void SlotTracker::CreateTypeIdCompatibleVtableSlot(
StringRef Id) {
1365 TypeIdCompatibleVtableMap[
Id] = TypeIdCompatibleVtableNext++;
1370struct AsmWriterContext {
1371 TypePrinting *TypePrinter =
nullptr;
1373 const Module *Context =
nullptr;
1376 : TypePrinter(TP),
Machine(
ST), Context(
M) {}
1378 static AsmWriterContext &getEmpty() {
1379 static AsmWriterContext EmptyCtx(
nullptr,
nullptr);
1385 virtual void onWriteMetadataAsOperand(
const Metadata *) {}
1387 virtual ~AsmWriterContext() =
default;
1396 AsmWriterContext &WriterCtx);
1399 AsmWriterContext &WriterCtx,
1400 bool FromValue =
false);
1403 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U))
1404 Out << FPO->getFastMathFlags();
1407 dyn_cast<OverflowingBinaryOperator>(U)) {
1408 if (OBO->hasNoUnsignedWrap())
1410 if (OBO->hasNoSignedWrap())
1413 dyn_cast<PossiblyExactOperator>(U)) {
1417 dyn_cast<PossiblyDisjointInst>(U)) {
1418 if (PDI->isDisjoint())
1421 if (
GEP->isInBounds())
1423 else if (
GEP->hasNoUnsignedSignedWrap())
1425 if (
GEP->hasNoUnsignedWrap())
1428 Out <<
" inrange(" <<
InRange->getLower() <<
", " <<
InRange->getUpper()
1431 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(U)) {
1432 if (NNI->hasNonNeg())
1434 }
else if (
const auto *TI = dyn_cast<TruncInst>(U)) {
1435 if (TI->hasNoUnsignedWrap())
1437 if (TI->hasNoSignedWrap())
1453 bool isNaN = APF.
isNaN();
1455 if (!isInf && !isNaN) {
1464 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
isDigit(StrVal[1]))) &&
1465 "[-+]?[0-9] regex does not match!");
1477 static_assert(
sizeof(double) ==
sizeof(
uint64_t),
1478 "assuming that double is 64 bits!");
1536 AsmWriterContext &WriterCtx) {
1537 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1538 Type *Ty = CI->getType();
1547 Out << (CI->getZExtValue() ?
"true" :
"false");
1549 Out << CI->getValue();
1557 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1558 Type *Ty = CFP->getType();
1574 if (isa<ConstantAggregateZero>(CV) || isa<ConstantTargetNone>(CV)) {
1575 Out <<
"zeroinitializer";
1579 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1580 Out <<
"blockaddress(";
1588 if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV)) {
1589 Out <<
"dso_local_equivalent ";
1594 if (
const auto *
NC = dyn_cast<NoCFIValue>(CV)) {
1604 unsigned NumOpsToWrite = 2;
1605 if (!CPA->getOperand(2)->isNullValue())
1607 if (!CPA->getOperand(3)->isNullValue())
1611 for (
unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {
1613 WriterCtx.TypePrinter->print(CPA->getOperand(i)->getType(), Out);
1621 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1622 Type *ETy = CA->getType()->getElementType();
1624 WriterCtx.TypePrinter->print(ETy, Out);
1627 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1629 WriterCtx.TypePrinter->print(ETy, Out);
1640 if (CA->isString()) {
1642 printEscapedString(CA->getAsString(), Out);
1647 Type *ETy = CA->getType()->getElementType();
1649 WriterCtx.TypePrinter->print(ETy, Out);
1652 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1654 WriterCtx.TypePrinter->print(ETy, Out);
1663 if (CS->getType()->isPacked())
1666 unsigned N = CS->getNumOperands();
1669 WriterCtx.TypePrinter->print(CS->getOperand(0)->getType(), Out);
1674 for (
unsigned i = 1; i <
N; i++) {
1676 WriterCtx.TypePrinter->print(CS->getOperand(i)->getType(), Out);
1685 if (CS->getType()->isPacked())
1690 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1691 auto *CVVTy = cast<FixedVectorType>(CV->
getType());
1692 Type *ETy = CVVTy->getElementType();
1694 WriterCtx.TypePrinter->print(ETy, Out);
1697 for (
unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) {
1699 WriterCtx.TypePrinter->print(ETy, Out);
1707 if (isa<ConstantPointerNull>(CV)) {
1712 if (isa<ConstantTokenNone>(CV)) {
1717 if (isa<PoisonValue>(CV)) {
1722 if (isa<UndefValue>(CV)) {
1727 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1728 Out << CE->getOpcodeName();
1733 WriterCtx.TypePrinter->print(
GEP->getSourceElementType(), Out);
1739 WriterCtx.TypePrinter->print((*OI)->getType(), Out);
1742 if (OI+1 != CE->op_end())
1748 WriterCtx.TypePrinter->print(CE->getType(), Out);
1751 if (CE->getOpcode() == Instruction::ShuffleVector)
1758 Out <<
"<placeholder or erroneous Constant>";
1762 AsmWriterContext &WriterCtx) {
1764 for (
unsigned mi = 0, me =
Node->getNumOperands(); mi != me; ++mi) {
1768 else if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1769 Value *V = MDV->getValue();
1770 WriterCtx.TypePrinter->print(V->getType(), Out);
1775 WriterCtx.onWriteMetadataAsOperand(MD);
1786struct FieldSeparator {
1790 FieldSeparator(
const char *Sep =
", ") : Sep(Sep) {}
1798 return OS <<
FS.Sep;
1801struct MDFieldPrinter {
1804 AsmWriterContext &WriterCtx;
1807 : Out(Out), WriterCtx(AsmWriterContext::getEmpty()) {}
1808 MDFieldPrinter(
raw_ostream &Out, AsmWriterContext &Ctx)
1809 : Out(Out), WriterCtx(Ctx) {}
1811 void printTag(
const DINode *
N);
1815 bool ShouldSkipEmpty =
true);
1817 bool ShouldSkipNull =
true);
1818 template <
class IntTy>
1821 bool ShouldSkipZero);
1823 std::optional<bool>
Default = std::nullopt);
1826 template <
class IntTy,
class Stringifier>
1828 bool ShouldSkipZero =
true);
1836void MDFieldPrinter::printTag(
const DINode *
N) {
1837 Out <<
FS <<
"tag: ";
1845void MDFieldPrinter::printMacinfoType(
const DIMacroNode *
N) {
1846 Out <<
FS <<
"type: ";
1851 Out <<
N->getMacinfoType();
1854void MDFieldPrinter::printChecksum(
1857 printString(
"checksum", Checksum.
Value,
false);
1861 bool ShouldSkipEmpty) {
1862 if (ShouldSkipEmpty &&
Value.empty())
1865 Out <<
FS <<
Name <<
": \"";
1866 printEscapedString(
Value, Out);
1871 AsmWriterContext &WriterCtx) {
1877 WriterCtx.onWriteMetadataAsOperand(MD);
1881 bool ShouldSkipNull) {
1882 if (ShouldSkipNull && !MD)
1885 Out <<
FS <<
Name <<
": ";
1889template <
class IntTy>
1890void MDFieldPrinter::printInt(
StringRef Name, IntTy
Int,
bool ShouldSkipZero) {
1891 if (ShouldSkipZero && !
Int)
1898 bool IsUnsigned,
bool ShouldSkipZero) {
1899 if (ShouldSkipZero &&
Int.isZero())
1902 Out <<
FS <<
Name <<
": ";
1903 Int.print(Out, !IsUnsigned);
1907 std::optional<bool>
Default) {
1910 Out <<
FS <<
Name <<
": " << (
Value ?
"true" :
"false");
1917 Out <<
FS <<
Name <<
": ";
1922 FieldSeparator FlagsFS(
" | ");
1923 for (
auto F : SplitFlags) {
1925 assert(!StringF.empty() &&
"Expected valid flag");
1926 Out << FlagsFS << StringF;
1928 if (Extra || SplitFlags.empty())
1929 Out << FlagsFS << Extra;
1936 Out <<
FS <<
Name <<
": ";
1946 FieldSeparator FlagsFS(
" | ");
1947 for (
auto F : SplitFlags) {
1949 assert(!StringF.empty() &&
"Expected valid flag");
1950 Out << FlagsFS << StringF;
1952 if (Extra || SplitFlags.empty())
1953 Out << FlagsFS << Extra;
1968template <
class IntTy,
class Stringifier>
1970 Stringifier
toString,
bool ShouldSkipZero) {
1974 Out <<
FS <<
Name <<
": ";
1983 AsmWriterContext &WriterCtx) {
1984 Out <<
"!GenericDINode(";
1985 MDFieldPrinter
Printer(Out, WriterCtx);
1987 Printer.printString(
"header",
N->getHeader());
1988 if (
N->getNumDwarfOperands()) {
1989 Out <<
Printer.FS <<
"operands: {";
1991 for (
auto &
I :
N->dwarf_operands()) {
2001 AsmWriterContext &WriterCtx) {
2002 Out <<
"!DILocation(";
2003 MDFieldPrinter
Printer(Out, WriterCtx);
2005 Printer.printInt(
"line",
DL->getLine(),
false);
2006 Printer.printInt(
"column",
DL->getColumn());
2007 Printer.printMetadata(
"scope",
DL->getRawScope(),
false);
2008 Printer.printMetadata(
"inlinedAt",
DL->getRawInlinedAt());
2009 Printer.printBool(
"isImplicitCode",
DL->isImplicitCode(),
2015 AsmWriterContext &WriterCtx) {
2016 Out <<
"!DIAssignID()";
2017 MDFieldPrinter
Printer(Out, WriterCtx);
2021 AsmWriterContext &WriterCtx) {
2022 Out <<
"!DISubrange(";
2023 MDFieldPrinter
Printer(Out, WriterCtx);
2025 auto *Count =
N->getRawCountNode();
2026 if (
auto *CE = dyn_cast_or_null<ConstantAsMetadata>(Count)) {
2027 auto *CV = cast<ConstantInt>(CE->getValue());
2028 Printer.printInt(
"count", CV->getSExtValue(),
2031 Printer.printMetadata(
"count", Count,
true);
2035 auto *LBound =
N->getRawLowerBound();
2036 if (
auto *LE = dyn_cast_or_null<ConstantAsMetadata>(LBound)) {
2037 auto *LV = cast<ConstantInt>(LE->getValue());
2038 Printer.printInt(
"lowerBound", LV->getSExtValue(),
2041 Printer.printMetadata(
"lowerBound", LBound,
true);
2043 auto *UBound =
N->getRawUpperBound();
2044 if (
auto *UE = dyn_cast_or_null<ConstantAsMetadata>(UBound)) {
2045 auto *UV = cast<ConstantInt>(UE->getValue());
2046 Printer.printInt(
"upperBound", UV->getSExtValue(),
2049 Printer.printMetadata(
"upperBound", UBound,
true);
2051 auto *Stride =
N->getRawStride();
2052 if (
auto *SE = dyn_cast_or_null<ConstantAsMetadata>(Stride)) {
2053 auto *SV = cast<ConstantInt>(SE->getValue());
2054 Printer.printInt(
"stride", SV->getSExtValue(),
false);
2056 Printer.printMetadata(
"stride", Stride,
true);
2062 AsmWriterContext &WriterCtx) {
2063 Out <<
"!DIGenericSubrange(";
2064 MDFieldPrinter
Printer(Out, WriterCtx);
2066 auto IsConstant = [&](
Metadata *Bound) ->
bool {
2067 if (
auto *BE = dyn_cast_or_null<DIExpression>(Bound)) {
2068 return BE->isConstant() &&
2075 auto GetConstant = [&](
Metadata *Bound) -> int64_t {
2076 assert(IsConstant(Bound) &&
"Expected constant");
2077 auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2078 return static_cast<int64_t
>(BE->getElement(1));
2081 auto *Count =
N->getRawCountNode();
2082 if (IsConstant(Count))
2083 Printer.printInt(
"count", GetConstant(Count),
2086 Printer.printMetadata(
"count", Count,
true);
2088 auto *LBound =
N->getRawLowerBound();
2089 if (IsConstant(LBound))
2090 Printer.printInt(
"lowerBound", GetConstant(LBound),
2093 Printer.printMetadata(
"lowerBound", LBound,
true);
2095 auto *UBound =
N->getRawUpperBound();
2096 if (IsConstant(UBound))
2097 Printer.printInt(
"upperBound", GetConstant(UBound),
2100 Printer.printMetadata(
"upperBound", UBound,
true);
2102 auto *Stride =
N->getRawStride();
2103 if (IsConstant(Stride))
2104 Printer.printInt(
"stride", GetConstant(Stride),
2107 Printer.printMetadata(
"stride", Stride,
true);
2113 AsmWriterContext &) {
2114 Out <<
"!DIEnumerator(";
2116 Printer.printString(
"name",
N->getName(),
false);
2117 Printer.printAPInt(
"value",
N->getValue(),
N->isUnsigned(),
2119 if (
N->isUnsigned())
2120 Printer.printBool(
"isUnsigned",
true);
2125 AsmWriterContext &) {
2126 Out <<
"!DIBasicType(";
2128 if (
N->getTag() != dwarf::DW_TAG_base_type)
2130 Printer.printString(
"name",
N->getName());
2131 Printer.printInt(
"size",
N->getSizeInBits());
2132 Printer.printInt(
"align",
N->getAlignInBits());
2133 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2135 Printer.printDIFlags(
"flags",
N->getFlags());
2140 AsmWriterContext &WriterCtx) {
2141 Out <<
"!DIStringType(";
2142 MDFieldPrinter
Printer(Out, WriterCtx);
2143 if (
N->getTag() != dwarf::DW_TAG_string_type)
2145 Printer.printString(
"name",
N->getName());
2146 Printer.printMetadata(
"stringLength",
N->getRawStringLength());
2147 Printer.printMetadata(
"stringLengthExpression",
N->getRawStringLengthExp());
2148 Printer.printMetadata(
"stringLocationExpression",
2149 N->getRawStringLocationExp());
2150 Printer.printInt(
"size",
N->getSizeInBits());
2151 Printer.printInt(
"align",
N->getAlignInBits());
2152 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2158 AsmWriterContext &WriterCtx) {
2159 Out <<
"!DIDerivedType(";
2160 MDFieldPrinter
Printer(Out, WriterCtx);
2162 Printer.printString(
"name",
N->getName());
2163 Printer.printMetadata(
"scope",
N->getRawScope());
2164 Printer.printMetadata(
"file",
N->getRawFile());
2165 Printer.printInt(
"line",
N->getLine());
2166 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2168 Printer.printInt(
"size",
N->getSizeInBits());
2169 Printer.printInt(
"align",
N->getAlignInBits());
2170 Printer.printInt(
"offset",
N->getOffsetInBits());
2171 Printer.printDIFlags(
"flags",
N->getFlags());
2172 Printer.printMetadata(
"extraData",
N->getRawExtraData());
2173 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2174 Printer.printInt(
"dwarfAddressSpace", *DWARFAddressSpace,
2176 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2177 if (
auto PtrAuthData =
N->getPtrAuthData()) {
2178 Printer.printInt(
"ptrAuthKey", PtrAuthData->key());
2179 Printer.printBool(
"ptrAuthIsAddressDiscriminated",
2180 PtrAuthData->isAddressDiscriminated());
2181 Printer.printInt(
"ptrAuthExtraDiscriminator",
2182 PtrAuthData->extraDiscriminator());
2183 Printer.printBool(
"ptrAuthIsaPointer", PtrAuthData->isaPointer());
2184 Printer.printBool(
"ptrAuthAuthenticatesNullValues",
2185 PtrAuthData->authenticatesNullValues());
2191 AsmWriterContext &WriterCtx) {
2192 Out <<
"!DICompositeType(";
2193 MDFieldPrinter
Printer(Out, WriterCtx);
2195 Printer.printString(
"name",
N->getName());
2196 Printer.printMetadata(
"scope",
N->getRawScope());
2197 Printer.printMetadata(
"file",
N->getRawFile());
2198 Printer.printInt(
"line",
N->getLine());
2199 Printer.printMetadata(
"baseType",
N->getRawBaseType());
2200 Printer.printInt(
"size",
N->getSizeInBits());
2201 Printer.printInt(
"align",
N->getAlignInBits());
2202 Printer.printInt(
"offset",
N->getOffsetInBits());
2203 Printer.printDIFlags(
"flags",
N->getFlags());
2204 Printer.printMetadata(
"elements",
N->getRawElements());
2205 Printer.printDwarfEnum(
"runtimeLang",
N->getRuntimeLang(),
2207 Printer.printMetadata(
"vtableHolder",
N->getRawVTableHolder());
2208 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2209 Printer.printString(
"identifier",
N->getIdentifier());
2210 Printer.printMetadata(
"discriminator",
N->getRawDiscriminator());
2211 Printer.printMetadata(
"dataLocation",
N->getRawDataLocation());
2212 Printer.printMetadata(
"associated",
N->getRawAssociated());
2213 Printer.printMetadata(
"allocated",
N->getRawAllocated());
2214 if (
auto *RankConst =
N->getRankConst())
2215 Printer.printInt(
"rank", RankConst->getSExtValue(),
2218 Printer.printMetadata(
"rank",
N->getRawRank(),
true);
2219 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2224 AsmWriterContext &WriterCtx) {
2225 Out <<
"!DISubroutineType(";
2226 MDFieldPrinter
Printer(Out, WriterCtx);
2227 Printer.printDIFlags(
"flags",
N->getFlags());
2229 Printer.printMetadata(
"types",
N->getRawTypeArray(),
2237 Printer.printString(
"filename",
N->getFilename(),
2239 Printer.printString(
"directory",
N->getDirectory(),
2242 if (
N->getChecksum())
2243 Printer.printChecksum(*
N->getChecksum());
2250 AsmWriterContext &WriterCtx) {
2251 Out <<
"!DICompileUnit(";
2252 MDFieldPrinter
Printer(Out, WriterCtx);
2253 Printer.printDwarfEnum(
"language",
N->getSourceLanguage(),
2255 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2256 Printer.printString(
"producer",
N->getProducer());
2257 Printer.printBool(
"isOptimized",
N->isOptimized());
2258 Printer.printString(
"flags",
N->getFlags());
2259 Printer.printInt(
"runtimeVersion",
N->getRuntimeVersion(),
2261 Printer.printString(
"splitDebugFilename",
N->getSplitDebugFilename());
2262 Printer.printEmissionKind(
"emissionKind",
N->getEmissionKind());
2263 Printer.printMetadata(
"enums",
N->getRawEnumTypes());
2264 Printer.printMetadata(
"retainedTypes",
N->getRawRetainedTypes());
2265 Printer.printMetadata(
"globals",
N->getRawGlobalVariables());
2266 Printer.printMetadata(
"imports",
N->getRawImportedEntities());
2267 Printer.printMetadata(
"macros",
N->getRawMacros());
2268 Printer.printInt(
"dwoId",
N->getDWOId());
2269 Printer.printBool(
"splitDebugInlining",
N->getSplitDebugInlining(),
true);
2270 Printer.printBool(
"debugInfoForProfiling",
N->getDebugInfoForProfiling(),
2272 Printer.printNameTableKind(
"nameTableKind",
N->getNameTableKind());
2273 Printer.printBool(
"rangesBaseAddress",
N->getRangesBaseAddress(),
false);
2274 Printer.printString(
"sysroot",
N->getSysRoot());
2275 Printer.printString(
"sdk",
N->getSDK());
2280 AsmWriterContext &WriterCtx) {
2281 Out <<
"!DISubprogram(";
2282 MDFieldPrinter
Printer(Out, WriterCtx);
2283 Printer.printString(
"name",
N->getName());
2284 Printer.printString(
"linkageName",
N->getLinkageName());
2285 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2286 Printer.printMetadata(
"file",
N->getRawFile());
2287 Printer.printInt(
"line",
N->getLine());
2288 Printer.printMetadata(
"type",
N->getRawType());
2289 Printer.printInt(
"scopeLine",
N->getScopeLine());
2290 Printer.printMetadata(
"containingType",
N->getRawContainingType());
2291 if (
N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
2292 N->getVirtualIndex() != 0)
2293 Printer.printInt(
"virtualIndex",
N->getVirtualIndex(),
false);
2294 Printer.printInt(
"thisAdjustment",
N->getThisAdjustment());
2295 Printer.printDIFlags(
"flags",
N->getFlags());
2296 Printer.printDISPFlags(
"spFlags",
N->getSPFlags());
2297 Printer.printMetadata(
"unit",
N->getRawUnit());
2298 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2299 Printer.printMetadata(
"declaration",
N->getRawDeclaration());
2300 Printer.printMetadata(
"retainedNodes",
N->getRawRetainedNodes());
2301 Printer.printMetadata(
"thrownTypes",
N->getRawThrownTypes());
2302 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2303 Printer.printString(
"targetFuncName",
N->getTargetFuncName());
2308 AsmWriterContext &WriterCtx) {
2309 Out <<
"!DILexicalBlock(";
2310 MDFieldPrinter
Printer(Out, WriterCtx);
2311 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2312 Printer.printMetadata(
"file",
N->getRawFile());
2313 Printer.printInt(
"line",
N->getLine());
2314 Printer.printInt(
"column",
N->getColumn());
2320 AsmWriterContext &WriterCtx) {
2321 Out <<
"!DILexicalBlockFile(";
2322 MDFieldPrinter
Printer(Out, WriterCtx);
2323 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2324 Printer.printMetadata(
"file",
N->getRawFile());
2325 Printer.printInt(
"discriminator",
N->getDiscriminator(),
2331 AsmWriterContext &WriterCtx) {
2332 Out <<
"!DINamespace(";
2333 MDFieldPrinter
Printer(Out, WriterCtx);
2334 Printer.printString(
"name",
N->getName());
2335 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2336 Printer.printBool(
"exportSymbols",
N->getExportSymbols(),
false);
2341 AsmWriterContext &WriterCtx) {
2342 Out <<
"!DICommonBlock(";
2343 MDFieldPrinter
Printer(Out, WriterCtx);
2344 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2345 Printer.printMetadata(
"declaration",
N->getRawDecl(),
false);
2346 Printer.printString(
"name",
N->getName());
2347 Printer.printMetadata(
"file",
N->getRawFile());
2348 Printer.printInt(
"line",
N->getLineNo());
2353 AsmWriterContext &WriterCtx) {
2355 MDFieldPrinter
Printer(Out, WriterCtx);
2357 Printer.printInt(
"line",
N->getLine());
2358 Printer.printString(
"name",
N->getName());
2359 Printer.printString(
"value",
N->getValue());
2364 AsmWriterContext &WriterCtx) {
2365 Out <<
"!DIMacroFile(";
2366 MDFieldPrinter
Printer(Out, WriterCtx);
2367 Printer.printInt(
"line",
N->getLine());
2368 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2369 Printer.printMetadata(
"nodes",
N->getRawElements());
2374 AsmWriterContext &WriterCtx) {
2375 Out <<
"!DIModule(";
2376 MDFieldPrinter
Printer(Out, WriterCtx);
2377 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2378 Printer.printString(
"name",
N->getName());
2379 Printer.printString(
"configMacros",
N->getConfigurationMacros());
2380 Printer.printString(
"includePath",
N->getIncludePath());
2381 Printer.printString(
"apinotes",
N->getAPINotesFile());
2382 Printer.printMetadata(
"file",
N->getRawFile());
2383 Printer.printInt(
"line",
N->getLineNo());
2384 Printer.printBool(
"isDecl",
N->getIsDecl(),
false);
2390 AsmWriterContext &WriterCtx) {
2391 Out <<
"!DITemplateTypeParameter(";
2392 MDFieldPrinter
Printer(Out, WriterCtx);
2393 Printer.printString(
"name",
N->getName());
2394 Printer.printMetadata(
"type",
N->getRawType(),
false);
2395 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2401 AsmWriterContext &WriterCtx) {
2402 Out <<
"!DITemplateValueParameter(";
2403 MDFieldPrinter
Printer(Out, WriterCtx);
2404 if (
N->getTag() != dwarf::DW_TAG_template_value_parameter)
2406 Printer.printString(
"name",
N->getName());
2407 Printer.printMetadata(
"type",
N->getRawType());
2408 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2409 Printer.printMetadata(
"value",
N->getValue(),
false);
2414 AsmWriterContext &WriterCtx) {
2415 Out <<
"!DIGlobalVariable(";
2416 MDFieldPrinter
Printer(Out, WriterCtx);
2417 Printer.printString(
"name",
N->getName());
2418 Printer.printString(
"linkageName",
N->getLinkageName());
2419 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2420 Printer.printMetadata(
"file",
N->getRawFile());
2421 Printer.printInt(
"line",
N->getLine());
2422 Printer.printMetadata(
"type",
N->getRawType());
2423 Printer.printBool(
"isLocal",
N->isLocalToUnit());
2424 Printer.printBool(
"isDefinition",
N->isDefinition());
2425 Printer.printMetadata(
"declaration",
N->getRawStaticDataMemberDeclaration());
2426 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2427 Printer.printInt(
"align",
N->getAlignInBits());
2428 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2433 AsmWriterContext &WriterCtx) {
2434 Out <<
"!DILocalVariable(";
2435 MDFieldPrinter
Printer(Out, WriterCtx);
2436 Printer.printString(
"name",
N->getName());
2437 Printer.printInt(
"arg",
N->getArg());
2438 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2439 Printer.printMetadata(
"file",
N->getRawFile());
2440 Printer.printInt(
"line",
N->getLine());
2441 Printer.printMetadata(
"type",
N->getRawType());
2442 Printer.printDIFlags(
"flags",
N->getFlags());
2443 Printer.printInt(
"align",
N->getAlignInBits());
2444 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2449 AsmWriterContext &WriterCtx) {
2451 MDFieldPrinter
Printer(Out, WriterCtx);
2452 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2453 Printer.printString(
"name",
N->getName());
2454 Printer.printMetadata(
"file",
N->getRawFile());
2455 Printer.printInt(
"line",
N->getLine());
2460 AsmWriterContext &WriterCtx) {
2461 Out <<
"!DIExpression(";
2466 assert(!OpStr.empty() &&
"Expected valid opcode");
2470 Out << FS <<
Op.getArg(0);
2473 for (
unsigned A = 0, AE =
Op.getNumArgs();
A != AE; ++
A)
2474 Out << FS <<
Op.getArg(
A);
2478 for (
const auto &
I :
N->getElements())
2485 AsmWriterContext &WriterCtx,
2486 bool FromValue =
false) {
2488 "Unexpected DIArgList metadata outside of value argument");
2489 Out <<
"!DIArgList(";
2491 MDFieldPrinter
Printer(Out, WriterCtx);
2501 AsmWriterContext &WriterCtx) {
2502 Out <<
"!DIGlobalVariableExpression(";
2503 MDFieldPrinter
Printer(Out, WriterCtx);
2504 Printer.printMetadata(
"var",
N->getVariable());
2505 Printer.printMetadata(
"expr",
N->getExpression());
2510 AsmWriterContext &WriterCtx) {
2511 Out <<
"!DIObjCProperty(";
2512 MDFieldPrinter
Printer(Out, WriterCtx);
2513 Printer.printString(
"name",
N->getName());
2514 Printer.printMetadata(
"file",
N->getRawFile());
2515 Printer.printInt(
"line",
N->getLine());
2516 Printer.printString(
"setter",
N->getSetterName());
2517 Printer.printString(
"getter",
N->getGetterName());
2518 Printer.printInt(
"attributes",
N->getAttributes());
2519 Printer.printMetadata(
"type",
N->getRawType());
2524 AsmWriterContext &WriterCtx) {
2525 Out <<
"!DIImportedEntity(";
2526 MDFieldPrinter
Printer(Out, WriterCtx);
2528 Printer.printString(
"name",
N->getName());
2529 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2530 Printer.printMetadata(
"entity",
N->getRawEntity());
2531 Printer.printMetadata(
"file",
N->getRawFile());
2532 Printer.printInt(
"line",
N->getLine());
2533 Printer.printMetadata(
"elements",
N->getRawElements());
2538 AsmWriterContext &Ctx) {
2539 if (
Node->isDistinct())
2541 else if (
Node->isTemporary())
2542 Out <<
"<temporary!> ";
2544 switch (
Node->getMetadataID()) {
2547#define HANDLE_MDNODE_LEAF(CLASS) \
2548 case Metadata::CLASS##Kind: \
2549 write##CLASS(Out, cast<CLASS>(Node), Ctx); \
2551#include "llvm/IR/Metadata.def"
2558 AsmWriterContext &WriterCtx) {
2564 const Constant *CV = dyn_cast<Constant>(V);
2565 if (CV && !isa<GlobalValue>(CV)) {
2566 assert(WriterCtx.TypePrinter &&
"Constants require TypePrinting!");
2571 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2573 if (IA->hasSideEffects())
2574 Out <<
"sideeffect ";
2575 if (IA->isAlignStack())
2576 Out <<
"alignstack ";
2579 Out <<
"inteldialect ";
2583 printEscapedString(IA->getAsmString(), Out);
2585 printEscapedString(IA->getConstraintString(), Out);
2590 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2598 auto *
Machine = WriterCtx.Machine;
2601 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2602 Slot =
Machine->getGlobalSlot(GV);
2605 Slot =
Machine->getLocalSlot(V);
2612 Slot =
Machine->getLocalSlot(V);
2618 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2619 Slot =
Machine->getGlobalSlot(GV);
2622 Slot =
Machine->getLocalSlot(V);
2631 Out << Prefix << Slot;
2637 AsmWriterContext &WriterCtx,
2641 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2645 if (
const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) {
2650 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2651 std::unique_ptr<SlotTracker> MachineStorage;
2653 if (!WriterCtx.Machine) {
2654 MachineStorage = std::make_unique<SlotTracker>(WriterCtx.Context);
2655 WriterCtx.Machine = MachineStorage.get();
2657 int Slot = WriterCtx.Machine->getMetadataSlot(
N);
2659 if (
const DILocation *Loc = dyn_cast<DILocation>(
N)) {
2665 Out <<
"<" <<
N <<
">";
2671 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2673 printEscapedString(MDS->getString(), Out);
2678 auto *V = cast<ValueAsMetadata>(MD);
2679 assert(WriterCtx.TypePrinter &&
"TypePrinter required for metadata values");
2680 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2681 "Unexpected function-local metadata outside of value argument");
2683 WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);
2690class AssemblyWriter {
2692 const Module *TheModule =
nullptr;
2694 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2696 TypePrinting TypePrinter;
2700 bool ShouldPreserveUseListOrder;
2711 bool ShouldPreserveUseListOrder =
false);
2716 AsmWriterContext getContext() {
2717 return AsmWriterContext(&TypePrinter, &
Machine, TheModule);
2720 void printMDNodeBody(
const MDNode *MD);
2723 void printModule(
const Module *M);
2725 void writeOperand(
const Value *
Op,
bool PrintType);
2727 void writeOperandBundles(
const CallBase *Call);
2733 void writeAtomicCmpXchg(
const LLVMContext &Context,
2738 void writeAllMDNodes();
2739 void writeMDNode(
unsigned Slot,
const MDNode *
Node);
2740 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
2741 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
2742 void writeAllAttributeGroups();
2744 void printTypeIdentities();
2748 void printComdat(
const Comdat *
C);
2754 void printDbgMarker(
const DbgMarker &DPI);
2757 void printDbgRecord(
const DbgRecord &DR);
2758 void printDbgRecordLine(
const DbgRecord &DR);
2760 void printUseListOrder(
const Value *V,
const std::vector<unsigned> &Shuffle);
2763 void printModuleSummaryIndex();
2764 void printSummaryInfo(
unsigned Slot,
const ValueInfo &VI);
2772 void printArgs(
const std::vector<uint64_t> &Args);
2777 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> &VCallList,
2780 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> &VCallList,
2785 void printMetadataAttachments(
2791 void printInfoComment(
const Value &V);
2802 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2803 : Out(
o), TheModule(
M),
Machine(Mac), TypePrinter(
M), AnnotationWriter(AAW),
2804 IsForDebug(IsForDebug),
2805 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2808 for (
const GlobalObject &GO : TheModule->global_objects())
2815 : Out(
o), TheIndex(
Index),
Machine(Mac), TypePrinter(nullptr),
2816 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2818void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2820 Out <<
"<null operand!>";
2824 TypePrinter.print(Operand->
getType(), Out);
2827 auto WriterCtx = getContext();
2831void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2841 Out <<
" syncscope(\"";
2842 printEscapedString(SSNs[SSID], Out);
2849void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2852 if (Ordering == AtomicOrdering::NotAtomic)
2855 writeSyncScope(Context, SSID);
2859void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2863 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
2864 FailureOrdering != AtomicOrdering::NotAtomic);
2866 writeSyncScope(Context, SSID);
2871void AssemblyWriter::writeParamOperand(
const Value *Operand,
2874 Out <<
"<null operand!>";
2879 TypePrinter.print(Operand->
getType(), Out);
2881 if (
Attrs.hasAttributes()) {
2883 writeAttributeSet(Attrs);
2887 auto WriterCtx = getContext();
2891void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
2892 if (!
Call->hasOperandBundles())
2897 bool FirstBundle =
true;
2898 for (
unsigned i = 0, e =
Call->getNumOperandBundles(); i != e; ++i) {
2903 FirstBundle =
false;
2911 bool FirstInput =
true;
2912 auto WriterCtx = getContext();
2913 for (
const auto &Input : BU.
Inputs) {
2918 if (Input ==
nullptr)
2919 Out <<
"<null operand bundle!>";
2921 TypePrinter.print(Input->getType(), Out);
2933void AssemblyWriter::printModule(
const Module *M) {
2936 if (ShouldPreserveUseListOrder)
2939 if (!
M->getModuleIdentifier().empty() &&
2942 M->getModuleIdentifier().find(
'\n') == std::string::npos)
2943 Out <<
"; ModuleID = '" <<
M->getModuleIdentifier() <<
"'\n";
2945 if (!
M->getSourceFileName().empty()) {
2946 Out <<
"source_filename = \"";
2947 printEscapedString(
M->getSourceFileName(), Out);
2951 const std::string &
DL =
M->getDataLayoutStr();
2953 Out <<
"target datalayout = \"" <<
DL <<
"\"\n";
2954 if (!
M->getTargetTriple().empty())
2955 Out <<
"target triple = \"" <<
M->getTargetTriple() <<
"\"\n";
2957 if (!
M->getModuleInlineAsm().empty()) {
2964 std::tie(Front, Asm) =
Asm.split(
'\n');
2968 Out <<
"module asm \"";
2969 printEscapedString(Front, Out);
2971 }
while (!
Asm.empty());
2974 printTypeIdentities();
2977 if (!Comdats.empty())
2979 for (
const Comdat *
C : Comdats) {
2981 if (
C != Comdats.back())
2986 if (!
M->global_empty()) Out <<
'\n';
2988 printGlobal(&GV); Out <<
'\n';
2992 if (!
M->alias_empty()) Out <<
"\n";
2997 if (!
M->ifunc_empty()) Out <<
"\n";
3008 printUseLists(
nullptr);
3013 writeAllAttributeGroups();
3017 if (!
M->named_metadata_empty()) Out <<
'\n';
3020 printNamedMDNode(&
Node);
3029void AssemblyWriter::printModuleSummaryIndex() {
3031 int NumSlots =
Machine.initializeIndexIfNeeded();
3037 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
3038 std::string RegularLTOModuleName =
3040 moduleVec.resize(TheIndex->modulePaths().size());
3041 for (
auto &[ModPath, ModHash] : TheIndex->modulePaths())
3042 moduleVec[
Machine.getModulePathSlot(ModPath)] = std::make_pair(
3045 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
3048 for (
auto &ModPair : moduleVec) {
3049 Out <<
"^" << i++ <<
" = module: (";
3051 printEscapedString(ModPair.first, Out);
3052 Out <<
"\", hash: (";
3054 for (
auto Hash : ModPair.second)
3061 for (
auto &GlobalList : *TheIndex) {
3062 auto GUID = GlobalList.first;
3063 for (
auto &Summary : GlobalList.second.SummaryList)
3068 for (
auto &GlobalList : *TheIndex) {
3069 auto GUID = GlobalList.first;
3070 auto VI = TheIndex->getValueInfo(GlobalList);
3071 printSummaryInfo(
Machine.getGUIDSlot(GUID), VI);
3075 for (
const auto &TID : TheIndex->typeIds()) {
3076 Out <<
"^" <<
Machine.getTypeIdSlot(TID.second.first)
3077 <<
" = typeid: (name: \"" << TID.second.first <<
"\"";
3078 printTypeIdSummary(TID.second.second);
3079 Out <<
") ; guid = " << TID.first <<
"\n";
3083 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
3085 Out <<
"^" <<
Machine.getTypeIdCompatibleVtableSlot(TId.first)
3086 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
3087 printTypeIdCompatibleVtableSummary(TId.second);
3088 Out <<
") ; guid = " <<
GUID <<
"\n";
3092 if (TheIndex->getFlags()) {
3093 Out <<
"^" << NumSlots <<
" = flags: " << TheIndex->getFlags() <<
"\n";
3097 Out <<
"^" << NumSlots <<
" = blockcount: " << TheIndex->getBlockCount()
3107 return "singleImpl";
3109 return "branchFunnel";
3120 return "uniformRetVal";
3122 return "uniqueRetVal";
3124 return "virtualConstProp";
3154 Out <<
", alignLog2: " << TTRes.
AlignLog2;
3156 Out <<
", sizeM1: " << TTRes.
SizeM1;
3166void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
3167 Out <<
", summary: (";
3168 printTypeTestResolution(TIS.
TTRes);
3169 if (!TIS.
WPDRes.empty()) {
3170 Out <<
", wpdResolutions: (";
3172 for (
auto &WPDRes : TIS.
WPDRes) {
3174 Out <<
"(offset: " << WPDRes.first <<
", ";
3175 printWPDRes(WPDRes.second);
3183void AssemblyWriter::printTypeIdCompatibleVtableSummary(
3185 Out <<
", summary: (";
3187 for (
auto &
P : TI) {
3189 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
3190 Out <<
"^" <<
Machine.getGUIDSlot(
P.VTableVI.getGUID());
3196void AssemblyWriter::printArgs(
const std::vector<uint64_t> &Args) {
3199 for (
auto arg : Args) {
3207 Out <<
"wpdRes: (kind: ";
3214 Out <<
", resByArg: (";
3216 for (
auto &ResByArg : WPDRes.
ResByArg) {
3218 printArgs(ResByArg.first);
3219 Out <<
", byArg: (kind: ";
3221 if (ResByArg.second.TheKind ==
3223 ResByArg.second.TheKind ==
3225 Out <<
", info: " << ResByArg.second.Info;
3229 if (ResByArg.second.Byte || ResByArg.second.Bit)
3230 Out <<
", byte: " << ResByArg.second.Byte
3231 <<
", bit: " << ResByArg.second.Bit;
3252void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
3253 Out <<
", aliasee: ";
3264 auto VTableFuncs =
GS->vTableFuncs();
3265 Out <<
", varFlags: (readonly: " <<
GS->VarFlags.MaybeReadOnly <<
", "
3266 <<
"writeonly: " <<
GS->VarFlags.MaybeWriteOnly <<
", "
3267 <<
"constant: " <<
GS->VarFlags.Constant;
3268 if (!VTableFuncs.empty())
3270 <<
"vcall_visibility: " <<
GS->VarFlags.VCallVisibility;
3273 if (!VTableFuncs.empty()) {
3274 Out <<
", vTableFuncs: (";
3276 for (
auto &
P : VTableFuncs) {
3278 Out <<
"(virtFunc: ^" <<
Machine.getGUIDSlot(
P.FuncVI.getGUID())
3279 <<
", offset: " <<
P.VTableOffset;
3297 return "linkonce_odr";
3307 return "extern_weak";
3309 return "available_externally";
3338 return "definition";
3340 return "declaration";
3346 Out <<
", insts: " <<
FS->instCount();
3347 if (
FS->fflags().anyFlagSet())
3348 Out <<
", " <<
FS->fflags();
3350 if (!
FS->calls().empty()) {
3351 Out <<
", calls: (";
3353 for (
auto &Call :
FS->calls()) {
3355 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.first.getGUID());
3356 if (
Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)
3358 else if (
Call.second.RelBlockFreq)
3359 Out <<
", relbf: " <<
Call.second.RelBlockFreq;
3362 if (
Call.second.HasTailCall)
3369 if (
const auto *TIdInfo =
FS->getTypeIdInfo())
3370 printTypeIdInfo(*TIdInfo);
3374 auto AllocTypeName = [](uint8_t
Type) ->
const char * {
3376 case (uint8_t)AllocationType::None:
3378 case (uint8_t)AllocationType::NotCold:
3380 case (uint8_t)AllocationType::Cold:
3382 case (uint8_t)AllocationType::Hot:
3388 if (!
FS->allocs().empty()) {
3389 Out <<
", allocs: (";
3391 for (
auto &AI :
FS->allocs()) {
3393 Out <<
"(versions: (";
3395 for (
auto V : AI.Versions) {
3397 Out << AllocTypeName(V);
3399 Out <<
"), memProf: (";
3400 FieldSeparator MIBFS;
3401 for (
auto &MIB : AI.MIBs) {
3403 Out <<
"(type: " << AllocTypeName((uint8_t)MIB.AllocType);
3404 Out <<
", stackIds: (";
3405 FieldSeparator SIDFS;
3406 for (
auto Id : MIB.StackIdIndices) {
3408 Out << TheIndex->getStackIdAtIndex(Id);
3417 if (!
FS->callsites().empty()) {
3418 Out <<
", callsites: (";
3419 FieldSeparator SNFS;
3420 for (
auto &CI :
FS->callsites()) {
3423 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(CI.Callee.getGUID());
3425 Out <<
"(callee: null";
3426 Out <<
", clones: (";
3428 for (
auto V : CI.Clones) {
3432 Out <<
"), stackIds: (";
3433 FieldSeparator SIDFS;
3434 for (
auto Id : CI.StackIdIndices) {
3436 Out << TheIndex->getStackIdAtIndex(Id);
3447 if (!
FS->paramAccesses().empty()) {
3448 Out <<
", params: (";
3450 for (
auto &PS :
FS->paramAccesses()) {
3452 Out <<
"(param: " << PS.ParamNo;
3453 Out <<
", offset: ";
3455 if (!PS.Calls.empty()) {
3456 Out <<
", calls: (";
3458 for (
auto &Call : PS.Calls) {
3460 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.Callee.getGUID());
3461 Out <<
", param: " <<
Call.ParamNo;
3462 Out <<
", offset: ";
3463 PrintRange(
Call.Offsets);
3474void AssemblyWriter::printTypeIdInfo(
3476 Out <<
", typeIdInfo: (";
3477 FieldSeparator TIDFS;
3480 Out <<
"typeTests: (";
3483 auto TidIter = TheIndex->typeIds().equal_range(GUID);
3484 if (TidIter.first == TidIter.second) {
3490 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3492 auto Slot =
Machine.getTypeIdSlot(It->second.first);
3510 "typeTestAssumeConstVCalls");
3515 "typeCheckedLoadConstVCalls");
3521 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
3522 if (TidIter.first == TidIter.second) {
3523 Out <<
"vFuncId: (";
3524 Out <<
"guid: " << VFId.
GUID;
3525 Out <<
", offset: " << VFId.
Offset;
3531 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3533 Out <<
"vFuncId: (";
3534 auto Slot =
Machine.getTypeIdSlot(It->second.first);
3537 Out <<
", offset: " << VFId.
Offset;
3542void AssemblyWriter::printNonConstVCalls(
3543 const std::vector<FunctionSummary::VFuncId> &VCallList,
const char *
Tag) {
3544 Out <<
Tag <<
": (";
3546 for (
auto &VFuncId : VCallList) {
3548 printVFuncId(VFuncId);
3553void AssemblyWriter::printConstVCalls(
3554 const std::vector<FunctionSummary::ConstVCall> &VCallList,
3556 Out <<
Tag <<
": (";
3558 for (
auto &ConstVCall : VCallList) {
3561 printVFuncId(ConstVCall.VFunc);
3562 if (!ConstVCall.Args.empty()) {
3564 printArgs(ConstVCall.Args);
3575 Out <<
"(module: ^" <<
Machine.getModulePathSlot(
Summary.modulePath())
3578 Out <<
", visibility: "
3581 Out <<
", live: " << GVFlags.
Live;
3582 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3584 Out <<
", importType: "
3589 printAliasSummary(cast<AliasSummary>(&Summary));
3591 printFunctionSummary(cast<FunctionSummary>(&Summary));
3593 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3595 auto RefList =
Summary.refs();
3596 if (!RefList.empty()) {
3599 for (
auto &
Ref : RefList) {
3601 if (
Ref.isReadOnly())
3603 else if (
Ref.isWriteOnly())
3604 Out <<
"writeonly ";
3605 Out <<
"^" <<
Machine.getGUIDSlot(
Ref.getGUID());
3613void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &VI) {
3614 Out <<
"^" <<
Slot <<
" = gv: (";
3615 if (!
VI.name().empty())
3616 Out <<
"name: \"" <<
VI.name() <<
"\"";
3618 Out <<
"guid: " <<
VI.getGUID();
3619 if (!
VI.getSummaryList().empty()) {
3620 Out <<
", summaries: (";
3622 for (
auto &Summary :
VI.getSummaryList()) {
3624 printSummary(*Summary);
3629 if (!
VI.name().empty())
3630 Out <<
" ; guid = " <<
VI.getGUID();
3637 Out <<
"<empty name> ";
3639 unsigned char FirstC =
static_cast<unsigned char>(
Name[0]);
3640 if (isalpha(FirstC) || FirstC ==
'-' || FirstC ==
'$' || FirstC ==
'.' ||
3644 Out <<
'\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);
3645 for (
unsigned i = 1, e =
Name.size(); i != e; ++i) {
3646 unsigned char C =
Name[i];
3647 if (isalnum(
C) ||
C ==
'-' ||
C ==
'$' ||
C ==
'.' ||
C ==
'_')
3650 Out <<
'\\' << hexdigit(
C >> 4) << hexdigit(
C & 0x0F);
3655void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3666 if (
auto *Expr = dyn_cast<DIExpression>(
Op)) {
3692 Out <<
"dso_local ";
3707 case GlobalVariable::NotThreadLocal:
3709 case GlobalVariable::GeneralDynamicTLSModel:
3710 Out <<
"thread_local ";
3712 case GlobalVariable::LocalDynamicTLSModel:
3713 Out <<
"thread_local(localdynamic) ";
3715 case GlobalVariable::InitialExecTLSModel:
3716 Out <<
"thread_local(initialexec) ";
3718 case GlobalVariable::LocalExecTLSModel:
3719 Out <<
"thread_local(localexec) ";
3726 case GlobalVariable::UnnamedAddr::None:
3728 case GlobalVariable::UnnamedAddr::Local:
3729 return "local_unnamed_addr";
3730 case GlobalVariable::UnnamedAddr::Global:
3731 return "unnamed_addr";
3742 if (isa<GlobalVariable>(GO))
3756 Out <<
"; Materializable\n";
3777 Out << (GV->
isConstant() ?
"constant " :
"global ");
3786 Out <<
", section \"";
3791 Out <<
", partition \"";
3796 Out <<
", code_model \"";
3821 Out <<
", no_sanitize_address";
3823 Out <<
", no_sanitize_hwaddress";
3825 Out <<
", sanitize_memtag";
3827 Out <<
", sanitize_address_dyninit";
3832 Out <<
", align " <<
A->value();
3836 printMetadataAttachments(MDs,
", ");
3839 if (
Attrs.hasAttributes())
3840 Out <<
" #" <<
Machine.getAttributeGroupSlot(Attrs);
3842 printInfoComment(*GV);
3845void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
3847 Out <<
"; Materializable\n";
3868 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
3870 TypePrinter.print(GA->
getType(), Out);
3871 Out <<
" <<NULL ALIASEE>>";
3875 Out <<
", partition \"";
3880 printInfoComment(*GA);
3884void AssemblyWriter::printIFunc(
const GlobalIFunc *GI) {
3886 Out <<
"; Materializable\n";
3904 TypePrinter.print(GI->
getType(), Out);
3905 Out <<
" <<NULL RESOLVER>>";
3909 Out <<
", partition \"";
3914 printInfoComment(*GI);
3918void AssemblyWriter::printComdat(
const Comdat *
C) {
3922void AssemblyWriter::printTypeIdentities() {
3923 if (TypePrinter.empty())
3929 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3930 for (
unsigned I = 0, E = NumberedTypes.size();
I != E; ++
I) {
3931 Out <<
'%' <<
I <<
" = type ";
3935 TypePrinter.printStructBody(NumberedTypes[
I], Out);
3939 auto &NamedTypes = TypePrinter.getNamedTypes();
3946 TypePrinter.printStructBody(NamedType, Out);
3952void AssemblyWriter::printFunction(
const Function *
F) {
3953 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(
F, Out);
3955 if (
F->isMaterializable())
3956 Out <<
"; Materializable\n";
3959 if (
Attrs.hasFnAttrs()) {
3961 std::string AttrStr;
3964 if (!Attr.isStringAttribute()) {
3965 if (!AttrStr.empty()) AttrStr +=
' ';
3966 AttrStr += Attr.getAsString();
3970 if (!AttrStr.empty())
3971 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
3976 if (
F->isDeclaration()) {
3979 F->getAllMetadata(MDs);
3980 printMetadataAttachments(MDs,
" ");
3997 if (
Attrs.hasRetAttrs())
3999 TypePrinter.print(
F->getReturnType(), Out);
4000 AsmWriterContext WriterCtx(&TypePrinter, &
Machine,
F->getParent());
4006 if (
F->isDeclaration() && !IsForDebug) {
4008 for (
unsigned I = 0, E = FT->getNumParams();
I != E; ++
I) {
4013 TypePrinter.print(FT->getParamType(
I), Out);
4018 writeAttributeSet(ArgAttrs);
4025 if (Arg.getArgNo() != 0)
4027 printArgument(&Arg,
Attrs.getParamAttrs(Arg.getArgNo()));
4032 if (FT->isVarArg()) {
4033 if (FT->getNumParams()) Out <<
", ";
4044 if (
F->getAddressSpace() != 0 || !
Mod ||
4046 Out <<
" addrspace(" <<
F->getAddressSpace() <<
")";
4047 if (
Attrs.hasFnAttrs())
4048 Out <<
" #" <<
Machine.getAttributeGroupSlot(
Attrs.getFnAttrs());
4049 if (
F->hasSection()) {
4050 Out <<
" section \"";
4051 printEscapedString(
F->getSection(), Out);
4054 if (
F->hasPartition()) {
4055 Out <<
" partition \"";
4056 printEscapedString(
F->getPartition(), Out);
4061 Out <<
" align " <<
A->value();
4063 Out <<
" gc \"" <<
F->getGC() <<
'"';
4064 if (
F->hasPrefixData()) {
4066 writeOperand(
F->getPrefixData(),
true);
4068 if (
F->hasPrologueData()) {
4069 Out <<
" prologue ";
4070 writeOperand(
F->getPrologueData(),
true);
4072 if (
F->hasPersonalityFn()) {
4073 Out <<
" personality ";
4074 writeOperand(
F->getPersonalityFn(),
true);
4077 if (
F->isDeclaration()) {
4081 F->getAllMetadata(MDs);
4082 printMetadataAttachments(MDs,
" ");
4087 printBasicBlock(&BB);
4102 TypePrinter.print(Arg->
getType(), Out);
4105 if (
Attrs.hasAttributes()) {
4107 writeAttributeSet(Attrs);
4116 assert(Slot != -1 &&
"expect argument in function here");
4117 Out <<
" %" <<
Slot;
4122void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
4128 }
else if (!IsEntryBlock) {
4137 if (!IsEntryBlock) {
4139 Out.PadToColumn(50);
4144 Out <<
" No predecessors!";
4147 writeOperand(*PI,
false);
4148 for (++PI; PI != PE; ++PI) {
4150 writeOperand(*PI,
false);
4157 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
4161 for (
const DbgRecord &DR :
I.getDbgRecordRange())
4162 printDbgRecordLine(DR);
4163 printInstructionLine(
I);
4166 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
4170void AssemblyWriter::printInstructionLine(
const Instruction &
I) {
4171 printInstruction(
I);
4177void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
4187void AssemblyWriter::printInfoComment(
const Value &V) {
4188 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
4189 printGCRelocateComment(*Relocate);
4191 if (AnnotationWriter) {
4192 AnnotationWriter->printInfoComment(V, Out);
4199 if (Operand ==
nullptr) {
4200 Out <<
" <cannot get addrspace!>";
4204 bool PrintAddrSpace = CallAddrSpace != 0;
4205 if (!PrintAddrSpace) {
4211 PrintAddrSpace =
true;
4214 Out <<
" addrspace(" << CallAddrSpace <<
")";
4218void AssemblyWriter::printInstruction(
const Instruction &
I) {
4219 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&
I, Out);
4228 }
else if (!
I.getType()->isVoidTy()) {
4230 int SlotNum =
Machine.getLocalSlot(&
I);
4232 Out <<
"<badref> = ";
4234 Out <<
'%' << SlotNum <<
" = ";
4237 if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4238 if (CI->isMustTailCall())
4240 else if (CI->isTailCall())
4242 else if (CI->isNoTailCall())
4247 Out <<
I.getOpcodeName();
4250 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isAtomic()) ||
4251 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isAtomic()))
4254 if (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isWeak())
4258 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isVolatile()) ||
4259 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isVolatile()) ||
4260 (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isVolatile()) ||
4261 (isa<AtomicRMWInst>(
I) && cast<AtomicRMWInst>(
I).isVolatile()))
4268 if (
const CmpInst *CI = dyn_cast<CmpInst>(&
I))
4269 Out <<
' ' << CI->getPredicate();
4276 const Value *Operand =
I.getNumOperands() ?
I.getOperand(0) :
nullptr;
4279 if (isa<BranchInst>(
I) && cast<BranchInst>(
I).isConditional()) {
4282 writeOperand(BI.getCondition(),
true);
4284 writeOperand(BI.getSuccessor(0),
true);
4286 writeOperand(BI.getSuccessor(1),
true);
4288 }
else if (isa<SwitchInst>(
I)) {
4292 writeOperand(
SI.getCondition(),
true);
4294 writeOperand(
SI.getDefaultDest(),
true);
4296 for (
auto Case :
SI.cases()) {
4298 writeOperand(Case.getCaseValue(),
true);
4300 writeOperand(Case.getCaseSuccessor(),
true);
4303 }
else if (isa<IndirectBrInst>(
I)) {
4306 writeOperand(Operand,
true);
4309 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i) {
4312 writeOperand(
I.getOperand(i),
true);
4315 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&
I)) {
4317 TypePrinter.print(
I.getType(), Out);
4320 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
4321 if (
op) Out <<
", ";
4323 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
4324 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
4328 writeOperand(
I.getOperand(0),
true);
4329 for (
unsigned i : EVI->indices())
4333 writeOperand(
I.getOperand(0),
true); Out <<
", ";
4334 writeOperand(
I.getOperand(1),
true);
4335 for (
unsigned i : IVI->indices())
4337 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&
I)) {
4339 TypePrinter.print(
I.getType(), Out);
4340 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
4343 if (LPI->isCleanup())
4346 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
4347 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
4348 if (LPI->isCatch(i))
4353 writeOperand(LPI->getClause(i),
true);
4355 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&
I)) {
4357 writeOperand(CatchSwitch->getParentPad(),
false);
4360 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
4363 writeOperand(PadBB,
true);
4367 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
4368 writeOperand(UnwindDest,
true);
4371 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&
I)) {
4373 writeOperand(FPI->getParentPad(),
false);
4375 for (
unsigned Op = 0, NumOps = FPI->arg_size();
Op < NumOps; ++
Op) {
4378 writeOperand(FPI->getArgOperand(
Op),
true);
4381 }
else if (isa<ReturnInst>(
I) && !Operand) {
4383 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&
I)) {
4385 writeOperand(CRI->getOperand(0),
false);
4388 writeOperand(CRI->getOperand(1),
true);
4389 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&
I)) {
4391 writeOperand(CRI->getOperand(0),
false);
4394 if (CRI->hasUnwindDest())
4395 writeOperand(CRI->getOperand(1),
true);
4398 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4405 Operand = CI->getCalledOperand();
4420 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4422 writeOperand(Operand,
false);
4424 for (
unsigned op = 0, Eop = CI->arg_size();
op < Eop; ++
op) {
4432 if (CI->isMustTailCall() && CI->getParent() &&
4433 CI->getParent()->getParent() &&
4434 CI->getParent()->getParent()->isVarArg()) {
4435 if (CI->arg_size() > 0)
4444 writeOperandBundles(CI);
4445 }
else if (
const InvokeInst *
II = dyn_cast<InvokeInst>(&
I)) {
4446 Operand =
II->getCalledOperand();
4468 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4470 writeOperand(Operand,
false);
4472 for (
unsigned op = 0, Eop =
II->arg_size();
op < Eop; ++
op) {
4482 writeOperandBundles(
II);
4485 writeOperand(
II->getNormalDest(),
true);
4487 writeOperand(
II->getUnwindDest(),
true);
4488 }
else if (
const CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
4489 Operand = CBI->getCalledOperand();
4508 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4510 writeOperand(Operand,
false);
4512 for (
unsigned op = 0, Eop = CBI->arg_size();
op < Eop; ++
op) {
4522 writeOperandBundles(CBI);
4525 writeOperand(CBI->getDefaultDest(),
true);
4527 for (
unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i) {
4530 writeOperand(CBI->getIndirectDest(i),
true);
4533 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
4535 if (AI->isUsedWithInAlloca())
4537 if (AI->isSwiftError())
4538 Out <<
"swifterror ";
4539 TypePrinter.print(AI->getAllocatedType(), Out);
4545 if (!AI->getArraySize() || AI->isArrayAllocation() ||
4546 !AI->getArraySize()->getType()->isIntegerTy(32)) {
4548 writeOperand(AI->getArraySize(),
true);
4551 Out <<
", align " <<
A->value();
4554 unsigned AddrSpace = AI->getAddressSpace();
4555 if (AddrSpace != 0) {
4556 Out <<
", addrspace(" << AddrSpace <<
')';
4558 }
else if (isa<CastInst>(
I)) {
4561 writeOperand(Operand,
true);
4564 TypePrinter.print(
I.getType(), Out);
4565 }
else if (isa<VAArgInst>(
I)) {
4568 writeOperand(Operand,
true);
4571 TypePrinter.print(
I.getType(), Out);
4572 }
else if (Operand) {
4573 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&
I)) {
4575 TypePrinter.print(
GEP->getSourceElementType(), Out);
4577 }
else if (
const auto *LI = dyn_cast<LoadInst>(&
I)) {
4579 TypePrinter.print(LI->getType(), Out);
4586 bool PrintAllTypes =
false;
4591 if (isa<SelectInst>(
I) || isa<StoreInst>(
I) || isa<ShuffleVectorInst>(
I) ||
4592 isa<ReturnInst>(
I) || isa<AtomicCmpXchgInst>(
I) ||
4593 isa<AtomicRMWInst>(
I)) {
4594 PrintAllTypes =
true;
4596 for (
unsigned i = 1, E =
I.getNumOperands(); i != E; ++i) {
4597 Operand =
I.getOperand(i);
4600 if (Operand && Operand->
getType() != TheType) {
4601 PrintAllTypes =
true;
4607 if (!PrintAllTypes) {
4609 TypePrinter.print(TheType, Out);
4613 for (
unsigned i = 0, E =
I.getNumOperands(); i != E; ++i) {
4615 writeOperand(
I.getOperand(i), PrintAllTypes);
4620 if (
const LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
4622 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4624 Out <<
", align " <<
A->value();
4625 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(&
I)) {
4627 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4629 Out <<
", align " <<
A->value();
4631 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4632 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4633 Out <<
", align " << CXI->getAlign().value();
4634 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&
I)) {
4635 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4636 RMWI->getSyncScopeID());
4637 Out <<
", align " << RMWI->getAlign().value();
4638 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&
I)) {
4639 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
4646 I.getAllMetadata(InstMD);
4647 printMetadataAttachments(InstMD,
", ");
4650 printInfoComment(
I);
4653void AssemblyWriter::printDbgMarker(
const DbgMarker &Marker) {
4657 printDbgRecord(DPR);
4661 Out <<
" DbgMarker -> { ";
4667void AssemblyWriter::printDbgRecord(
const DbgRecord &DR) {
4668 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR))
4669 printDbgVariableRecord(*DVR);
4670 else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR))
4671 printDbgLabelRecord(*DLR);
4677 auto WriterCtx = getContext();
4680 case DbgVariableRecord::LocationType::Value:
4683 case DbgVariableRecord::LocationType::Declare:
4686 case DbgVariableRecord::LocationType::Assign:
4691 "Tried to print a DbgVariableRecord with an invalid LocationType!");
4714void AssemblyWriter::printDbgRecordLine(
const DbgRecord &DR) {
4721void AssemblyWriter::printDbgLabelRecord(
const DbgLabelRecord &Label) {
4722 auto WriterCtx = getContext();
4723 Out <<
"#dbg_label(";
4730void AssemblyWriter::printMetadataAttachments(
4736 if (MDNames.empty())
4737 MDs[0].second->getContext().getMDKindNames(MDNames);
4739 auto WriterCtx = getContext();
4740 for (
const auto &
I : MDs) {
4741 unsigned Kind =
I.first;
4743 if (Kind < MDNames.size()) {
4747 Out <<
"!<unknown kind #" <<
Kind <<
">";
4753void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *
Node) {
4754 Out <<
'!' <<
Slot <<
" = ";
4755 printMDNodeBody(
Node);
4759void AssemblyWriter::writeAllMDNodes() {
4763 Nodes[
I.second] = cast<MDNode>(
I.first);
4765 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
4766 writeMDNode(i, Nodes[i]);
4770void AssemblyWriter::printMDNodeBody(
const MDNode *
Node) {
4771 auto WriterCtx = getContext();
4775void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
4784 TypePrinter.print(Ty, Out);
4789void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
4791 bool FirstAttr =
true;
4792 for (
const auto &Attr : AttrSet) {
4795 writeAttribute(Attr, InAttrGroup);
4800void AssemblyWriter::writeAllAttributeGroups() {
4801 std::vector<std::pair<AttributeSet, unsigned>> asVec;
4802 asVec.resize(
Machine.as_size());
4805 asVec[
I.second] =
I;
4807 for (
const auto &
I : asVec)
4808 Out <<
"attributes #" <<
I.second <<
" = { "
4809 <<
I.first.getAsString(
true) <<
" }\n";
4812void AssemblyWriter::printUseListOrder(
const Value *V,
4813 const std::vector<unsigned> &Shuffle) {
4814 bool IsInFunction =
Machine.getFunction();
4818 Out <<
"uselistorder";
4819 if (
const BasicBlock *BB = IsInFunction ?
nullptr : dyn_cast<BasicBlock>(V)) {
4821 writeOperand(BB->getParent(),
false);
4823 writeOperand(BB,
false);
4826 writeOperand(V,
true);
4830 assert(Shuffle.size() >= 2 &&
"Shuffle too small");
4832 for (
unsigned I = 1, E = Shuffle.size();
I != E; ++
I)
4833 Out <<
", " << Shuffle[
I];
4837void AssemblyWriter::printUseLists(
const Function *
F) {
4838 auto It = UseListOrders.find(
F);
4839 if (It == UseListOrders.end())
4842 Out <<
"\n; uselistorder directives\n";
4843 for (
const auto &Pair : It->second)
4844 printUseListOrder(Pair.first, Pair.second);
4852 bool ShouldPreserveUseListOrder,
4853 bool IsForDebug)
const {
4856 AssemblyWriter W(
OS, SlotTable, this->
getParent(), AAW,
4858 ShouldPreserveUseListOrder);
4859 W.printFunction(
this);
4863 bool ShouldPreserveUseListOrder,
4864 bool IsForDebug)
const {
4867 AssemblyWriter W(
OS, SlotTable, this->
getModule(), AAW,
4869 ShouldPreserveUseListOrder);
4870 W.printBasicBlock(
this);
4874 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
4877 AssemblyWriter W(
OS, SlotTable,
this, AAW, IsForDebug,
4878 ShouldPreserveUseListOrder);
4879 W.printModule(
this);
4885 AssemblyWriter W(
OS, SlotTable,
getParent(),
nullptr, IsForDebug);
4886 W.printNamedMDNode(
this);
4890 bool IsForDebug)
const {
4891 std::optional<SlotTracker> LocalST;
4897 SlotTable = &*LocalST;
4901 AssemblyWriter W(
OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4902 W.printNamedMDNode(
this);
4907 ROS <<
" = comdat ";
4914 ROS <<
"exactmatch";
4920 ROS <<
"nodeduplicate";
4932 TP.print(
const_cast<Type*
>(
this),
OS);
4938 if (
StructType *STy = dyn_cast<StructType>(
const_cast<Type*
>(
this)))
4941 TP.printStructBody(STy,
OS);
4946 if (
const auto *CI = dyn_cast<CallInst>(&
I))
4947 if (
Function *
F = CI->getCalledFunction())
4948 if (
F->isIntrinsic())
4949 for (
auto &
Op :
I.operands())
4950 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4951 if (isa<MDNode>(V->getMetadata()))
4959 print(ROS, MST, IsForDebug);
4965 print(ROS, MST, IsForDebug);
4969 bool IsForDebug)
const {
4974 auto incorporateFunction = [&](
const Function *
F) {
4980 W.printDbgMarker(*
this);
4986 print(ROS, MST, IsForDebug);
4990 bool IsForDebug)
const {
4995 auto incorporateFunction = [&](
const Function *
F) {
5003 W.printDbgVariableRecord(*
this);
5007 bool IsForDebug)
const {
5012 auto incorporateFunction = [&](
const Function *
F) {
5019 W.printDbgLabelRecord(*
this);
5023 bool ShouldInitializeAllMetadata =
false;
5024 if (
auto *
I = dyn_cast<Instruction>(
this))
5026 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
5027 ShouldInitializeAllMetadata =
true;
5030 print(ROS, MST, IsForDebug);
5034 bool IsForDebug)
const {
5039 auto incorporateFunction = [&](
const Function *
F) {
5044 if (
const Instruction *
I = dyn_cast<Instruction>(
this)) {
5045 incorporateFunction(
I->getParent() ?
I->getParent()->getParent() :
nullptr);
5047 W.printInstruction(*
I);
5048 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
5049 incorporateFunction(BB->getParent());
5051 W.printBasicBlock(BB);
5052 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
5053 AssemblyWriter W(
OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
5056 else if (
const Function *
F = dyn_cast<Function>(GV))
5058 else if (
const GlobalAlias *
A = dyn_cast<GlobalAlias>(GV))
5060 else if (
const GlobalIFunc *
I = dyn_cast<GlobalIFunc>(GV))
5064 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
5066 }
else if (
const Constant *
C = dyn_cast<Constant>(
this)) {
5067 TypePrinting TypePrinter;
5068 TypePrinter.print(
C->getType(),
OS);
5070 AsmWriterContext WriterCtx(&TypePrinter, MST.
getMachine());
5072 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
5084 if (V.hasName() || isa<GlobalValue>(V) ||
5085 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
5086 AsmWriterContext WriterCtx(
nullptr,
Machine, M);
5095 TypePrinting TypePrinter(MST.
getModule());
5097 TypePrinter.print(V.getType(), O);
5115 M, isa<MetadataAsValue>(
this));
5131 AsmWriterContext &WriterCtx) {
5135 auto *
N = dyn_cast<MDNode>(&MD);
5136 if (!
N || isa<DIExpression>(MD))
5144struct MDTreeAsmWriterContext :
public AsmWriterContext {
5147 using EntryTy = std::pair<unsigned, std::string>;
5157 : AsmWriterContext(TP,
ST,
M), Level(0
U), Visited({InitMD}), MainOS(
OS) {}
5159 void onWriteMetadataAsOperand(
const Metadata *MD)
override {
5160 if (!Visited.
insert(MD).second)
5169 unsigned InsertIdx = Buffer.
size() - 1;
5172 Buffer[InsertIdx].second = std::move(
SS.str());
5176 ~MDTreeAsmWriterContext() {
5177 for (
const auto &Entry : Buffer) {
5179 unsigned NumIndent =
Entry.first * 2U;
5188 bool OnlyAsOperand,
bool PrintAsTree =
false) {
5191 TypePrinting TypePrinter(M);
5193 std::unique_ptr<AsmWriterContext> WriterCtx;
5194 if (PrintAsTree && !OnlyAsOperand)
5195 WriterCtx = std::make_unique<MDTreeAsmWriterContext>(
5199 std::make_unique<AsmWriterContext>(&TypePrinter, MST.
getMachine(), M);
5203 auto *
N = dyn_cast<MDNode>(&MD);
5204 if (OnlyAsOperand || !
N || isa<DIExpression>(MD))
5228 const Module *M,
bool )
const {
5247 AssemblyWriter W(
OS, SlotTable,
this, IsForDebug);
5248 W.printModuleSummaryIndex();
5252 unsigned UB)
const {
5258 if (
I.second >= LB &&
I.second < UB)
5259 L.push_back(std::make_pair(
I.second,
I.first));
5262#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
MapVector< const Value *, unsigned > OrderMap
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand, bool PrintAsTree=false)
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT)
static std::vector< unsigned > predictValueUseListOrder(const Value *V, unsigned ID, const OrderMap &OM)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void orderValue(const Value *V, OrderMap &OM)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix)
Turn the specified name into an 'LLVM name', which is either prefixed with % (if the string only cont...
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)
static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef< int > Mask)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static bool isReferencingMDNode(const Instruction &I)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, AsmWriterContext &Ctx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static 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.
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...
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides utility classes that use RAII to save and restore values.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
This defines the Use class.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
const fltSemantics & getSemantics() const
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
Abstract interface of slot tracker storage.
virtual ~AbstractSlotTrackerStorage()
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
virtual ~AssemblyAnnotationWriter()
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
static StringRef getOperationName(BinOp Op)
AttributeSet getFnAttrs() const
The function attributes are returned.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
bool hasRetAttrs() const
Return true if attributes exist for the return value.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
bool hasFnAttrs() const
Return true the attributes exist for the function.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
bool hasAttributes() const
Return true if attributes exists in this set.
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM Basic Block Representation.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the basic block to an output stream with an optional AssemblyAnnotationWriter.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const Function * getParent() const
Return the enclosing method, or null if none.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
The address of a basic block.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
void print(raw_ostream &OS, bool IsForDebug=false) const
StringRef getName() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
SelectionKind getSelectionKind() const
ConstantArray - Constant Array Declarations.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
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 * 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.
unsigned getProgramAddressSpace() const
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 > insert(const std::pair< KeyT, ValueT > &KV)
Utility class for floating point operations which can have information about relaxed accuracy require...
An instruction for ordering other memory operations.
Function summary information to aid decisions and implementation of importing.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter.
Represents calls to the gc.relocate intrinsic.
Value * getBasePtr() const
Value * getDerivedPtr() const
Generic tagged DWARF-like metadata node.
const Constant * getAliasee() const
const Constant * getResolver() const
StringRef getSection() const
Get the custom section of this global if it has one.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
const Comdat * getComdat() const
bool hasSection() const
Check if this global has a custom object file section.
Function and variable summary information to aid decisions and implementation of importing.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
bool hasPartition() const
const SanitizerMetadata & getSanitizerMetadata() const
bool hasExternalLinkage() const
VisibilityTypes getVisibility() const
bool isImplicitDSOLocal() const
LinkageTypes getLinkage() const
ThreadLocalMode getThreadLocalMode() const
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
bool hasSanitizerMetadata() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
StringRef getPartition() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Type * getValueType() const
Global variable summary information to aid decisions and implementation of importing.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isExternallyInitialized() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
AttributeSet getAttributes() const
Return the attribute set for this global.
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
This instruction inserts a struct field of array element value into an aggregate value.
This is an important class for using LLVM in a threaded context.
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
void printTree(raw_ostream &OS, const Module *M=nullptr) const
Print in tree shape.
void dumpTree() const
User-friendly dump in tree shape.
This class implements a map that also provides access to all stored values in a deterministic order.
Manage lifetime of a slot tracker for printing IR.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
const Module * getModule() const
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
virtual ~ModuleSlotTracker()
Destructor to clean up storage.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
SlotTracker * getMachine()
Lazily creates a slot tracker.
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
void incorporateFunction(const Function &F)
Incorporate the given function.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr const char * getRegularLTOModuleName()
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
void dump() const
Dump to stderr (for debugging).
void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
A Module instance is used to store all the information related to an LLVM module.
iterator_range< ifunc_iterator > ifuncs()
iterator_range< named_metadata_iterator > named_metadata()
iterator_range< alias_iterator > aliases()
iterator_range< global_iterator > globals()
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void dump() const
Dump the module to stderr (for debugging).
StringRef getName() const
void print(raw_ostream &ROS, bool IsForDebug=false) const
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
Module * getParent()
Get the module that holds this named metadata collection.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
A vector that has set insertion semantics.
This instruction constructs a fixed permutation of two input vectors.
This class provides computation of slot numbers for LLVM Assembly writing.
int getMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
int getTypeIdCompatibleVtableSlot(StringRef Id)
int getModulePathSlot(StringRef Path)
unsigned mdn_size() const
SlotTracker(const SlotTracker &)=delete
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
int getTypeIdSlot(StringRef Id)
void initializeIfNeeded()
These functions do the actual initialization.
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
const Function * getFunction() const
unsigned getNextMetadataSlot() override
void incorporateFunction(const Function *F)
If you'd like to deal with a function instead of just a module, use this method to get its data into ...
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
int getAttributeGroupSlot(AttributeSet AS)
SlotTracker(const Module *M, bool ShouldInitializeAllMetadata=false)
Construct from a module.
void createMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
SlotTracker & operator=(const SlotTracker &)=delete
int getGUIDSlot(GlobalValue::GUID GUID)
int initializeIndexIfNeeded()
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Class to represent struct types.
ArrayRef< Type * > elements() const
unsigned getNumElements() const
Random access to the elements.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
StringRef getName() const
Return the name for this struct type if it has an identity.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
ArrayRef< Type * > type_params() const
Return the type parameters for this particular target extension type.
ArrayRef< unsigned > int_params() const
Return the integer parameters for this particular target extension type.
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
StringRef getTargetExtName() const
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
A few GPU targets, such as DXIL and SPIR-V, have typed pointers.
Type * getElementType() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
StringRef getName() const
Return a constant reference to the value's name.
void dump() const
Support for debugging, callable in GDB: V->dump()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
StringRef LanguageString(unsigned Language)
StringRef AttributeEncodingString(unsigned Encoding)
StringRef ConventionString(unsigned Convention)
StringRef MacinfoString(unsigned Encoding)
StringRef OperationEncodingString(unsigned Encoding)
StringRef TagString(unsigned Tag)
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ 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.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
This is an optimization pass for GlobalISel generic memory operations.
pred_iterator pred_end(BasicBlock *BB)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
const char * getHotnessName(CalleeInfo::HotnessType HT)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
pred_iterator pred_begin(BasicBlock *BB)
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)
@ 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:...