31#include "llvm/Config/llvm-config.h"
93 cl::desc(
"Print addresses of instructions when dumping"));
97 cl::desc(
"Pretty print debug locations of instructions when dumping"));
101 cl::desc(
"Pretty print perf data (branch weights, etc) when dumping"));
118 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V))
119 if (
const auto *VAM = dyn_cast<ValueAsMetadata>(MAV->getMetadata()))
120 return VAM->getValue();
128 if (
const Constant *
C = dyn_cast<Constant>(V)) {
129 if (isa<ConstantData>(
C))
132 if (
C->getNumOperands() && !isa<GlobalValue>(
C))
133 for (
const Value *
Op :
C->operands())
134 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
140 unsigned ID = OM.size() + 1;
147 auto orderConstantValue = [&OM](
const Value *V) {
148 if (isa<Constant>(V) || isa<InlineAsm>(V))
152 auto OrderConstantFromMetadata = [&](
Metadata *MD) {
153 if (
const auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
154 orderConstantValue(VAM->getValue());
155 }
else if (
const auto *AL = dyn_cast<DIArgList>(MD)) {
156 for (
const auto *VAM : AL->getArgs())
157 orderConstantValue(VAM->getValue());
162 if (
G.hasInitializer())
163 if (!isa<GlobalValue>(
G.getInitializer()))
168 if (!isa<GlobalValue>(
A.getAliasee()))
173 if (!isa<GlobalValue>(
I.getResolver()))
178 for (
const Use &U :
F.operands())
179 if (!isa<GlobalValue>(U.get()))
184 if (
F.isDeclaration())
197 OrderConstantFromMetadata(DVR.getRawLocation());
198 if (DVR.isDbgAssign())
199 OrderConstantFromMetadata(DVR.getRawAddress());
202 for (
const Value *
Op :
I.operands()) {
204 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
215static std::vector<unsigned>
218 using Entry = std::pair<const Use *, unsigned>;
220 for (
const Use &U : V->uses())
222 if (OM.lookup(U.getUser()))
223 List.push_back(std::make_pair(&U,
List.size()));
232 bool GetsReversed = !isa<BasicBlock>(V);
233 if (
auto *BA = dyn_cast<BlockAddress>(V))
234 ID = OM.lookup(BA->getBasicBlock());
236 const Use *LU = L.first;
237 const Use *RU = R.first;
241 auto LID = OM.lookup(LU->getUser());
242 auto RID = OM.lookup(RU->getUser());
262 return LU->getOperandNo() < RU->getOperandNo();
263 return LU->getOperandNo() > RU->getOperandNo();
271 std::vector<unsigned> Shuffle(
List.size());
272 for (
size_t I = 0, E =
List.size();
I != E; ++
I)
273 Shuffle[
I] =
List[
I].second;
280 for (
const auto &Pair : OM) {
281 const Value *V = Pair.first;
282 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
285 std::vector<unsigned> Shuffle =
291 if (
auto *
I = dyn_cast<Instruction>(V))
292 F =
I->getFunction();
293 if (
auto *
A = dyn_cast<Argument>(V))
295 if (
auto *BB = dyn_cast<BasicBlock>(V))
297 ULOM[
F][V] = std::move(Shuffle);
303 if (
const Argument *MA = dyn_cast<Argument>(V))
304 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
306 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
307 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
310 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
311 return M ? M->getParent() :
nullptr;
314 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
315 return GV->getParent();
317 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
318 for (
const User *U : MAV->users())
319 if (isa<Instruction>(U))
331 return M ? M->getParent() :
nullptr;
340 default: Out <<
"cc" << cc;
break;
363 Out <<
"aarch64_sve_vector_pcs";
366 Out <<
"aarch64_sme_preservemost_from_x0";
369 Out <<
"aarch64_sme_preservemost_from_x1";
372 Out <<
"aarch64_sme_preservemost_from_x2";
400 Out <<
"amdgpu_cs_chain";
403 Out <<
"amdgpu_cs_chain_preserve";
408 Out <<
"amdgpu_gfx_whole_wave";
412 Out <<
"riscv_vector_cc";
414#define CC_VLS_CASE(ABI_VLEN) \
415 case CallingConv::RISCV_VLSCall_##ABI_VLEN: \
416 Out << "riscv_vls_cc(" #ABI_VLEN ")"; \
443 assert(!
Name.empty() &&
"Cannot get empty name!");
446 bool NeedsQuotes = isdigit(
static_cast<unsigned char>(
Name[0]));
448 for (
unsigned char C :
Name) {
453 if (!isalnum(
C) &&
C !=
'-' &&
C !=
'.' &&
C !=
'_') {
469 printEscapedString(
Name,
OS);
505 if (isa<ScalableVectorType>(Ty))
507 Out << Mask.size() <<
" x i32> ";
508 bool FirstElt =
true;
509 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
510 Out <<
"zeroinitializer";
515 for (
int Elt : Mask) {
534 TypePrinting(
const Module *M =
nullptr) : DeferredM(
M) {}
536 TypePrinting(
const TypePrinting &) =
delete;
537 TypePrinting &operator=(
const TypePrinting &) =
delete;
543 std::vector<StructType *> &getNumberedTypes();
552 void incorporateTypes();
562 std::vector<StructType *> NumberedTypes;
572std::vector<StructType *> &TypePrinting::getNumberedTypes() {
578 if (NumberedTypes.size() == Type2Number.size())
579 return NumberedTypes;
581 NumberedTypes.resize(Type2Number.size());
582 for (
const auto &
P : Type2Number) {
583 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
584 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
585 NumberedTypes[
P.second] =
P.first;
587 return NumberedTypes;
590bool TypePrinting::empty() {
592 return NamedTypes.empty() && Type2Number.empty();
595void TypePrinting::incorporateTypes() {
599 NamedTypes.run(*DeferredM,
false);
604 unsigned NextNumber = 0;
606 std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();
609 if (STy->isLiteral())
612 if (STy->getName().empty())
613 Type2Number[STy] = NextNumber++;
618 NamedTypes.erase(NextToUse, NamedTypes.end());
640 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
645 print(FTy->getReturnType(),
OS);
648 for (
Type *Ty : FTy->params()) {
661 return printStructBody(STy,
OS);
667 const auto I = Type2Number.find(STy);
668 if (
I != Type2Number.end())
669 OS <<
'%' <<
I->second;
671 OS <<
"%\"type " << STy <<
'\"';
683 OS <<
'[' << ATy->getNumElements() <<
" x ";
684 print(ATy->getElementType(),
OS);
695 OS <<
EC.getKnownMinValue() <<
" x ";
696 print(PTy->getElementType(),
OS);
713 Inner->print(
OS,
false,
true);
716 OS <<
", " << IntParam;
767 const Function* TheFunction =
nullptr;
768 bool FunctionProcessed =
false;
769 bool ShouldInitializeAllMetadata;
774 ProcessFunctionHookFn;
789 unsigned mdnNext = 0;
797 unsigned ModulePathNext = 0;
801 unsigned GUIDNext = 0;
805 unsigned TypeIdNext = 0;
810 unsigned TypeIdCompatibleVtableNext = 0;
819 bool ShouldInitializeAllMetadata =
false);
827 bool ShouldInitializeAllMetadata =
false);
861 FunctionProcessed =
false;
900 void CreateMetadataSlot(
const MDNode *
N);
903 void CreateFunctionSlot(
const Value *V);
908 inline void CreateModulePathSlot(
StringRef Path);
911 void CreateTypeIdCompatibleVtableSlot(
StringRef Id);
915 void processModule();
920 void processFunction();
923 void processGlobalObjectMetadata(
const GlobalObject &GO);
926 void processFunctionMetadata(
const Function &
F);
932 void processDbgRecordMetadata(
const DbgRecord &DVR);
942 bool ShouldInitializeAllMetadata)
943 : ShouldCreateStorage(M),
944 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
949 if (!ShouldCreateStorage)
952 ShouldCreateStorage =
false;
954 std::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
955 Machine = MachineStorage.get();
956 if (ProcessModuleHookFn)
958 if (ProcessFunctionHookFn)
978 assert(F &&
"No function incorporated");
985 ProcessModuleHookFn = Fn;
991 ProcessFunctionHookFn = Fn;
995 if (
const Argument *FA = dyn_cast<Argument>(V))
1002 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
1008 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
1011 if (
const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
1014 if (
const Function *Func = dyn_cast<Function>(V))
1021#define ST_DEBUG(X) dbgs() << X
1029 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
1034 : TheModule(
F ?
F->
getParent() : nullptr), TheFunction(
F),
1035 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
1038 : TheModule(nullptr), ShouldInitializeAllMetadata(
false), TheIndex(Index) {}
1043 TheModule =
nullptr;
1046 if (TheFunction && !FunctionProcessed)
1053 int NumSlots = processIndex();
1060void SlotTracker::processModule() {
1061 ST_DEBUG(
"begin processModule!\n");
1066 CreateModuleSlot(&Var);
1067 processGlobalObjectMetadata(Var);
1068 auto Attrs = Var.getAttributes();
1069 if (Attrs.hasAttributes())
1070 CreateAttributeSetSlot(Attrs);
1075 CreateModuleSlot(&
A);
1080 CreateModuleSlot(&
I);
1085 for (
const MDNode *
N : NMD.operands())
1086 CreateMetadataSlot(
N);
1092 CreateModuleSlot(&
F);
1094 if (ShouldInitializeAllMetadata)
1095 processFunctionMetadata(
F);
1101 CreateAttributeSetSlot(FnAttrs);
1104 if (ProcessModuleHookFn)
1105 ProcessModuleHookFn(
this, TheModule, ShouldInitializeAllMetadata);
1111void SlotTracker::processFunction() {
1112 ST_DEBUG(
"begin processFunction!\n");
1116 if (!ShouldInitializeAllMetadata)
1117 processFunctionMetadata(*TheFunction);
1121 AE = TheFunction->
arg_end(); AI != AE; ++AI)
1123 CreateFunctionSlot(&*AI);
1125 ST_DEBUG(
"Inserting Instructions:\n");
1128 for (
auto &BB : *TheFunction) {
1130 CreateFunctionSlot(&BB);
1132 for (
auto &
I : BB) {
1133 if (!
I.getType()->isVoidTy() && !
I.hasName())
1134 CreateFunctionSlot(&
I);
1138 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1141 if (
Attrs.hasAttributes())
1142 CreateAttributeSetSlot(Attrs);
1147 if (ProcessFunctionHookFn)
1148 ProcessFunctionHookFn(
this, TheFunction, ShouldInitializeAllMetadata);
1150 FunctionProcessed =
true;
1152 ST_DEBUG(
"end processFunction!\n");
1156int SlotTracker::processIndex() {
1163 std::vector<StringRef> ModulePaths;
1165 ModulePaths.push_back(ModPath);
1167 for (
auto &ModPath : ModulePaths)
1168 CreateModulePathSlot(ModPath);
1171 GUIDNext = ModulePathNext;
1173 for (
auto &GlobalList : *TheIndex)
1174 CreateGUIDSlot(GlobalList.first);
1177 TypeIdCompatibleVtableNext = GUIDNext;
1178 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1179 CreateTypeIdCompatibleVtableSlot(TId.first);
1182 TypeIdNext = TypeIdCompatibleVtableNext;
1183 for (
const auto &TID : TheIndex->typeIds())
1184 CreateTypeIdSlot(TID.second.first);
1190void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1193 for (
auto &MD : MDs)
1194 CreateMetadataSlot(MD.second);
1197void SlotTracker::processFunctionMetadata(
const Function &
F) {
1198 processGlobalObjectMetadata(
F);
1199 for (
auto &BB :
F) {
1200 for (
auto &
I : BB) {
1201 for (
const DbgRecord &DR :
I.getDbgRecordRange())
1202 processDbgRecordMetadata(DR);
1203 processInstructionMetadata(
I);
1208void SlotTracker::processDbgRecordMetadata(
const DbgRecord &DR) {
1218 if (
auto *Empty = dyn_cast_if_present<MDNode>(DVR->getRawLocation()))
1219 CreateMetadataSlot(Empty);
1220 if (DVR->getRawVariable())
1221 CreateMetadataSlot(DVR->getRawVariable());
1222 if (DVR->isDbgAssign()) {
1223 if (
auto *AssignID = DVR->getRawAssignID())
1224 CreateMetadataSlot(cast<MDNode>(AssignID));
1225 if (
auto *Empty = dyn_cast_if_present<MDNode>(DVR->getRawAddress()))
1226 CreateMetadataSlot(Empty);
1228 }
else if (
const DbgLabelRecord *DLR = dyn_cast<const DbgLabelRecord>(&DR)) {
1229 CreateMetadataSlot(DLR->getRawLabel());
1237void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1239 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
1240 if (
Function *
F = CI->getCalledFunction())
1241 if (
F->isIntrinsic())
1242 for (
auto &
Op :
I.operands())
1243 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1244 if (
MDNode *
N = dyn_cast<MDNode>(
V->getMetadata()))
1245 CreateMetadataSlot(
N);
1249 I.getAllMetadata(MDs);
1250 for (
auto &MD : MDs)
1251 CreateMetadataSlot(MD.second);
1258 ST_DEBUG(
"begin purgeFunction!\n");
1260 TheFunction =
nullptr;
1261 FunctionProcessed =
false;
1272 return MI == mMap.
end() ? -1 : (int)
MI->second;
1278 ProcessModuleHookFn = Fn;
1284 ProcessFunctionHookFn = Fn;
1297 return MI == mdnMap.
end() ? -1 : (int)
MI->second;
1302 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1308 return FI == fMap.
end() ? -1 : (int)FI->second;
1317 return AI == asMap.
end() ? -1 : (int)AI->second;
1325 auto I = ModulePathMap.
find(Path);
1326 return I == ModulePathMap.
end() ? -1 : (int)
I->second;
1335 return I == GUIDMap.
end() ? -1 : (int)
I->second;
1343 auto I = TypeIdMap.
find(Id);
1344 return I == TypeIdMap.
end() ? -1 : (int)
I->second;
1352 auto I = TypeIdCompatibleVtableMap.
find(Id);
1353 return I == TypeIdCompatibleVtableMap.
end() ? -1 : (int)
I->second;
1357void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1358 assert(V &&
"Can't insert a null Value into SlotTracker!");
1359 assert(!V->getType()->isVoidTy() &&
"Doesn't need a slot!");
1360 assert(!V->hasName() &&
"Doesn't need a slot!");
1362 unsigned DestSlot = mNext++;
1365 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1368 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1369 (isa<Function>(V) ?
'F' :
1370 (isa<GlobalAlias>(V) ?
'A' :
1371 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1375void SlotTracker::CreateFunctionSlot(
const Value *V) {
1376 assert(!V->getType()->isVoidTy() && !V->hasName() &&
"Doesn't need a slot!");
1378 unsigned DestSlot = fNext++;
1382 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1383 DestSlot <<
" [o]\n");
1387void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1388 assert(
N &&
"Can't insert a null Value into SlotTracker!");
1391 if (isa<DIExpression>(
N))
1394 unsigned DestSlot = mdnNext;
1395 if (!mdnMap.
insert(std::make_pair(
N, DestSlot)).second)
1400 for (
unsigned i = 0, e =
N->getNumOperands(); i != e; ++i)
1401 if (
const MDNode *
Op = dyn_cast_or_null<MDNode>(
N->getOperand(i)))
1402 CreateMetadataSlot(
Op);
1405void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1413void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1414 ModulePathMap[
Path] = ModulePathNext++;
1419 GUIDMap[
GUID] = GUIDNext++;
1423void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1424 TypeIdMap[
Id] = TypeIdNext++;
1428void SlotTracker::CreateTypeIdCompatibleVtableSlot(
StringRef Id) {
1429 TypeIdCompatibleVtableMap[
Id] = TypeIdCompatibleVtableNext++;
1434struct AsmWriterContext {
1435 TypePrinting *TypePrinter =
nullptr;
1442 static AsmWriterContext &getEmpty() {
1443 static AsmWriterContext EmptyCtx(
nullptr,
nullptr);
1449 virtual void onWriteMetadataAsOperand(
const Metadata *) {}
1451 virtual ~AsmWriterContext() =
default;
1460 AsmWriterContext &WriterCtx);
1463 AsmWriterContext &WriterCtx,
1464 bool FromValue =
false);
1467 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U))
1468 Out << FPO->getFastMathFlags();
1471 dyn_cast<OverflowingBinaryOperator>(U)) {
1472 if (OBO->hasNoUnsignedWrap())
1474 if (OBO->hasNoSignedWrap())
1477 dyn_cast<PossiblyExactOperator>(U)) {
1481 dyn_cast<PossiblyDisjointInst>(U)) {
1482 if (PDI->isDisjoint())
1485 if (
GEP->isInBounds())
1487 else if (
GEP->hasNoUnsignedSignedWrap())
1489 if (
GEP->hasNoUnsignedWrap())
1492 Out <<
" inrange(" <<
InRange->getLower() <<
", " <<
InRange->getUpper()
1495 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(U)) {
1496 if (NNI->hasNonNeg())
1498 }
else if (
const auto *TI = dyn_cast<TruncInst>(U)) {
1499 if (TI->hasNoUnsignedWrap())
1501 if (TI->hasNoSignedWrap())
1503 }
else if (
const auto *ICmp = dyn_cast<ICmpInst>(U)) {
1504 if (ICmp->hasSameSign())
1520 bool isNaN = APF.
isNaN();
1522 if (!isInf && !isNaN) {
1531 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
isDigit(StrVal[1]))) &&
1532 "[-+]?[0-9] regex does not match!");
1544 static_assert(
sizeof(double) ==
sizeof(
uint64_t),
1545 "assuming that double is 64 bits!");
1603 AsmWriterContext &WriterCtx) {
1604 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1605 Type *Ty = CI->getType();
1614 Out << (CI->getZExtValue() ?
"true" :
"false");
1616 Out << CI->getValue();
1624 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1625 Type *Ty = CFP->getType();
1641 if (isa<ConstantAggregateZero>(CV) || isa<ConstantTargetNone>(CV)) {
1642 Out <<
"zeroinitializer";
1646 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1647 Out <<
"blockaddress(";
1655 if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV)) {
1656 Out <<
"dso_local_equivalent ";
1661 if (
const auto *
NC = dyn_cast<NoCFIValue>(CV)) {
1671 unsigned NumOpsToWrite = 2;
1672 if (!CPA->getOperand(2)->isNullValue())
1674 if (!CPA->getOperand(3)->isNullValue())
1678 for (
unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {
1680 WriterCtx.TypePrinter->print(CPA->getOperand(i)->getType(), Out);
1688 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1689 Type *ETy = CA->getType()->getElementType();
1691 WriterCtx.TypePrinter->print(ETy, Out);
1694 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1696 WriterCtx.TypePrinter->print(ETy, Out);
1707 if (CA->isString()) {
1709 printEscapedString(CA->getAsString(), Out);
1714 Type *ETy = CA->getType()->getElementType();
1716 WriterCtx.TypePrinter->print(ETy, Out);
1719 for (
uint64_t i = 1, e = CA->getNumElements(); i != e; ++i) {
1721 WriterCtx.TypePrinter->print(ETy, Out);
1730 if (CS->getType()->isPacked())
1733 unsigned N = CS->getNumOperands();
1736 WriterCtx.TypePrinter->print(CS->getOperand(0)->getType(), Out);
1741 for (
unsigned i = 1; i <
N; i++) {
1743 WriterCtx.TypePrinter->print(CS->getOperand(i)->getType(), Out);
1752 if (CS->getType()->isPacked())
1757 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1758 auto *CVVTy = cast<FixedVectorType>(CV->
getType());
1759 Type *ETy = CVVTy->getElementType();
1767 if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1769 WriterCtx.TypePrinter->print(ETy, Out);
1778 WriterCtx.TypePrinter->print(ETy, Out);
1781 for (
unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) {
1783 WriterCtx.TypePrinter->print(ETy, Out);
1791 if (isa<ConstantPointerNull>(CV)) {
1796 if (isa<ConstantTokenNone>(CV)) {
1801 if (isa<PoisonValue>(CV)) {
1806 if (isa<UndefValue>(CV)) {
1811 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1817 if (CE->getOpcode() == Instruction::ShuffleVector) {
1818 if (
auto *SplatVal = CE->getSplatValue()) {
1819 if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1821 WriterCtx.TypePrinter->print(SplatVal->getType(), Out);
1830 Out << CE->getOpcodeName();
1835 WriterCtx.TypePrinter->print(
GEP->getSourceElementType(), Out);
1841 WriterCtx.TypePrinter->print((*OI)->getType(), Out);
1844 if (OI+1 != CE->op_end())
1850 WriterCtx.TypePrinter->print(CE->getType(), Out);
1853 if (CE->getOpcode() == Instruction::ShuffleVector)
1860 Out <<
"<placeholder or erroneous Constant>";
1864 AsmWriterContext &WriterCtx) {
1866 for (
unsigned mi = 0, me =
Node->getNumOperands(); mi != me; ++mi) {
1870 else if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD)) {
1871 Value *V = MDV->getValue();
1872 WriterCtx.TypePrinter->print(V->getType(), Out);
1877 WriterCtx.onWriteMetadataAsOperand(MD);
1888struct FieldSeparator {
1892 FieldSeparator(
const char *Sep =
", ") : Sep(Sep) {}
1900 return OS <<
FS.Sep;
1903struct MDFieldPrinter {
1906 AsmWriterContext &WriterCtx;
1909 : Out(Out), WriterCtx(AsmWriterContext::getEmpty()) {}
1910 MDFieldPrinter(
raw_ostream &Out, AsmWriterContext &Ctx)
1911 : Out(Out), WriterCtx(Ctx) {}
1913 void printTag(
const DINode *
N);
1917 bool ShouldSkipEmpty =
true);
1919 bool ShouldSkipNull =
true);
1921 bool ShouldSkipZero =
true);
1922 template <
class IntTy>
1925 bool ShouldSkipZero);
1927 std::optional<bool>
Default = std::nullopt);
1930 template <
class IntTy,
class Stringifier>
1932 bool ShouldSkipZero =
true);
1941void MDFieldPrinter::printTag(
const DINode *
N) {
1942 Out <<
FS <<
"tag: ";
1950void MDFieldPrinter::printMacinfoType(
const DIMacroNode *
N) {
1951 Out <<
FS <<
"type: ";
1956 Out <<
N->getMacinfoType();
1959void MDFieldPrinter::printChecksum(
1962 printString(
"checksum", Checksum.
Value,
false);
1966 bool ShouldSkipEmpty) {
1967 if (ShouldSkipEmpty &&
Value.empty())
1970 Out <<
FS <<
Name <<
": \"";
1971 printEscapedString(
Value, Out);
1976 AsmWriterContext &WriterCtx) {
1982 WriterCtx.onWriteMetadataAsOperand(MD);
1986 bool ShouldSkipNull) {
1987 if (ShouldSkipNull && !MD)
1990 Out <<
FS <<
Name <<
": ";
1995 bool IsUnsigned,
bool ShouldSkipZero) {
1999 if (
auto *CI = dyn_cast<ConstantAsMetadata>(MD)) {
2000 auto *CV = cast<ConstantInt>(CI->getValue());
2002 printInt(
Name, CV->getZExtValue(), ShouldSkipZero);
2004 printInt(
Name, CV->getSExtValue(), ShouldSkipZero);
2006 printMetadata(
Name, MD);
2009template <
class IntTy>
2010void MDFieldPrinter::printInt(
StringRef Name, IntTy
Int,
bool ShouldSkipZero) {
2011 if (ShouldSkipZero && !
Int)
2018 bool IsUnsigned,
bool ShouldSkipZero) {
2019 if (ShouldSkipZero &&
Int.isZero())
2022 Out <<
FS <<
Name <<
": ";
2023 Int.print(Out, !IsUnsigned);
2027 std::optional<bool>
Default) {
2030 Out <<
FS <<
Name <<
": " << (
Value ?
"true" :
"false");
2037 Out <<
FS <<
Name <<
": ";
2042 FieldSeparator FlagsFS(
" | ");
2043 for (
auto F : SplitFlags) {
2045 assert(!StringF.empty() &&
"Expected valid flag");
2046 Out << FlagsFS << StringF;
2048 if (Extra || SplitFlags.empty())
2049 Out << FlagsFS << Extra;
2056 Out <<
FS <<
Name <<
": ";
2066 FieldSeparator FlagsFS(
" | ");
2067 for (
auto F : SplitFlags) {
2069 assert(!StringF.empty() &&
"Expected valid flag");
2070 Out << FlagsFS << StringF;
2072 if (Extra || SplitFlags.empty())
2073 Out << FlagsFS << Extra;
2093template <
class IntTy,
class Stringifier>
2095 Stringifier
toString,
bool ShouldSkipZero) {
2096 if (ShouldSkipZero && !
Value)
2099 Out <<
FS <<
Name <<
": ";
2108 AsmWriterContext &WriterCtx) {
2109 Out <<
"!GenericDINode(";
2110 MDFieldPrinter
Printer(Out, WriterCtx);
2112 Printer.printString(
"header",
N->getHeader());
2113 if (
N->getNumDwarfOperands()) {
2114 Out <<
Printer.FS <<
"operands: {";
2116 for (
auto &
I :
N->dwarf_operands()) {
2126 AsmWriterContext &WriterCtx) {
2127 Out <<
"!DILocation(";
2128 MDFieldPrinter
Printer(Out, WriterCtx);
2130 Printer.printInt(
"line",
DL->getLine(),
false);
2131 Printer.printInt(
"column",
DL->getColumn());
2132 Printer.printMetadata(
"scope",
DL->getRawScope(),
false);
2133 Printer.printMetadata(
"inlinedAt",
DL->getRawInlinedAt());
2134 Printer.printBool(
"isImplicitCode",
DL->isImplicitCode(),
2136 Printer.printInt(
"atomGroup",
DL->getAtomGroup());
2137 Printer.printInt<
unsigned>(
"atomRank",
DL->getAtomRank());
2142 AsmWriterContext &WriterCtx) {
2143 Out <<
"!DIAssignID()";
2144 MDFieldPrinter
Printer(Out, WriterCtx);
2148 AsmWriterContext &WriterCtx) {
2149 Out <<
"!DISubrange(";
2150 MDFieldPrinter
Printer(Out, WriterCtx);
2152 Printer.printMetadataOrInt(
"count",
N->getRawCountNode(),
2158 Printer.printMetadataOrInt(
"lowerBound",
N->getRawLowerBound(),
2161 Printer.printMetadataOrInt(
"upperBound",
N->getRawUpperBound(),
2164 Printer.printMetadataOrInt(
"stride",
N->getRawStride(),
2172 AsmWriterContext &WriterCtx) {
2173 Out <<
"!DIGenericSubrange(";
2174 MDFieldPrinter
Printer(Out, WriterCtx);
2176 auto GetConstant = [&](
Metadata *Bound) -> std::optional<int64_t> {
2177 auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2179 return std::nullopt;
2180 if (BE->isConstant() &&
2182 *BE->isConstant()) {
2183 return static_cast<int64_t
>(BE->getElement(1));
2185 return std::nullopt;
2188 auto *Count =
N->getRawCountNode();
2189 if (
auto ConstantCount = GetConstant(Count))
2190 Printer.printInt(
"count", *ConstantCount,
2193 Printer.printMetadata(
"count", Count,
true);
2195 auto *LBound =
N->getRawLowerBound();
2196 if (
auto ConstantLBound = GetConstant(LBound))
2197 Printer.printInt(
"lowerBound", *ConstantLBound,
2200 Printer.printMetadata(
"lowerBound", LBound,
true);
2202 auto *UBound =
N->getRawUpperBound();
2203 if (
auto ConstantUBound = GetConstant(UBound))
2204 Printer.printInt(
"upperBound", *ConstantUBound,
2207 Printer.printMetadata(
"upperBound", UBound,
true);
2209 auto *Stride =
N->getRawStride();
2210 if (
auto ConstantStride = GetConstant(Stride))
2211 Printer.printInt(
"stride", *ConstantStride,
2214 Printer.printMetadata(
"stride", Stride,
true);
2220 AsmWriterContext &) {
2221 Out <<
"!DIEnumerator(";
2223 Printer.printString(
"name",
N->getName(),
false);
2224 Printer.printAPInt(
"value",
N->getValue(),
N->isUnsigned(),
2226 if (
N->isUnsigned())
2227 Printer.printBool(
"isUnsigned",
true);
2232 AsmWriterContext &WriterCtx) {
2233 Out <<
"!DIBasicType(";
2234 MDFieldPrinter
Printer(Out, WriterCtx);
2235 if (
N->getTag() != dwarf::DW_TAG_base_type)
2237 Printer.printString(
"name",
N->getName());
2238 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2239 Printer.printInt(
"align",
N->getAlignInBits());
2240 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2242 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2243 Printer.printDIFlags(
"flags",
N->getFlags());
2248 AsmWriterContext &WriterCtx) {
2249 Out <<
"!DIFixedPointType(";
2250 MDFieldPrinter
Printer(Out, WriterCtx);
2251 if (
N->getTag() != dwarf::DW_TAG_base_type)
2253 Printer.printString(
"name",
N->getName());
2254 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2255 Printer.printInt(
"align",
N->getAlignInBits());
2256 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2258 Printer.printDIFlags(
"flags",
N->getFlags());
2259 Printer.printFixedPointKind(
"kind",
N->getKind());
2260 if (
N->isRational()) {
2261 bool IsUnsigned = !
N->isSigned();
2262 Printer.printAPInt(
"numerator",
N->getNumerator(), IsUnsigned,
false);
2263 Printer.printAPInt(
"denominator",
N->getDenominator(), IsUnsigned,
false);
2265 Printer.printInt(
"factor",
N->getFactor());
2271 AsmWriterContext &WriterCtx) {
2272 Out <<
"!DIStringType(";
2273 MDFieldPrinter
Printer(Out, WriterCtx);
2274 if (
N->getTag() != dwarf::DW_TAG_string_type)
2276 Printer.printString(
"name",
N->getName());
2277 Printer.printMetadata(
"stringLength",
N->getRawStringLength());
2278 Printer.printMetadata(
"stringLengthExpression",
N->getRawStringLengthExp());
2279 Printer.printMetadata(
"stringLocationExpression",
2280 N->getRawStringLocationExp());
2281 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2282 Printer.printInt(
"align",
N->getAlignInBits());
2283 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2289 AsmWriterContext &WriterCtx) {
2290 Out <<
"!DIDerivedType(";
2291 MDFieldPrinter
Printer(Out, WriterCtx);
2293 Printer.printString(
"name",
N->getName());
2294 Printer.printMetadata(
"scope",
N->getRawScope());
2295 Printer.printMetadata(
"file",
N->getRawFile());
2296 Printer.printInt(
"line",
N->getLine());
2297 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2299 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2300 Printer.printInt(
"align",
N->getAlignInBits());
2301 Printer.printMetadataOrInt(
"offset",
N->getRawOffsetInBits(),
true);
2302 Printer.printDIFlags(
"flags",
N->getFlags());
2303 Printer.printMetadata(
"extraData",
N->getRawExtraData());
2304 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2305 Printer.printInt(
"dwarfAddressSpace", *DWARFAddressSpace,
2307 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2308 if (
auto PtrAuthData =
N->getPtrAuthData()) {
2309 Printer.printInt(
"ptrAuthKey", PtrAuthData->key());
2310 Printer.printBool(
"ptrAuthIsAddressDiscriminated",
2311 PtrAuthData->isAddressDiscriminated());
2312 Printer.printInt(
"ptrAuthExtraDiscriminator",
2313 PtrAuthData->extraDiscriminator());
2314 Printer.printBool(
"ptrAuthIsaPointer", PtrAuthData->isaPointer());
2315 Printer.printBool(
"ptrAuthAuthenticatesNullValues",
2316 PtrAuthData->authenticatesNullValues());
2322 AsmWriterContext &WriterCtx) {
2323 Out <<
"!DISubrangeType(";
2324 MDFieldPrinter
Printer(Out, WriterCtx);
2325 Printer.printString(
"name",
N->getName());
2326 Printer.printMetadata(
"scope",
N->getRawScope());
2327 Printer.printMetadata(
"file",
N->getRawFile());
2328 Printer.printInt(
"line",
N->getLine());
2329 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2330 Printer.printInt(
"align",
N->getAlignInBits());
2331 Printer.printDIFlags(
"flags",
N->getFlags());
2332 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2334 Printer.printMetadata(
"lowerBound",
N->getRawLowerBound());
2335 Printer.printMetadata(
"upperBound",
N->getRawUpperBound());
2336 Printer.printMetadata(
"stride",
N->getRawStride());
2337 Printer.printMetadata(
"bias",
N->getRawBias());
2342 AsmWriterContext &WriterCtx) {
2343 Out <<
"!DICompositeType(";
2344 MDFieldPrinter
Printer(Out, WriterCtx);
2346 Printer.printString(
"name",
N->getName());
2347 Printer.printMetadata(
"scope",
N->getRawScope());
2348 Printer.printMetadata(
"file",
N->getRawFile());
2349 Printer.printInt(
"line",
N->getLine());
2350 Printer.printMetadata(
"baseType",
N->getRawBaseType());
2351 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2352 Printer.printInt(
"align",
N->getAlignInBits());
2353 Printer.printMetadataOrInt(
"offset",
N->getRawOffsetInBits(),
true);
2354 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2355 Printer.printDIFlags(
"flags",
N->getFlags());
2356 Printer.printMetadata(
"elements",
N->getRawElements());
2357 Printer.printDwarfEnum(
"runtimeLang",
N->getRuntimeLang(),
2359 Printer.printMetadata(
"vtableHolder",
N->getRawVTableHolder());
2360 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2361 Printer.printString(
"identifier",
N->getIdentifier());
2362 Printer.printMetadata(
"discriminator",
N->getRawDiscriminator());
2363 Printer.printMetadata(
"dataLocation",
N->getRawDataLocation());
2364 Printer.printMetadata(
"associated",
N->getRawAssociated());
2365 Printer.printMetadata(
"allocated",
N->getRawAllocated());
2366 if (
auto *RankConst =
N->getRankConst())
2367 Printer.printInt(
"rank", RankConst->getSExtValue(),
2370 Printer.printMetadata(
"rank",
N->getRawRank(),
true);
2371 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2372 if (
auto *Specification =
N->getRawSpecification())
2373 Printer.printMetadata(
"specification", Specification);
2375 if (
auto EnumKind =
N->getEnumKind())
2379 Printer.printMetadata(
"bitStride",
N->getRawBitStride());
2384 AsmWriterContext &WriterCtx) {
2385 Out <<
"!DISubroutineType(";
2386 MDFieldPrinter
Printer(Out, WriterCtx);
2387 Printer.printDIFlags(
"flags",
N->getFlags());
2389 Printer.printMetadata(
"types",
N->getRawTypeArray(),
2397 Printer.printString(
"filename",
N->getFilename(),
2399 Printer.printString(
"directory",
N->getDirectory(),
2402 if (
N->getChecksum())
2403 Printer.printChecksum(*
N->getChecksum());
2405 Printer.printString(
"source", *
N->getSource(),
2411 AsmWriterContext &WriterCtx) {
2412 Out <<
"!DICompileUnit(";
2413 MDFieldPrinter
Printer(Out, WriterCtx);
2414 Printer.printDwarfEnum(
"language",
N->getSourceLanguage(),
2416 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2417 Printer.printString(
"producer",
N->getProducer());
2418 Printer.printBool(
"isOptimized",
N->isOptimized());
2419 Printer.printString(
"flags",
N->getFlags());
2420 Printer.printInt(
"runtimeVersion",
N->getRuntimeVersion(),
2422 Printer.printString(
"splitDebugFilename",
N->getSplitDebugFilename());
2423 Printer.printEmissionKind(
"emissionKind",
N->getEmissionKind());
2424 Printer.printMetadata(
"enums",
N->getRawEnumTypes());
2425 Printer.printMetadata(
"retainedTypes",
N->getRawRetainedTypes());
2426 Printer.printMetadata(
"globals",
N->getRawGlobalVariables());
2427 Printer.printMetadata(
"imports",
N->getRawImportedEntities());
2428 Printer.printMetadata(
"macros",
N->getRawMacros());
2429 Printer.printInt(
"dwoId",
N->getDWOId());
2430 Printer.printBool(
"splitDebugInlining",
N->getSplitDebugInlining(),
true);
2431 Printer.printBool(
"debugInfoForProfiling",
N->getDebugInfoForProfiling(),
2433 Printer.printNameTableKind(
"nameTableKind",
N->getNameTableKind());
2434 Printer.printBool(
"rangesBaseAddress",
N->getRangesBaseAddress(),
false);
2435 Printer.printString(
"sysroot",
N->getSysRoot());
2436 Printer.printString(
"sdk",
N->getSDK());
2441 AsmWriterContext &WriterCtx) {
2442 Out <<
"!DISubprogram(";
2443 MDFieldPrinter
Printer(Out, WriterCtx);
2444 Printer.printString(
"name",
N->getName());
2445 Printer.printString(
"linkageName",
N->getLinkageName());
2446 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2447 Printer.printMetadata(
"file",
N->getRawFile());
2448 Printer.printInt(
"line",
N->getLine());
2449 Printer.printMetadata(
"type",
N->getRawType());
2450 Printer.printInt(
"scopeLine",
N->getScopeLine());
2451 Printer.printMetadata(
"containingType",
N->getRawContainingType());
2452 if (
N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
2453 N->getVirtualIndex() != 0)
2454 Printer.printInt(
"virtualIndex",
N->getVirtualIndex(),
false);
2455 Printer.printInt(
"thisAdjustment",
N->getThisAdjustment());
2456 Printer.printDIFlags(
"flags",
N->getFlags());
2457 Printer.printDISPFlags(
"spFlags",
N->getSPFlags());
2458 Printer.printMetadata(
"unit",
N->getRawUnit());
2459 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2460 Printer.printMetadata(
"declaration",
N->getRawDeclaration());
2461 Printer.printMetadata(
"retainedNodes",
N->getRawRetainedNodes());
2462 Printer.printMetadata(
"thrownTypes",
N->getRawThrownTypes());
2463 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2464 Printer.printString(
"targetFuncName",
N->getTargetFuncName());
2465 Printer.printBool(
"keyInstructions",
N->getKeyInstructionsEnabled(),
false);
2470 AsmWriterContext &WriterCtx) {
2471 Out <<
"!DILexicalBlock(";
2472 MDFieldPrinter
Printer(Out, WriterCtx);
2473 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2474 Printer.printMetadata(
"file",
N->getRawFile());
2475 Printer.printInt(
"line",
N->getLine());
2476 Printer.printInt(
"column",
N->getColumn());
2482 AsmWriterContext &WriterCtx) {
2483 Out <<
"!DILexicalBlockFile(";
2484 MDFieldPrinter
Printer(Out, WriterCtx);
2485 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2486 Printer.printMetadata(
"file",
N->getRawFile());
2487 Printer.printInt(
"discriminator",
N->getDiscriminator(),
2493 AsmWriterContext &WriterCtx) {
2494 Out <<
"!DINamespace(";
2495 MDFieldPrinter
Printer(Out, WriterCtx);
2496 Printer.printString(
"name",
N->getName());
2497 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2498 Printer.printBool(
"exportSymbols",
N->getExportSymbols(),
false);
2503 AsmWriterContext &WriterCtx) {
2504 Out <<
"!DICommonBlock(";
2505 MDFieldPrinter
Printer(Out, WriterCtx);
2506 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2507 Printer.printMetadata(
"declaration",
N->getRawDecl(),
false);
2508 Printer.printString(
"name",
N->getName());
2509 Printer.printMetadata(
"file",
N->getRawFile());
2510 Printer.printInt(
"line",
N->getLineNo());
2515 AsmWriterContext &WriterCtx) {
2517 MDFieldPrinter
Printer(Out, WriterCtx);
2519 Printer.printInt(
"line",
N->getLine());
2520 Printer.printString(
"name",
N->getName());
2521 Printer.printString(
"value",
N->getValue());
2526 AsmWriterContext &WriterCtx) {
2527 Out <<
"!DIMacroFile(";
2528 MDFieldPrinter
Printer(Out, WriterCtx);
2529 Printer.printInt(
"line",
N->getLine());
2530 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2531 Printer.printMetadata(
"nodes",
N->getRawElements());
2536 AsmWriterContext &WriterCtx) {
2537 Out <<
"!DIModule(";
2538 MDFieldPrinter
Printer(Out, WriterCtx);
2539 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2540 Printer.printString(
"name",
N->getName());
2541 Printer.printString(
"configMacros",
N->getConfigurationMacros());
2542 Printer.printString(
"includePath",
N->getIncludePath());
2543 Printer.printString(
"apinotes",
N->getAPINotesFile());
2544 Printer.printMetadata(
"file",
N->getRawFile());
2545 Printer.printInt(
"line",
N->getLineNo());
2546 Printer.printBool(
"isDecl",
N->getIsDecl(),
false);
2552 AsmWriterContext &WriterCtx) {
2553 Out <<
"!DITemplateTypeParameter(";
2554 MDFieldPrinter
Printer(Out, WriterCtx);
2555 Printer.printString(
"name",
N->getName());
2556 Printer.printMetadata(
"type",
N->getRawType(),
false);
2557 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2563 AsmWriterContext &WriterCtx) {
2564 Out <<
"!DITemplateValueParameter(";
2565 MDFieldPrinter
Printer(Out, WriterCtx);
2566 if (
N->getTag() != dwarf::DW_TAG_template_value_parameter)
2568 Printer.printString(
"name",
N->getName());
2569 Printer.printMetadata(
"type",
N->getRawType());
2570 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2571 Printer.printMetadata(
"value",
N->getValue(),
false);
2576 AsmWriterContext &WriterCtx) {
2577 Out <<
"!DIGlobalVariable(";
2578 MDFieldPrinter
Printer(Out, WriterCtx);
2579 Printer.printString(
"name",
N->getName());
2580 Printer.printString(
"linkageName",
N->getLinkageName());
2581 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2582 Printer.printMetadata(
"file",
N->getRawFile());
2583 Printer.printInt(
"line",
N->getLine());
2584 Printer.printMetadata(
"type",
N->getRawType());
2585 Printer.printBool(
"isLocal",
N->isLocalToUnit());
2586 Printer.printBool(
"isDefinition",
N->isDefinition());
2587 Printer.printMetadata(
"declaration",
N->getRawStaticDataMemberDeclaration());
2588 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2589 Printer.printInt(
"align",
N->getAlignInBits());
2590 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2595 AsmWriterContext &WriterCtx) {
2596 Out <<
"!DILocalVariable(";
2597 MDFieldPrinter
Printer(Out, WriterCtx);
2598 Printer.printString(
"name",
N->getName());
2599 Printer.printInt(
"arg",
N->getArg());
2600 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2601 Printer.printMetadata(
"file",
N->getRawFile());
2602 Printer.printInt(
"line",
N->getLine());
2603 Printer.printMetadata(
"type",
N->getRawType());
2604 Printer.printDIFlags(
"flags",
N->getFlags());
2605 Printer.printInt(
"align",
N->getAlignInBits());
2606 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2611 AsmWriterContext &WriterCtx) {
2613 MDFieldPrinter
Printer(Out, WriterCtx);
2614 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2615 Printer.printString(
"name",
N->getName());
2616 Printer.printMetadata(
"file",
N->getRawFile());
2617 Printer.printInt(
"line",
N->getLine());
2618 Printer.printInt(
"column",
N->getColumn());
2619 Printer.printBool(
"isArtificial",
N->isArtificial(),
false);
2620 if (
N->getCoroSuspendIdx())
2621 Printer.printInt(
"coroSuspendIdx", *
N->getCoroSuspendIdx(),
2627 AsmWriterContext &WriterCtx) {
2628 Out <<
"!DIExpression(";
2633 assert(!OpStr.empty() &&
"Expected valid opcode");
2637 Out << FS <<
Op.getArg(0);
2640 for (
unsigned A = 0, AE =
Op.getNumArgs();
A != AE; ++
A)
2641 Out << FS <<
Op.getArg(
A);
2645 for (
const auto &
I :
N->getElements())
2652 AsmWriterContext &WriterCtx,
2653 bool FromValue =
false) {
2655 "Unexpected DIArgList metadata outside of value argument");
2656 Out <<
"!DIArgList(";
2658 MDFieldPrinter
Printer(Out, WriterCtx);
2668 AsmWriterContext &WriterCtx) {
2669 Out <<
"!DIGlobalVariableExpression(";
2670 MDFieldPrinter
Printer(Out, WriterCtx);
2671 Printer.printMetadata(
"var",
N->getVariable());
2672 Printer.printMetadata(
"expr",
N->getExpression());
2677 AsmWriterContext &WriterCtx) {
2678 Out <<
"!DIObjCProperty(";
2679 MDFieldPrinter
Printer(Out, WriterCtx);
2680 Printer.printString(
"name",
N->getName());
2681 Printer.printMetadata(
"file",
N->getRawFile());
2682 Printer.printInt(
"line",
N->getLine());
2683 Printer.printString(
"setter",
N->getSetterName());
2684 Printer.printString(
"getter",
N->getGetterName());
2685 Printer.printInt(
"attributes",
N->getAttributes());
2686 Printer.printMetadata(
"type",
N->getRawType());
2691 AsmWriterContext &WriterCtx) {
2692 Out <<
"!DIImportedEntity(";
2693 MDFieldPrinter
Printer(Out, WriterCtx);
2695 Printer.printString(
"name",
N->getName());
2696 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2697 Printer.printMetadata(
"entity",
N->getRawEntity());
2698 Printer.printMetadata(
"file",
N->getRawFile());
2699 Printer.printInt(
"line",
N->getLine());
2700 Printer.printMetadata(
"elements",
N->getRawElements());
2705 AsmWriterContext &Ctx) {
2706 if (
Node->isDistinct())
2708 else if (
Node->isTemporary())
2709 Out <<
"<temporary!> ";
2711 switch (
Node->getMetadataID()) {
2714#define HANDLE_MDNODE_LEAF(CLASS) \
2715 case Metadata::CLASS##Kind: \
2716 write##CLASS(Out, cast<CLASS>(Node), Ctx); \
2718#include "llvm/IR/Metadata.def"
2725 AsmWriterContext &WriterCtx) {
2731 const Constant *CV = dyn_cast<Constant>(V);
2732 if (CV && !isa<GlobalValue>(CV)) {
2733 assert(WriterCtx.TypePrinter &&
"Constants require TypePrinting!");
2738 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2740 if (IA->hasSideEffects())
2741 Out <<
"sideeffect ";
2742 if (IA->isAlignStack())
2743 Out <<
"alignstack ";
2746 Out <<
"inteldialect ";
2750 printEscapedString(IA->getAsmString(), Out);
2752 printEscapedString(IA->getConstraintString(), Out);
2757 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2765 auto *
Machine = WriterCtx.Machine;
2768 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2769 Slot =
Machine->getGlobalSlot(GV);
2772 Slot =
Machine->getLocalSlot(V);
2779 Slot =
Machine->getLocalSlot(V);
2785 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2786 Slot =
Machine->getGlobalSlot(GV);
2789 Slot =
Machine->getLocalSlot(V);
2798 Out << Prefix << Slot;
2804 AsmWriterContext &WriterCtx,
2808 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2812 if (
const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) {
2817 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2818 std::unique_ptr<SlotTracker> MachineStorage;
2820 if (!WriterCtx.Machine) {
2821 MachineStorage = std::make_unique<SlotTracker>(WriterCtx.Context);
2822 WriterCtx.Machine = MachineStorage.get();
2824 int Slot = WriterCtx.Machine->getMetadataSlot(
N);
2826 if (
const DILocation *Loc = dyn_cast<DILocation>(
N)) {
2832 Out <<
"<" <<
N <<
">";
2838 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2840 printEscapedString(MDS->getString(), Out);
2845 auto *V = cast<ValueAsMetadata>(MD);
2846 assert(WriterCtx.TypePrinter &&
"TypePrinter required for metadata values");
2847 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2848 "Unexpected function-local metadata outside of value argument");
2850 WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);
2857class AssemblyWriter {
2859 const Module *TheModule =
nullptr;
2861 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2863 TypePrinting TypePrinter;
2867 bool ShouldPreserveUseListOrder;
2878 bool ShouldPreserveUseListOrder =
false);
2883 AsmWriterContext getContext() {
2884 return AsmWriterContext(&TypePrinter, &
Machine, TheModule);
2887 void printMDNodeBody(
const MDNode *MD);
2890 void printModule(
const Module *M);
2892 void writeOperand(
const Value *
Op,
bool PrintType);
2894 void writeOperandBundles(
const CallBase *Call);
2900 void writeAtomicCmpXchg(
const LLVMContext &Context,
2905 void writeAllMDNodes();
2906 void writeMDNode(
unsigned Slot,
const MDNode *
Node);
2907 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
2908 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
2909 void writeAllAttributeGroups();
2911 void printTypeIdentities();
2915 void printComdat(
const Comdat *
C);
2921 void printDbgMarker(
const DbgMarker &DPI);
2924 void printDbgRecord(
const DbgRecord &DR);
2925 void printDbgRecordLine(
const DbgRecord &DR);
2927 void printUseListOrder(
const Value *V,
const std::vector<unsigned> &Shuffle);
2930 void printModuleSummaryIndex();
2931 void printSummaryInfo(
unsigned Slot,
const ValueInfo &VI);
2939 void printArgs(
const std::vector<uint64_t> &Args);
2944 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> &VCallList,
2947 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> &VCallList,
2952 void printMetadataAttachments(
2958 void printInfoComment(
const Value &V);
2969 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2970 : Out(
o), TheModule(
M),
Machine(Mac), TypePrinter(
M), AnnotationWriter(AAW),
2971 IsForDebug(IsForDebug),
2972 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2975 for (
const GlobalObject &GO : TheModule->global_objects())
2982 : Out(
o), TheIndex(
Index),
Machine(Mac), TypePrinter(nullptr),
2983 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2985void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2987 Out <<
"<null operand!>";
2991 TypePrinter.print(Operand->
getType(), Out);
2994 auto WriterCtx = getContext();
2998void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
3006 Context.getSyncScopeNames(SSNs);
3008 Out <<
" syncscope(\"";
3009 printEscapedString(SSNs[SSID], Out);
3016void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
3019 if (Ordering == AtomicOrdering::NotAtomic)
3022 writeSyncScope(Context, SSID);
3026void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
3030 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
3031 FailureOrdering != AtomicOrdering::NotAtomic);
3033 writeSyncScope(Context, SSID);
3038void AssemblyWriter::writeParamOperand(
const Value *Operand,
3041 Out <<
"<null operand!>";
3046 TypePrinter.print(Operand->
getType(), Out);
3048 if (
Attrs.hasAttributes()) {
3050 writeAttributeSet(Attrs);
3054 auto WriterCtx = getContext();
3058void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
3059 if (!
Call->hasOperandBundles())
3064 bool FirstBundle =
true;
3065 for (
unsigned i = 0, e =
Call->getNumOperandBundles(); i != e; ++i) {
3070 FirstBundle =
false;
3078 bool FirstInput =
true;
3079 auto WriterCtx = getContext();
3080 for (
const auto &Input : BU.
Inputs) {
3085 if (Input ==
nullptr)
3086 Out <<
"<null operand bundle!>";
3088 TypePrinter.print(Input->getType(), Out);
3100void AssemblyWriter::printModule(
const Module *M) {
3103 if (ShouldPreserveUseListOrder)
3106 if (!
M->getModuleIdentifier().empty() &&
3109 M->getModuleIdentifier().find(
'\n') == std::string::npos)
3110 Out <<
"; ModuleID = '" <<
M->getModuleIdentifier() <<
"'\n";
3112 if (!
M->getSourceFileName().empty()) {
3113 Out <<
"source_filename = \"";
3114 printEscapedString(
M->getSourceFileName(), Out);
3118 const std::string &
DL =
M->getDataLayoutStr();
3120 Out <<
"target datalayout = \"" <<
DL <<
"\"\n";
3121 if (!
M->getTargetTriple().empty())
3122 Out <<
"target triple = \"" <<
M->getTargetTriple().str() <<
"\"\n";
3124 if (!
M->getModuleInlineAsm().empty()) {
3131 std::tie(Front, Asm) =
Asm.split(
'\n');
3135 Out <<
"module asm \"";
3136 printEscapedString(Front, Out);
3138 }
while (!
Asm.empty());
3141 printTypeIdentities();
3144 if (!Comdats.empty())
3146 for (
const Comdat *
C : Comdats) {
3148 if (
C != Comdats.back())
3153 if (!
M->global_empty()) Out <<
'\n';
3155 printGlobal(&GV); Out <<
'\n';
3159 if (!
M->alias_empty()) Out <<
"\n";
3164 if (!
M->ifunc_empty()) Out <<
"\n";
3175 printUseLists(
nullptr);
3180 writeAllAttributeGroups();
3184 if (!
M->named_metadata_empty()) Out <<
'\n';
3187 printNamedMDNode(&
Node);
3196void AssemblyWriter::printModuleSummaryIndex() {
3198 int NumSlots =
Machine.initializeIndexIfNeeded();
3204 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
3205 std::string RegularLTOModuleName =
3207 moduleVec.resize(TheIndex->modulePaths().size());
3208 for (
auto &[ModPath, ModHash] : TheIndex->modulePaths())
3209 moduleVec[
Machine.getModulePathSlot(ModPath)] = std::make_pair(
3212 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
3215 for (
auto &ModPair : moduleVec) {
3216 Out <<
"^" << i++ <<
" = module: (";
3218 printEscapedString(ModPair.first, Out);
3219 Out <<
"\", hash: (";
3221 for (
auto Hash : ModPair.second)
3228 for (
auto &GlobalList : *TheIndex) {
3229 auto GUID = GlobalList.first;
3230 for (
auto &Summary : GlobalList.second.SummaryList)
3235 for (
auto &GlobalList : *TheIndex) {
3236 auto GUID = GlobalList.first;
3237 auto VI = TheIndex->getValueInfo(GlobalList);
3238 printSummaryInfo(
Machine.getGUIDSlot(GUID), VI);
3242 for (
const auto &TID : TheIndex->typeIds()) {
3243 Out <<
"^" <<
Machine.getTypeIdSlot(TID.second.first)
3244 <<
" = typeid: (name: \"" << TID.second.first <<
"\"";
3245 printTypeIdSummary(TID.second.second);
3246 Out <<
") ; guid = " << TID.first <<
"\n";
3250 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
3252 Out <<
"^" <<
Machine.getTypeIdCompatibleVtableSlot(TId.first)
3253 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
3254 printTypeIdCompatibleVtableSummary(TId.second);
3255 Out <<
") ; guid = " <<
GUID <<
"\n";
3259 if (TheIndex->getFlags()) {
3260 Out <<
"^" << NumSlots <<
" = flags: " << TheIndex->getFlags() <<
"\n";
3264 Out <<
"^" << NumSlots <<
" = blockcount: " << TheIndex->getBlockCount()
3274 return "singleImpl";
3276 return "branchFunnel";
3287 return "uniformRetVal";
3289 return "uniqueRetVal";
3291 return "virtualConstProp";
3321 Out <<
", alignLog2: " << TTRes.
AlignLog2;
3323 Out <<
", sizeM1: " << TTRes.
SizeM1;
3333void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
3334 Out <<
", summary: (";
3335 printTypeTestResolution(TIS.
TTRes);
3336 if (!TIS.
WPDRes.empty()) {
3337 Out <<
", wpdResolutions: (";
3339 for (
auto &WPDRes : TIS.
WPDRes) {
3341 Out <<
"(offset: " << WPDRes.first <<
", ";
3342 printWPDRes(WPDRes.second);
3350void AssemblyWriter::printTypeIdCompatibleVtableSummary(
3352 Out <<
", summary: (";
3354 for (
auto &
P : TI) {
3356 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
3357 Out <<
"^" <<
Machine.getGUIDSlot(
P.VTableVI.getGUID());
3363void AssemblyWriter::printArgs(
const std::vector<uint64_t> &Args) {
3366 for (
auto arg : Args) {
3374 Out <<
"wpdRes: (kind: ";
3381 Out <<
", resByArg: (";
3383 for (
auto &ResByArg : WPDRes.
ResByArg) {
3385 printArgs(ResByArg.first);
3386 Out <<
", byArg: (kind: ";
3388 if (ResByArg.second.TheKind ==
3390 ResByArg.second.TheKind ==
3392 Out <<
", info: " << ResByArg.second.Info;
3396 if (ResByArg.second.Byte || ResByArg.second.Bit)
3397 Out <<
", byte: " << ResByArg.second.Byte
3398 <<
", bit: " << ResByArg.second.Bit;
3419void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
3420 Out <<
", aliasee: ";
3431 auto VTableFuncs =
GS->vTableFuncs();
3432 Out <<
", varFlags: (readonly: " <<
GS->VarFlags.MaybeReadOnly <<
", "
3433 <<
"writeonly: " <<
GS->VarFlags.MaybeWriteOnly <<
", "
3434 <<
"constant: " <<
GS->VarFlags.Constant;
3435 if (!VTableFuncs.empty())
3437 <<
"vcall_visibility: " <<
GS->VarFlags.VCallVisibility;
3440 if (!VTableFuncs.empty()) {
3441 Out <<
", vTableFuncs: (";
3443 for (
auto &
P : VTableFuncs) {
3445 Out <<
"(virtFunc: ^" <<
Machine.getGUIDSlot(
P.FuncVI.getGUID())
3446 <<
", offset: " <<
P.VTableOffset;
3464 return "linkonce_odr";
3474 return "extern_weak";
3476 return "available_externally";
3505 return "definition";
3507 return "declaration";
3513 Out <<
", insts: " <<
FS->instCount();
3514 if (
FS->fflags().anyFlagSet())
3515 Out <<
", " <<
FS->fflags();
3517 if (!
FS->calls().empty()) {
3518 Out <<
", calls: (";
3520 for (
auto &Call :
FS->calls()) {
3522 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.first.getGUID());
3523 if (
Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)
3525 else if (
Call.second.RelBlockFreq)
3526 Out <<
", relbf: " <<
Call.second.RelBlockFreq;
3529 if (
Call.second.HasTailCall)
3536 if (
const auto *TIdInfo =
FS->getTypeIdInfo())
3537 printTypeIdInfo(*TIdInfo);
3541 auto AllocTypeName = [](
uint8_t Type) ->
const char * {
3543 case (
uint8_t)AllocationType::None:
3545 case (
uint8_t)AllocationType::NotCold:
3547 case (
uint8_t)AllocationType::Cold:
3549 case (
uint8_t)AllocationType::Hot:
3555 if (!
FS->allocs().empty()) {
3556 Out <<
", allocs: (";
3558 for (
auto &AI :
FS->allocs()) {
3560 Out <<
"(versions: (";
3562 for (
auto V : AI.Versions) {
3564 Out << AllocTypeName(V);
3566 Out <<
"), memProf: (";
3567 FieldSeparator MIBFS;
3568 for (
auto &MIB : AI.MIBs) {
3570 Out <<
"(type: " << AllocTypeName((
uint8_t)MIB.AllocType);
3571 Out <<
", stackIds: (";
3572 FieldSeparator SIDFS;
3573 for (
auto Id : MIB.StackIdIndices) {
3575 Out << TheIndex->getStackIdAtIndex(Id);
3584 if (!
FS->callsites().empty()) {
3585 Out <<
", callsites: (";
3586 FieldSeparator SNFS;
3587 for (
auto &CI :
FS->callsites()) {
3590 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(CI.Callee.getGUID());
3592 Out <<
"(callee: null";
3593 Out <<
", clones: (";
3595 for (
auto V : CI.Clones) {
3599 Out <<
"), stackIds: (";
3600 FieldSeparator SIDFS;
3601 for (
auto Id : CI.StackIdIndices) {
3603 Out << TheIndex->getStackIdAtIndex(Id);
3614 if (!
FS->paramAccesses().empty()) {
3615 Out <<
", params: (";
3617 for (
auto &PS :
FS->paramAccesses()) {
3619 Out <<
"(param: " << PS.ParamNo;
3620 Out <<
", offset: ";
3622 if (!PS.Calls.empty()) {
3623 Out <<
", calls: (";
3625 for (
auto &Call : PS.Calls) {
3627 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.Callee.getGUID());
3628 Out <<
", param: " <<
Call.ParamNo;
3629 Out <<
", offset: ";
3630 PrintRange(
Call.Offsets);
3641void AssemblyWriter::printTypeIdInfo(
3643 Out <<
", typeIdInfo: (";
3644 FieldSeparator TIDFS;
3647 Out <<
"typeTests: (";
3650 auto TidIter = TheIndex->typeIds().equal_range(GUID);
3651 if (TidIter.first == TidIter.second) {
3657 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3659 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3677 "typeTestAssumeConstVCalls");
3682 "typeCheckedLoadConstVCalls");
3688 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
3689 if (TidIter.first == TidIter.second) {
3690 Out <<
"vFuncId: (";
3691 Out <<
"guid: " << VFId.
GUID;
3692 Out <<
", offset: " << VFId.
Offset;
3698 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3700 Out <<
"vFuncId: (";
3701 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3704 Out <<
", offset: " << VFId.
Offset;
3709void AssemblyWriter::printNonConstVCalls(
3710 const std::vector<FunctionSummary::VFuncId> &VCallList,
const char *Tag) {
3711 Out <<
Tag <<
": (";
3713 for (
auto &VFuncId : VCallList) {
3715 printVFuncId(VFuncId);
3720void AssemblyWriter::printConstVCalls(
3721 const std::vector<FunctionSummary::ConstVCall> &VCallList,
3723 Out <<
Tag <<
": (";
3725 for (
auto &ConstVCall : VCallList) {
3728 printVFuncId(ConstVCall.VFunc);
3729 if (!ConstVCall.Args.empty()) {
3731 printArgs(ConstVCall.Args);
3742 Out <<
"(module: ^" <<
Machine.getModulePathSlot(
Summary.modulePath())
3745 Out <<
", visibility: "
3748 Out <<
", live: " << GVFlags.
Live;
3749 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3751 Out <<
", importType: "
3756 printAliasSummary(cast<AliasSummary>(&Summary));
3758 printFunctionSummary(cast<FunctionSummary>(&Summary));
3760 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3762 auto RefList =
Summary.refs();
3763 if (!RefList.empty()) {
3766 for (
auto &
Ref : RefList) {
3768 if (
Ref.isReadOnly())
3770 else if (
Ref.isWriteOnly())
3771 Out <<
"writeonly ";
3772 Out <<
"^" <<
Machine.getGUIDSlot(
Ref.getGUID());
3780void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &VI) {
3781 Out <<
"^" <<
Slot <<
" = gv: (";
3782 if (
VI.hasName() && !
VI.name().empty())
3783 Out <<
"name: \"" <<
VI.name() <<
"\"";
3785 Out <<
"guid: " <<
VI.getGUID();
3786 if (!
VI.getSummaryList().empty()) {
3787 Out <<
", summaries: (";
3789 for (
auto &Summary :
VI.getSummaryList()) {
3791 printSummary(*Summary);
3796 if (
VI.hasName() && !
VI.name().empty())
3797 Out <<
" ; guid = " <<
VI.getGUID();
3804 Out <<
"<empty name> ";
3806 unsigned char FirstC =
static_cast<unsigned char>(
Name[0]);
3807 if (isalpha(FirstC) || FirstC ==
'-' || FirstC ==
'$' || FirstC ==
'.' ||
3811 Out <<
'\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);
3812 for (
unsigned i = 1, e =
Name.size(); i != e; ++i) {
3813 unsigned char C =
Name[i];
3814 if (isalnum(
C) ||
C ==
'-' ||
C ==
'$' ||
C ==
'.' ||
C ==
'_')
3817 Out <<
'\\' << hexdigit(
C >> 4) << hexdigit(
C & 0x0F);
3822void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3833 if (
auto *Expr = dyn_cast<DIExpression>(
Op)) {
3859 Out <<
"dso_local ";
3874 case GlobalVariable::NotThreadLocal:
3876 case GlobalVariable::GeneralDynamicTLSModel:
3877 Out <<
"thread_local ";
3879 case GlobalVariable::LocalDynamicTLSModel:
3880 Out <<
"thread_local(localdynamic) ";
3882 case GlobalVariable::InitialExecTLSModel:
3883 Out <<
"thread_local(initialexec) ";
3885 case GlobalVariable::LocalExecTLSModel:
3886 Out <<
"thread_local(localexec) ";
3893 case GlobalVariable::UnnamedAddr::None:
3895 case GlobalVariable::UnnamedAddr::Local:
3896 return "local_unnamed_addr";
3897 case GlobalVariable::UnnamedAddr::Global:
3898 return "unnamed_addr";
3909 if (isa<GlobalVariable>(GO))
3923 Out <<
"; Materializable\n";
3944 Out << (GV->
isConstant() ?
"constant " :
"global ");
3953 Out <<
", section \"";
3958 Out <<
", partition \"";
3963 Out <<
", code_model \"";
3988 Out <<
", no_sanitize_address";
3990 Out <<
", no_sanitize_hwaddress";
3992 Out <<
", sanitize_memtag";
3994 Out <<
", sanitize_address_dyninit";
3999 Out <<
", align " <<
A->value();
4003 printMetadataAttachments(MDs,
", ");
4006 if (
Attrs.hasAttributes())
4007 Out <<
" #" <<
Machine.getAttributeGroupSlot(Attrs);
4009 printInfoComment(*GV);
4012void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
4014 Out <<
"; Materializable\n";
4035 writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
4037 TypePrinter.print(GA->
getType(), Out);
4038 Out <<
" <<NULL ALIASEE>>";
4042 Out <<
", partition \"";
4047 printInfoComment(*GA);
4051void AssemblyWriter::printIFunc(
const GlobalIFunc *GI) {
4053 Out <<
"; Materializable\n";
4071 TypePrinter.print(GI->
getType(), Out);
4072 Out <<
" <<NULL RESOLVER>>";
4076 Out <<
", partition \"";
4081 printInfoComment(*GI);
4085void AssemblyWriter::printComdat(
const Comdat *
C) {
4089void AssemblyWriter::printTypeIdentities() {
4090 if (TypePrinter.empty())
4096 auto &NumberedTypes = TypePrinter.getNumberedTypes();
4097 for (
unsigned I = 0, E = NumberedTypes.size();
I != E; ++
I) {
4098 Out <<
'%' <<
I <<
" = type ";
4102 TypePrinter.printStructBody(NumberedTypes[
I], Out);
4106 auto &NamedTypes = TypePrinter.getNamedTypes();
4113 TypePrinter.printStructBody(NamedType, Out);
4119void AssemblyWriter::printFunction(
const Function *
F) {
4120 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(
F, Out);
4122 if (
F->isMaterializable())
4123 Out <<
"; Materializable\n";
4126 if (
Attrs.hasFnAttrs()) {
4128 std::string AttrStr;
4131 if (!Attr.isStringAttribute()) {
4132 if (!AttrStr.empty()) AttrStr +=
' ';
4133 AttrStr += Attr.getAsString();
4137 if (!AttrStr.empty())
4138 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
4142 Out <<
"; Unknown intrinsic\n";
4146 if (
F->isDeclaration()) {
4149 F->getAllMetadata(MDs);
4150 printMetadataAttachments(MDs,
" ");
4167 if (
Attrs.hasRetAttrs())
4169 TypePrinter.print(
F->getReturnType(), Out);
4170 AsmWriterContext WriterCtx(&TypePrinter, &
Machine,
F->getParent());
4176 if (
F->isDeclaration() && !IsForDebug) {
4178 for (
unsigned I = 0, E = FT->getNumParams();
I != E; ++
I) {
4183 TypePrinter.print(FT->getParamType(
I), Out);
4188 writeAttributeSet(ArgAttrs);
4195 if (Arg.getArgNo() != 0)
4197 printArgument(&Arg,
Attrs.getParamAttrs(Arg.getArgNo()));
4202 if (FT->isVarArg()) {
4203 if (FT->getNumParams()) Out <<
", ";
4214 if (
F->getAddressSpace() != 0 || !
Mod ||
4215 Mod->getDataLayout().getProgramAddressSpace() != 0)
4216 Out <<
" addrspace(" <<
F->getAddressSpace() <<
")";
4217 if (
Attrs.hasFnAttrs())
4218 Out <<
" #" <<
Machine.getAttributeGroupSlot(
Attrs.getFnAttrs());
4219 if (
F->hasSection()) {
4220 Out <<
" section \"";
4221 printEscapedString(
F->getSection(), Out);
4224 if (
F->hasPartition()) {
4225 Out <<
" partition \"";
4226 printEscapedString(
F->getPartition(), Out);
4231 Out <<
" align " <<
A->value();
4233 Out <<
" gc \"" <<
F->getGC() <<
'"';
4234 if (
F->hasPrefixData()) {
4236 writeOperand(
F->getPrefixData(),
true);
4238 if (
F->hasPrologueData()) {
4239 Out <<
" prologue ";
4240 writeOperand(
F->getPrologueData(),
true);
4242 if (
F->hasPersonalityFn()) {
4243 Out <<
" personality ";
4244 writeOperand(
F->getPersonalityFn(),
true);
4248 if (
auto *MDProf =
F->getMetadata(LLVMContext::MD_prof)) {
4250 MDProf->print(Out, TheModule,
true);
4254 if (
F->isDeclaration()) {
4258 F->getAllMetadata(MDs);
4259 printMetadataAttachments(MDs,
" ");
4264 printBasicBlock(&BB);
4279 TypePrinter.print(Arg->
getType(), Out);
4282 if (
Attrs.hasAttributes()) {
4284 writeAttributeSet(Attrs);
4293 assert(Slot != -1 &&
"expect argument in function here");
4294 Out <<
" %" <<
Slot;
4299void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
4305 }
else if (!IsEntryBlock) {
4314 if (!IsEntryBlock) {
4316 Out.PadToColumn(50);
4321 Out <<
" No predecessors!";
4324 writeOperand(*PI,
false);
4325 for (++PI; PI != PE; ++PI) {
4327 writeOperand(*PI,
false);
4334 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
4338 for (
const DbgRecord &DR :
I.getDbgRecordRange())
4339 printDbgRecordLine(DR);
4340 printInstructionLine(
I);
4343 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
4347void AssemblyWriter::printInstructionLine(
const Instruction &
I) {
4348 printInstruction(
I);
4354void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
4364void AssemblyWriter::printInfoComment(
const Value &V) {
4365 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
4366 printGCRelocateComment(*Relocate);
4368 if (AnnotationWriter) {
4369 AnnotationWriter->printInfoComment(V, Out);
4373 if (
auto *
I = dyn_cast<Instruction>(&V)) {
4374 if (
I->getDebugLoc()) {
4376 I->getDebugLoc().print(Out);
4381 if (
auto *
I = dyn_cast<Instruction>(&V)) {
4382 if (
auto *MD =
I->getMetadata(LLVMContext::MD_prof)) {
4384 MD->print(Out, TheModule,
true);
4396 if (Operand ==
nullptr) {
4397 Out <<
" <cannot get addrspace!>";
4401 bool PrintAddrSpace = CallAddrSpace != 0;
4402 if (!PrintAddrSpace) {
4407 if (!
Mod ||
Mod->getDataLayout().getProgramAddressSpace() != 0)
4408 PrintAddrSpace =
true;
4411 Out <<
" addrspace(" << CallAddrSpace <<
")";
4415void AssemblyWriter::printInstruction(
const Instruction &
I) {
4416 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&
I, Out);
4425 }
else if (!
I.getType()->isVoidTy()) {
4427 int SlotNum =
Machine.getLocalSlot(&
I);
4429 Out <<
"<badref> = ";
4431 Out <<
'%' << SlotNum <<
" = ";
4434 if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4435 if (CI->isMustTailCall())
4437 else if (CI->isTailCall())
4439 else if (CI->isNoTailCall())
4444 Out <<
I.getOpcodeName();
4447 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isAtomic()) ||
4448 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isAtomic()))
4451 if (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isWeak())
4455 if ((isa<LoadInst>(
I) && cast<LoadInst>(
I).isVolatile()) ||
4456 (isa<StoreInst>(
I) && cast<StoreInst>(
I).isVolatile()) ||
4457 (isa<AtomicCmpXchgInst>(
I) && cast<AtomicCmpXchgInst>(
I).isVolatile()) ||
4458 (isa<AtomicRMWInst>(
I) && cast<AtomicRMWInst>(
I).isVolatile()))
4465 if (
const CmpInst *CI = dyn_cast<CmpInst>(&
I))
4466 Out <<
' ' << CI->getPredicate();
4473 const Value *Operand =
I.getNumOperands() ?
I.getOperand(0) :
nullptr;
4476 if (isa<BranchInst>(
I) && cast<BranchInst>(
I).isConditional()) {
4479 writeOperand(BI.getCondition(),
true);
4481 writeOperand(BI.getSuccessor(0),
true);
4483 writeOperand(BI.getSuccessor(1),
true);
4485 }
else if (isa<SwitchInst>(
I)) {
4489 writeOperand(
SI.getCondition(),
true);
4491 writeOperand(
SI.getDefaultDest(),
true);
4493 for (
auto Case :
SI.cases()) {
4495 writeOperand(Case.getCaseValue(),
true);
4497 writeOperand(Case.getCaseSuccessor(),
true);
4500 }
else if (isa<IndirectBrInst>(
I)) {
4503 writeOperand(Operand,
true);
4506 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i) {
4509 writeOperand(
I.getOperand(i),
true);
4512 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&
I)) {
4514 TypePrinter.print(
I.getType(), Out);
4517 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
4518 if (
op) Out <<
", ";
4520 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
4521 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
4525 writeOperand(
I.getOperand(0),
true);
4526 for (
unsigned i : EVI->indices())
4530 writeOperand(
I.getOperand(0),
true); Out <<
", ";
4531 writeOperand(
I.getOperand(1),
true);
4532 for (
unsigned i : IVI->indices())
4534 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&
I)) {
4536 TypePrinter.print(
I.getType(), Out);
4537 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
4540 if (LPI->isCleanup())
4543 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
4544 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
4545 if (LPI->isCatch(i))
4550 writeOperand(LPI->getClause(i),
true);
4552 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&
I)) {
4554 writeOperand(CatchSwitch->getParentPad(),
false);
4557 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
4560 writeOperand(PadBB,
true);
4564 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
4565 writeOperand(UnwindDest,
true);
4568 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&
I)) {
4570 writeOperand(FPI->getParentPad(),
false);
4572 for (
unsigned Op = 0, NumOps = FPI->arg_size();
Op < NumOps; ++
Op) {
4575 writeOperand(FPI->getArgOperand(
Op),
true);
4578 }
else if (isa<ReturnInst>(
I) && !Operand) {
4580 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&
I)) {
4582 writeOperand(CRI->getOperand(0),
false);
4585 writeOperand(CRI->getOperand(1),
true);
4586 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&
I)) {
4588 writeOperand(CRI->getOperand(0),
false);
4591 if (CRI->hasUnwindDest())
4592 writeOperand(CRI->getOperand(1),
true);
4595 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
4602 Operand = CI->getCalledOperand();
4617 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4619 writeOperand(Operand,
false);
4621 for (
unsigned op = 0, Eop = CI->arg_size();
op < Eop; ++
op) {
4629 if (CI->isMustTailCall() && CI->getParent() &&
4630 CI->getParent()->getParent() &&
4631 CI->getParent()->getParent()->isVarArg()) {
4632 if (CI->arg_size() > 0)
4641 writeOperandBundles(CI);
4642 }
else if (
const InvokeInst *
II = dyn_cast<InvokeInst>(&
I)) {
4643 Operand =
II->getCalledOperand();
4665 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4667 writeOperand(Operand,
false);
4669 for (
unsigned op = 0, Eop =
II->arg_size();
op < Eop; ++
op) {
4679 writeOperandBundles(
II);
4682 writeOperand(
II->getNormalDest(),
true);
4684 writeOperand(
II->getUnwindDest(),
true);
4685 }
else if (
const CallBrInst *CBI = dyn_cast<CallBrInst>(&
I)) {
4686 Operand = CBI->getCalledOperand();
4705 TypePrinter.print(FTy->isVarArg() ? FTy :
RetTy, Out);
4707 writeOperand(Operand,
false);
4709 for (
unsigned op = 0, Eop = CBI->arg_size();
op < Eop; ++
op) {
4719 writeOperandBundles(CBI);
4722 writeOperand(CBI->getDefaultDest(),
true);
4724 for (
unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i) {
4727 writeOperand(CBI->getIndirectDest(i),
true);
4730 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
4732 if (AI->isUsedWithInAlloca())
4734 if (AI->isSwiftError())
4735 Out <<
"swifterror ";
4736 TypePrinter.print(AI->getAllocatedType(), Out);
4742 if (!AI->getArraySize() || AI->isArrayAllocation() ||
4743 !AI->getArraySize()->getType()->isIntegerTy(32)) {
4745 writeOperand(AI->getArraySize(),
true);
4748 Out <<
", align " <<
A->value();
4751 unsigned AddrSpace = AI->getAddressSpace();
4752 if (AddrSpace != 0) {
4753 Out <<
", addrspace(" << AddrSpace <<
')';
4755 }
else if (isa<CastInst>(
I)) {
4758 writeOperand(Operand,
true);
4761 TypePrinter.print(
I.getType(), Out);
4762 }
else if (isa<VAArgInst>(
I)) {
4765 writeOperand(Operand,
true);
4768 TypePrinter.print(
I.getType(), Out);
4769 }
else if (Operand) {
4770 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&
I)) {
4772 TypePrinter.print(
GEP->getSourceElementType(), Out);
4774 }
else if (
const auto *LI = dyn_cast<LoadInst>(&
I)) {
4776 TypePrinter.print(LI->getType(), Out);
4783 bool PrintAllTypes =
false;
4788 if (isa<SelectInst>(
I) || isa<StoreInst>(
I) || isa<ShuffleVectorInst>(
I) ||
4789 isa<ReturnInst>(
I) || isa<AtomicCmpXchgInst>(
I) ||
4790 isa<AtomicRMWInst>(
I)) {
4791 PrintAllTypes =
true;
4793 for (
unsigned i = 1, E =
I.getNumOperands(); i != E; ++i) {
4794 Operand =
I.getOperand(i);
4797 if (Operand && Operand->
getType() != TheType) {
4798 PrintAllTypes =
true;
4804 if (!PrintAllTypes) {
4806 TypePrinter.print(TheType, Out);
4810 for (
unsigned i = 0, E =
I.getNumOperands(); i != E; ++i) {
4812 writeOperand(
I.getOperand(i), PrintAllTypes);
4817 if (
const LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
4819 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4821 Out <<
", align " <<
A->value();
4822 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(&
I)) {
4824 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4826 Out <<
", align " <<
A->value();
4828 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4829 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4830 Out <<
", align " << CXI->getAlign().value();
4831 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&
I)) {
4832 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4833 RMWI->getSyncScopeID());
4834 Out <<
", align " << RMWI->getAlign().value();
4835 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&
I)) {
4836 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
4843 I.getAllMetadata(InstMD);
4844 printMetadataAttachments(InstMD,
", ");
4847 printInfoComment(
I);
4850void AssemblyWriter::printDbgMarker(
const DbgMarker &Marker) {
4854 printDbgRecord(DPR);
4858 Out <<
" DbgMarker -> { ";
4863void AssemblyWriter::printDbgRecord(
const DbgRecord &DR) {
4864 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR))
4865 printDbgVariableRecord(*DVR);
4866 else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR))
4867 printDbgLabelRecord(*DLR);
4873 auto WriterCtx = getContext();
4876 case DbgVariableRecord::LocationType::Value:
4879 case DbgVariableRecord::LocationType::Declare:
4882 case DbgVariableRecord::LocationType::Assign:
4887 "Tried to print a DbgVariableRecord with an invalid LocationType!");
4918void AssemblyWriter::printDbgRecordLine(
const DbgRecord &DR) {
4925void AssemblyWriter::printDbgLabelRecord(
const DbgLabelRecord &Label) {
4926 auto WriterCtx = getContext();
4927 Out <<
"#dbg_label(";
4934void AssemblyWriter::printMetadataAttachments(
4940 if (MDNames.empty())
4941 MDs[0].second->getContext().getMDKindNames(MDNames);
4943 auto WriterCtx = getContext();
4944 for (
const auto &
I : MDs) {
4945 unsigned Kind =
I.first;
4947 if (Kind < MDNames.size()) {
4951 Out <<
"!<unknown kind #" <<
Kind <<
">";
4957void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *
Node) {
4958 Out <<
'!' <<
Slot <<
" = ";
4959 printMDNodeBody(
Node);
4963void AssemblyWriter::writeAllMDNodes() {
4967 Nodes[
I.second] = cast<MDNode>(
I.first);
4969 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
4970 writeMDNode(i, Nodes[i]);
4974void AssemblyWriter::printMDNodeBody(
const MDNode *
Node) {
4975 auto WriterCtx = getContext();
4979void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
4988 TypePrinter.print(Ty, Out);
4993void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
4995 bool FirstAttr =
true;
4996 for (
const auto &Attr : AttrSet) {
4999 writeAttribute(Attr, InAttrGroup);
5004void AssemblyWriter::writeAllAttributeGroups() {
5005 std::vector<std::pair<AttributeSet, unsigned>> asVec;
5006 asVec.resize(
Machine.as_size());
5009 asVec[
I.second] =
I;
5011 for (
const auto &
I : asVec)
5012 Out <<
"attributes #" <<
I.second <<
" = { "
5013 <<
I.first.getAsString(
true) <<
" }\n";
5016void AssemblyWriter::printUseListOrder(
const Value *V,
5017 const std::vector<unsigned> &Shuffle) {
5018 bool IsInFunction =
Machine.getFunction();
5022 Out <<
"uselistorder";
5023 if (
const BasicBlock *BB = IsInFunction ?
nullptr : dyn_cast<BasicBlock>(V)) {
5025 writeOperand(BB->getParent(),
false);
5027 writeOperand(BB,
false);
5030 writeOperand(V,
true);
5033 assert(Shuffle.size() >= 2 &&
"Shuffle too small");
5037void AssemblyWriter::printUseLists(
const Function *
F) {
5038 auto It = UseListOrders.find(
F);
5039 if (It == UseListOrders.end())
5042 Out <<
"\n; uselistorder directives\n";
5043 for (
const auto &Pair : It->second)
5044 printUseListOrder(Pair.first, Pair.second);
5052 bool ShouldPreserveUseListOrder,
5053 bool IsForDebug)
const {
5056 AssemblyWriter W(
OS, SlotTable, this->
getParent(), AAW,
5058 ShouldPreserveUseListOrder);
5059 W.printFunction(
this);
5063 bool ShouldPreserveUseListOrder,
5064 bool IsForDebug)
const {
5067 AssemblyWriter W(
OS, SlotTable, this->
getModule(), AAW,
5069 ShouldPreserveUseListOrder);
5070 W.printBasicBlock(
this);
5074 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
5077 AssemblyWriter W(
OS, SlotTable,
this, AAW, IsForDebug,
5078 ShouldPreserveUseListOrder);
5079 W.printModule(
this);
5085 AssemblyWriter W(
OS, SlotTable,
getParent(),
nullptr, IsForDebug);
5086 W.printNamedMDNode(
this);
5090 bool IsForDebug)
const {
5091 std::optional<SlotTracker> LocalST;
5097 SlotTable = &*LocalST;
5101 AssemblyWriter W(
OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
5102 W.printNamedMDNode(
this);
5107 ROS <<
" = comdat ";
5114 ROS <<
"exactmatch";
5120 ROS <<
"nodeduplicate";
5132 TP.print(
const_cast<Type*
>(
this),
OS);
5138 if (
StructType *STy = dyn_cast<StructType>(
const_cast<Type*
>(
this)))
5141 TP.printStructBody(STy,
OS);
5146 if (
const auto *CI = dyn_cast<CallInst>(&
I))
5147 if (
Function *
F = CI->getCalledFunction())
5148 if (
F->isIntrinsic())
5149 for (
auto &
Op :
I.operands())
5150 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
5151 if (isa<MDNode>(V->getMetadata()))
5159 print(ROS, MST, IsForDebug);
5165 print(ROS, MST, IsForDebug);
5169 bool IsForDebug)
const {
5174 auto incorporateFunction = [&](
const Function *
F) {
5180 W.printDbgMarker(*
this);
5186 print(ROS, MST, IsForDebug);
5190 bool IsForDebug)
const {
5195 auto incorporateFunction = [&](
const Function *
F) {
5203 W.printDbgVariableRecord(*
this);
5207 bool IsForDebug)
const {
5212 auto incorporateFunction = [&](
const Function *
F) {
5219 W.printDbgLabelRecord(*
this);
5223 bool ShouldInitializeAllMetadata =
false;
5224 if (
auto *
I = dyn_cast<Instruction>(
this))
5226 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
5227 ShouldInitializeAllMetadata =
true;
5230 print(ROS, MST, IsForDebug);
5234 bool IsForDebug)
const {
5239 auto incorporateFunction = [&](
const Function *
F) {
5244 if (
const Instruction *
I = dyn_cast<Instruction>(
this)) {
5245 incorporateFunction(
I->getParent() ?
I->getParent()->getParent() :
nullptr);
5247 W.printInstruction(*
I);
5248 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
5249 incorporateFunction(BB->getParent());
5251 W.printBasicBlock(BB);
5252 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
5253 AssemblyWriter W(
OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
5256 else if (
const Function *
F = dyn_cast<Function>(GV))
5258 else if (
const GlobalAlias *
A = dyn_cast<GlobalAlias>(GV))
5260 else if (
const GlobalIFunc *
I = dyn_cast<GlobalIFunc>(GV))
5264 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
5266 }
else if (
const Constant *
C = dyn_cast<Constant>(
this)) {
5267 TypePrinting TypePrinter;
5268 TypePrinter.print(
C->getType(),
OS);
5270 AsmWriterContext WriterCtx(&TypePrinter, MST.
getMachine());
5272 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
5284 if (V.hasName() || isa<GlobalValue>(V) ||
5285 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
5286 AsmWriterContext WriterCtx(
nullptr,
Machine, M);
5295 TypePrinting TypePrinter(MST.
getModule());
5297 TypePrinter.print(V.getType(), O);
5315 M, isa<MetadataAsValue>(
this));
5331 AsmWriterContext &WriterCtx) {
5335 auto *
N = dyn_cast<MDNode>(&MD);
5336 if (!
N || isa<DIExpression>(MD))
5344struct MDTreeAsmWriterContext :
public AsmWriterContext {
5347 using EntryTy = std::pair<unsigned, std::string>;
5357 : AsmWriterContext(TP,
ST,
M), Level(0
U), Visited({InitMD}), MainOS(
OS) {}
5359 void onWriteMetadataAsOperand(
const Metadata *MD)
override {
5360 if (!Visited.
insert(MD).second)
5369 unsigned InsertIdx = Buffer.
size() - 1;
5372 Buffer[InsertIdx].second = std::move(
SS.str());
5376 ~MDTreeAsmWriterContext() {
5377 for (
const auto &Entry : Buffer) {
5379 unsigned NumIndent =
Entry.first * 2U;
5388 bool OnlyAsOperand,
bool PrintAsTree =
false) {
5391 TypePrinting TypePrinter(M);
5393 std::unique_ptr<AsmWriterContext> WriterCtx;
5394 if (PrintAsTree && !OnlyAsOperand)
5395 WriterCtx = std::make_unique<MDTreeAsmWriterContext>(
5399 std::make_unique<AsmWriterContext>(&TypePrinter, MST.
getMachine(), M);
5403 auto *
N = dyn_cast<MDNode>(&MD);
5404 if (OnlyAsOperand || !
N || isa<DIExpression>(MD))
5428 const Module *M,
bool )
const {
5447 AssemblyWriter W(
OS, SlotTable,
this, IsForDebug);
5448 W.printModuleSummaryIndex();
5452 unsigned UB)
const {
5458 if (
I.second >= LB &&
I.second < UB)
5459 L.push_back(std::make_pair(
I.second,
I.first));
5462#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
MapVector< const Value *, unsigned > OrderMap
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
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 writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
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)
#define CC_VLS_CASE(ABI_VLEN)
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 cl::opt< bool > PrintInstDebugLocs("print-inst-debug-locs", cl::Hidden, cl::desc("Pretty print debug locations of instructions when dumping"))
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 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 cl::opt< bool > PrintProfData("print-prof-data", cl::Hidden, cl::desc("Pretty print perf data (branch weights, etc) when dumping"))
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 cl::opt< bool > PrintInstAddrs("print-inst-addrs", cl::Hidden, cl::desc("Print addresses of instructions when dumping"))
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
static bool printWithoutType(const Value &V, raw_ostream &O, SlotTracker *Machine, const Module *M)
Print without a type, skipping the TypePrinting object.
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static const Value * skipMetadataWrapper(const Value *V)
Look for a value that might be wrapped as metadata, e.g.
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
COFF::MachineTypes Machine
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil pretty DXIL Metadata Pretty Printer
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
This defines the Use class.
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
static bool isDigit(const char C)
This file provides utility classes that use RAII to save and restore values.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_ABI 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.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI 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 LLVM_ABI StringRef getOperationName(BinOp Op)
LLVM_ABI AttributeSet getFnAttrs() const
The function attributes are returned.
LLVM_ABI 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.
LLVM_ABI AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
bool hasFnAttrs() const
Return true the attributes exist for the function.
LLVM_ABI 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.
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
LLVM_ABI Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
static LLVM_ABI StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
LLVM_ABI bool isTypeAttribute() const
Return true if the attribute is a type attribute.
LLVM_ABI Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM Basic Block Representation.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) const
LLVM_ABI StringRef getName() const
LLVM_ABI void dump() 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.
LLVM_ABI APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
LLVM_ABI APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
This is an important base class in LLVM.
LLVM_ABI Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
LLVM_ABI 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 LLVM_ABI const char * nameTableKindString(DebugNameTableKind PK)
static LLVM_ABI const char * emissionKindString(DebugEmissionKind EK)
A lightweight wrapper around an expression operand.
static LLVM_ABI const char * fixedPointKindString(FixedPointKind)
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 LLVM_ABI DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)
Split up a flags bitfield.
static LLVM_ABI StringRef getFlagString(DIFlags Flag)
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
static LLVM_ABI DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)
Split up a flags bitfield for easier printing.
static LLVM_ABI StringRef getFlagString(DISPFlags Flag)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Per-instruction record of debug-info.
LLVM_ABI void dump() const
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on DbgMarker.
LLVM_ABI 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.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
LLVM_ABI void dump() 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
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
Metadata * getRawAssignID() const
MDNode * getRawVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAddress() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Utility class for floating point operations which can have information about relaxed accuracy require...
An instruction for ordering other memory operations.
Function summary information to aid decisions and implementation of importing.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter.
Represents calls to the gc.relocate intrinsic.
LLVM_ABI Value * getBasePtr() const
LLVM_ABI 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.
LLVM_ABI 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
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
LLVM_ABI 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
LLVM_ABI 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.
LLVM_ABI 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.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
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.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
LLVM_ABI void printTree(raw_ostream &OS, const Module *M=nullptr) const
Print in tree shape.
LLVM_ABI 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.
LLVM_ABI void dump() const
Dump to stderr (for debugging).
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
A Module instance is used to store all the information related to an LLVM module.
iterator_range< ifunc_iterator > ifuncs()
iterator_range< named_metadata_iterator > named_metadata()
iterator_range< alias_iterator > aliases()
iterator_range< global_iterator > globals()
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
void dump() const
Dump the module to stderr (for debugging).
LLVM_ABI void dump() const
LLVM_ABI StringRef getName() const
LLVM_ABI void print(raw_ostream &ROS, bool IsForDebug=false) const
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI 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, sdiv, lshr, or ashr instruction, which can be marked as "exact", indicating that no bits are ...
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
A vector that has set insertion semantics.
This instruction constructs a fixed permutation of two input vectors.
This class provides computation of slot numbers for LLVM Assembly writing.
int getMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
int getTypeIdCompatibleVtableSlot(StringRef Id)
int getModulePathSlot(StringRef Path)
unsigned mdn_size() const
SlotTracker(const SlotTracker &)=delete
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
int getTypeIdSlot(StringRef Id)
void initializeIfNeeded()
These functions do the actual initialization.
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
const Function * getFunction() const
unsigned getNextMetadataSlot() override
void incorporateFunction(const Function *F)
If you'd like to deal with a function instead of just a module, use this method to get its data into ...
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
int getAttributeGroupSlot(AttributeSet AS)
SlotTracker(const Module *M, bool ShouldInitializeAllMetadata=false)
Construct from a module.
void createMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
SlotTracker & operator=(const SlotTracker &)=delete
int getGUIDSlot(GlobalValue::GUID GUID)
int initializeIndexIfNeeded()
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Class to represent struct types.
ArrayRef< Type * > elements() const
unsigned getNumElements() const
Random access to the elements.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
LLVM_ABI 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.
LLVM_ABI void dump() const
LLVM_ABI StringRef getTargetExtName() const
@ 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)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current 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.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
LLVM_ABI 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.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI 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.
LLVM_ABI StringRef EnumKindString(unsigned EnumKind)
LLVM_ABI StringRef LanguageString(unsigned Language)
LLVM_ABI StringRef AttributeEncodingString(unsigned Encoding)
LLVM_ABI StringRef ConventionString(unsigned Convention)
LLVM_ABI StringRef MacinfoString(unsigned Encoding)
LLVM_ABI StringRef OperationEncodingString(unsigned Encoding)
LLVM_ABI StringRef TagString(unsigned Tag)
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ RISCV_VectorCall
Calling convention used for RISC-V V-extension.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AVR_SIGNAL
Used for AVR signal routines.
@ Swift
Calling convention for Swift.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
@ AVR_INTR
Used for AVR interrupt routines.
@ PreserveMost
Used for runtime calls that preserves most registers.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ AMDGPU_Gfx
Used for AMD graphics targets.
@ DUMMY_HHVM
Placeholders for HHVM calling conventions (deprecated, removed).
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2
Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ CXX_FAST_TLS
Used for access functions.
@ X86_INTR
x86 hardware interrupt context.
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0
Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1
Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ X86_ThisCall
Similar to X86_StdCall.
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
@ X86_StdCall
stdcall is mostly used by the Win32 API.
@ SPIR_FUNC
Used for SPIR non-kernel device functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ MSP430_INTR
Used for MSP430 interrupt routines.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ PreserveNone
Used for runtime calls that preserves none general registers.
@ AMDGPU_ES
Used for AMDPAL shader stage before geometry shader if geometry is in use.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
@ AMDGPU_LS
Used for AMDPAL vertex shader if tessellation is in use.
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
@ M68k_RTD
Used for M68k rtd-based CC (similar to X86's stdcall).
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
@ System
Synchronized with respect to all concurrently executing threads.
@ DW_OP_LLVM_convert
Only used in LLVM metadata.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto pred_end(const MachineBasicBlock *BB)
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
const char * getHotnessName(CalleeInfo::HotnessType HT)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
constexpr int PoisonMaskElem
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Ref
The access may reference the value stored in memory.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto pred_begin(const MachineBasicBlock *BB)
const char * toString(DWARFSectionKind Kind)
@ Default
The result values are uniform if and only if all operands are uniform.
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
LLVM_ABI void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
static LLVM_ABI const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static LLVM_ABI const fltSemantics & x87DoubleExtended() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEquad() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEdouble() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEhalf() LLVM_READNONE
static LLVM_ABI 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:...