32#include "llvm/Config/llvm-config.h"
96 cl::desc(
"Print addresses of instructions when dumping"));
100 cl::desc(
"Pretty print debug locations of instructions when dumping"));
104 cl::desc(
"Pretty print perf data (branch weights, etc) when dumping"));
108 cl::desc(
"Preserve use-list order when writing LLVM assembly."));
112 cl::desc(
"Print address space names"));
131 return VAM->getValue();
144 for (
const Value *
Op :
C->operands())
151 unsigned ID = OM.size() + 1;
158 auto OrderConstantValue = [&OM](
const Value *V) {
163 auto OrderConstantFromMetadata = [&](
Metadata *MD) {
165 OrderConstantValue(VAM->getValue());
167 for (
const auto *VAM : AL->getArgs())
168 OrderConstantValue(VAM->getValue());
173 if (
G.hasInitializer())
189 for (
const Use &U :
F.operands())
195 if (
F.isDeclaration())
208 OrderConstantFromMetadata(DVR.getRawLocation());
209 if (DVR.isDbgAssign())
210 OrderConstantFromMetadata(DVR.getRawAddress());
213 for (
const Value *
Op :
I.operands()) {
226static std::vector<unsigned>
229 using Entry = std::pair<const Use *, unsigned>;
233 if (OM.lookup(U.getUser()))
234 List.
push_back(std::make_pair(&U, List.size()));
245 ID = OM.lookup(BA->getBasicBlock());
246 llvm::sort(List, [&](
const Entry &L,
const Entry &R) {
247 const Use *LU = L.first;
248 const Use *RU = R.first;
252 auto LID = OM.lookup(LU->getUser());
253 auto RID = OM.lookup(RU->getUser());
273 return LU->getOperandNo() < RU->getOperandNo();
274 return LU->getOperandNo() > RU->getOperandNo();
282 std::vector<unsigned> Shuffle(List.size());
283 for (
size_t I = 0,
E = List.size();
I !=
E; ++
I)
284 Shuffle[
I] = List[
I].second;
291 for (
const auto &Pair : OM) {
292 const Value *V = Pair.first;
293 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
296 std::vector<unsigned> Shuffle =
303 F =
I->getFunction();
308 ULOM[
F][V] = std::move(Shuffle);
315 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
318 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
321 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
322 return M ? M->getParent() :
nullptr;
326 return GV->getParent();
351 default: Out <<
"cc" << cc;
break;
374 Out <<
"aarch64_sve_vector_pcs";
377 Out <<
"aarch64_sme_preservemost_from_x0";
380 Out <<
"aarch64_sme_preservemost_from_x1";
383 Out <<
"aarch64_sme_preservemost_from_x2";
411 Out <<
"amdgpu_cs_chain";
414 Out <<
"amdgpu_cs_chain_preserve";
419 Out <<
"amdgpu_gfx_whole_wave";
423 Out <<
"wasm_emscripten_invokecc";
426 Out <<
"riscv_vector_cc";
428#define CC_VLS_CASE(ABI_VLEN) \
429 case CallingConv::RISCV_VLSCall_##ABI_VLEN: \
430 Out << "riscv_vls_cc(" #ABI_VLEN ")"; \
446 Out <<
"cheriot_compartmentcallcc";
449 Out <<
"cheriot_compartmentcalleecc";
452 Out <<
"cheriot_librarycallcc";
466 assert(!Name.empty() &&
"Cannot get empty name!");
469 bool NeedsQuotes = isdigit(
static_cast<unsigned char>(Name[0]));
471 for (
unsigned char C : Name) {
476 if (!isalnum(
C) &&
C !=
'-' &&
C !=
'.' &&
C !=
'_') {
530 Out << Mask.size() <<
" x i32> ";
532 Out <<
"zeroinitializer";
538 for (
int Elt : Mask) {
553 TypePrinting(
const Module *M =
nullptr)
554 : M(M), TypesIncorporated(M == nullptr) {}
556 TypePrinting(
const TypePrinting &) =
delete;
557 TypePrinting &operator=(
const TypePrinting &) =
delete;
560 TypeFinder &getNamedTypes();
563 std::vector<StructType *> &getNumberedTypes();
569 void printStructBody(StructType *Ty, raw_ostream &OS);
572 void incorporateTypes();
576 bool TypesIncorporated;
578 TypeFinder NamedTypes;
581 DenseMap<StructType *, unsigned> Type2Number;
583 std::vector<StructType *> NumberedTypes;
593std::vector<StructType *> &TypePrinting::getNumberedTypes() {
599 if (NumberedTypes.size() == Type2Number.size())
600 return NumberedTypes;
602 NumberedTypes.resize(Type2Number.size());
603 for (
const auto &
P : Type2Number) {
604 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
605 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
606 NumberedTypes[
P.second] =
P.first;
608 return NumberedTypes;
611bool TypePrinting::empty() {
613 return NamedTypes.
empty() && Type2Number.empty();
616void TypePrinting::incorporateTypes() {
617 if (TypesIncorporated)
620 NamedTypes.
run(*M,
false);
621 TypesIncorporated =
true;
625 unsigned NextNumber = 0;
627 std::vector<StructType *>::iterator NextToUse = NamedTypes.
begin();
628 for (StructType *STy : NamedTypes) {
630 if (STy->isLiteral())
633 if (STy->getName().empty())
634 Type2Number[STy] = NextNumber++;
639 NamedTypes.erase(NextToUse, NamedTypes.end());
644 bool ForcePrint =
false) {
645 if (AS == 0 && !ForcePrint)
647 OS << Prefix <<
"addrspace(";
651 OS <<
"\"" << ASName <<
"\"";
659void TypePrinting::print(
Type *Ty, raw_ostream &OS) {
661 case Type::VoidTyID: OS <<
"void";
return;
662 case Type::HalfTyID: OS <<
"half";
return;
663 case Type::BFloatTyID: OS <<
"bfloat";
return;
664 case Type::FloatTyID: OS <<
"float";
return;
665 case Type::DoubleTyID: OS <<
"double";
return;
666 case Type::X86_FP80TyID: OS <<
"x86_fp80";
return;
667 case Type::FP128TyID: OS <<
"fp128";
return;
668 case Type::PPC_FP128TyID: OS <<
"ppc_fp128";
return;
669 case Type::LabelTyID: OS <<
"label";
return;
670 case Type::MetadataTyID:
673 case Type::X86_AMXTyID: OS <<
"x86_amx";
return;
674 case Type::TokenTyID: OS <<
"token";
return;
678 case Type::IntegerTyID:
679 OS << 'i' << cast<IntegerType>(Ty)->getBitWidth();
682 case Type::FunctionTyID: {
684 print(FTy->getReturnType(), OS);
687 for (
Type *Ty : FTy->params()) {
696 case Type::StructTyID: {
700 return printStructBody(STy, OS);
706 const auto I = Type2Number.find(STy);
707 if (
I != Type2Number.end())
708 OS <<
'%' <<
I->second;
710 OS <<
"%\"type " << STy <<
'\"';
713 case Type::PointerTyID: {
719 case Type::ArrayTyID: {
721 OS <<
'[' << ATy->getNumElements() <<
" x ";
722 print(ATy->getElementType(), OS);
726 case Type::FixedVectorTyID:
727 case Type::ScalableVectorTyID: {
729 ElementCount
EC = PTy->getElementCount();
733 OS <<
EC.getKnownMinValue() <<
" x ";
734 print(PTy->getElementType(), OS);
738 case Type::TypedPointerTyID: {
744 case Type::TargetExtTyID:
751 Inner->print(OS,
false,
true);
754 OS <<
", " << IntParam;
761void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
803 const Function* TheFunction =
nullptr;
804 bool FunctionProcessed =
false;
805 bool ShouldTrackMetadataDefinitions;
810 ProcessFunctionHookFn;
831 unsigned ModulePathNext = 0;
835 unsigned GUIDNext = 0;
839 unsigned TypeIdNext = 0;
844 unsigned TypeIdCompatibleVtableNext = 0;
850 bool ShouldTrackMetadataDefinitions =
false);
886 FunctionProcessed =
false;
894 void purgeFunction();
901 unsigned mdn_size()
const {
return mdnMap.size(); }
909 unsigned as_size()
const {
return asMap.size(); }
925 void CreateMetadataSlot(
const MDNode *
N);
928 void CreateFunctionSlot(
const Value *V);
933 inline void CreateModulePathSlot(
StringRef Path);
936 void CreateTypeIdCompatibleVtableSlot(
StringRef Id);
950 : M(M), F(F), Machine(&Machine) {}
953 : ShouldCreateStorage(M), M(M) {}
958 if (!ShouldCreateStorage)
961 ShouldCreateStorage =
false;
962 MachineStorage = std::make_unique<SlotTracker>(M);
963 Machine = MachineStorage.get();
964 if (ProcessModuleHookFn)
965 Machine->setProcessHook(ProcessModuleHookFn);
966 if (ProcessFunctionHookFn)
967 Machine->setProcessHook(ProcessFunctionHookFn);
980 Machine->purgeFunction();
981 Machine->incorporateFunction(&F);
986 assert(F &&
"No function incorporated");
987 return Machine->getLocalSlot(V);
992 ProcessModuleHookFn = std::move(Fn);
997 ProcessFunctionHookFn = std::move(Fn);
1027#define ST_DEBUG(X) dbgs() << X
1036 ShouldTrackMetadataDefinitions(ShouldTrackMetadataDefinitions) {}
1041 : TheModule(
F ?
F->
getParent() : nullptr), TheFunction(
F),
1042 ShouldTrackMetadataDefinitions(
false) {}
1045 : TheModule(nullptr), ShouldTrackMetadataDefinitions(
false),
1051 TheModule =
nullptr;
1054 if (TheFunction && !FunctionProcessed)
1061 int NumSlots = processIndex();
1068void SlotTracker::processModule() {
1069 ST_DEBUG(
"begin processModule!\n");
1074 CreateModuleSlot(&Var);
1075 auto Attrs = Var.getAttributes();
1076 if (Attrs.hasAttributes())
1077 CreateAttributeSetSlot(Attrs);
1082 CreateModuleSlot(&
A);
1085 for (
const GlobalIFunc &
I : TheModule->ifuncs()) {
1087 CreateModuleSlot(&
I);
1093 CreateModuleSlot(&
F);
1097 AttributeSet FnAttrs =
F.getAttributes().getFnAttrs();
1099 CreateAttributeSetSlot(FnAttrs);
1102 if (ProcessModuleHookFn)
1103 ProcessModuleHookFn(
this, TheModule);
1109void SlotTracker::processFunction() {
1110 ST_DEBUG(
"begin processFunction!\n");
1115 AE = TheFunction->arg_end(); AI != AE; ++AI)
1117 CreateFunctionSlot(&*AI);
1119 ST_DEBUG(
"Inserting Instructions:\n");
1122 for (
auto &BB : *TheFunction) {
1124 CreateFunctionSlot(&BB);
1126 for (
auto &
I : BB) {
1127 if (!
I.getType()->isVoidTy() && !
I.hasName())
1128 CreateFunctionSlot(&
I);
1135 if (
Attrs.hasAttributes())
1136 CreateAttributeSetSlot(Attrs);
1141 if (ProcessFunctionHookFn)
1142 ProcessFunctionHookFn(
this, TheFunction);
1144 FunctionProcessed =
true;
1146 ST_DEBUG(
"end processFunction!\n");
1150int SlotTracker::processIndex() {
1157 std::vector<StringRef> ModulePaths;
1158 for (
auto &[ModPath,
_] : TheIndex->modulePaths())
1159 ModulePaths.push_back(ModPath);
1161 for (
auto &ModPath : ModulePaths)
1162 CreateModulePathSlot(ModPath);
1165 GUIDNext = ModulePathNext;
1168 for (
const auto &GlobalList : TheIndex->sortedGlobalValueSummariesRange())
1169 CreateGUIDSlot(GlobalList.first);
1172 TypeIdCompatibleVtableNext = GUIDNext;
1173 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1174 CreateTypeIdCompatibleVtableSlot(TId.first);
1177 TypeIdNext = TypeIdCompatibleVtableNext;
1178 for (
const auto &TID : TheIndex->typeIds())
1179 CreateTypeIdSlot(TID.second.first);
1186class MetadataNodeVisitor {
1188 SmallPtrSet<const MDNode *, 32> VisitedMDNodes;
1189 function_ref<void(
const MDNode *)> Visit;
1191 void visit(
const MDNode *
N) {
1196 for (
const MDOperand &
Op :
N->operands())
1201 void visitGlobalObjectMetadata(
const GlobalObject &GO) {
1204 for (
auto &MD : MDs)
1208 void visitDbgRecordMetadata(
const DbgRecord &DR) {
1212 if (DVR->getRawVariable())
1213 visit(DVR->getRawVariable());
1214 if (DVR->isDbgAssign()) {
1215 if (
auto *AssignID = DVR->getRawAssignID())
1221 visit(DLR->getRawLabel());
1229 void visitInstructionMetadata(
const Instruction &
I) {
1231 if (
Function *
F = CI->getCalledFunction())
1232 if (
F->isIntrinsic())
1233 for (
auto &
Op :
I.operands())
1239 I.getAllMetadata(MDs);
1240 for (
auto &MD : MDs)
1244 void visitFunctionMetadata(
const Function &
F) {
1245 visitGlobalObjectMetadata(
F);
1246 for (
const BasicBlock &BB :
F)
1247 for (
const Instruction &
I : BB) {
1248 for (
const DbgRecord &DR :
I.getDbgRecordRange())
1249 visitDbgRecordMetadata(DR);
1250 visitInstructionMetadata(
I);
1255 MetadataNodeVisitor(function_ref<
void(
const MDNode *)> Visit)
1258 void visitModuleMetadata(
const Module &M) {
1259 for (
const GlobalVariable &Var :
M.globals())
1260 visitGlobalObjectMetadata(Var);
1261 for (
const GlobalIFunc &
I :
M.ifuncs())
1262 visitGlobalObjectMetadata(
I);
1263 for (
const NamedMDNode &NMD :
M.named_metadata())
1264 for (
const MDNode *
N : NMD.operands())
1267 visitFunctionMetadata(
F);
1278class MetadataIDRenumberer {
1279 uint32_t NextID = 0;
1285 bool IsAdditionalMetadata =
false;
1286 auto Renumber = [&](
const MDNode *
N) {
1287 N->getContext().pImpl->setMetadataPrintID(
const_cast<MDNode *
>(
N),
1289 if (IsAdditionalMetadata && AdditionalMetadataNodes)
1290 AdditionalMetadataNodes->emplace_back(
1291 N->getContext().pImpl->getMetadataPrintID(
N),
N);
1293 MetadataNodeVisitor Visitor(Renumber);
1295 Visitor.visitModuleMetadata(M);
1297 IsAdditionalMetadata =
true;
1298 Visitor.visitMetadata(AdditionalMetadata);
1302 M.getContext().pImpl->getAllMetadataNodes(RemainingNodes);
1304 return Visitor.contains(
N) ||
1305 M.getContext().pImpl->getMetadataPrintID(
N) >= NextID;
1308 return M.getContext().pImpl->getMetadataPrintID(
LHS) <
1309 M.getContext().pImpl->getMetadataPrintID(
RHS);
1311 for (MDNode *
N : RemainingNodes)
1312 M.getContext().pImpl->setMetadataPrintID(
1313 N,
M.getContext().pImpl->allocateMetadataPrintID());
1315 if (AdditionalMetadataNodes)
1322 MetadataIDRenumberer().run(*
this, {});
1328 assert(M &&
"metadata renumbering requires a module");
1329 MetadataIDRenumberer().run(*M, AdditionalMetadata, AdditionalMetadataNodes);
1335 assert(M &&
"metadata collection requires a module");
1336 bool IsAdditionalMetadata =
false;
1337 auto Collect = [&](
const MDNode *
N) {
1338 if (IsAdditionalMetadata)
1340 N->getContext().pImpl->getMetadataPrintID(
N),
N);
1342 MetadataNodeVisitor Visitor(Collect);
1343 Visitor.visitModuleMetadata(*M);
1344 IsAdditionalMetadata =
true;
1345 Visitor.visitMetadata(AdditionalMetadata);
1353 ST_DEBUG(
"begin purgeFunction!\n");
1355 TheFunction =
nullptr;
1356 FunctionProcessed =
false;
1367 return MI == mMap.end() ? -1 : (int)
MI->second;
1372 ProcessModuleHookFn = std::move(Fn);
1377 ProcessFunctionHookFn = std::move(Fn);
1390 if (ShouldTrackMetadataDefinitions)
1391 CreateMetadataSlot(
N);
1392 return N->getContext().pImpl->getMetadataPrintID(
N);
1403 return FI == fMap.end() ? -1 : (int)FI->second;
1412 return AI == asMap.end() ? -1 : (int)AI->second;
1420 auto I = ModulePathMap.find(Path);
1421 return I == ModulePathMap.end() ? -1 : (int)
I->second;
1430 return I == GUIDMap.end() ? -1 : (int)
I->second;
1438 auto I = TypeIdMap.find(Id);
1439 return I == TypeIdMap.end() ? -1 : (int)
I->second;
1447 auto I = TypeIdCompatibleVtableMap.find(Id);
1448 return I == TypeIdCompatibleVtableMap.end() ? -1 : (int)
I->second;
1452void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1453 assert(V &&
"Can't insert a null Value into SlotTracker!");
1454 assert(!V->getType()->isVoidTy() &&
"Doesn't need a slot!");
1455 assert(!V->hasName() &&
"Doesn't need a slot!");
1457 unsigned DestSlot = mNext++;
1460 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1470void SlotTracker::CreateFunctionSlot(
const Value *V) {
1471 assert(!V->getType()->isVoidTy() && !V->hasName() &&
"Doesn't need a slot!");
1473 unsigned DestSlot = fNext++;
1477 ST_DEBUG(
" Inserting value [" << V->getType() <<
"] = " << V <<
" slot=" <<
1478 DestSlot <<
" [o]\n");
1482void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1483 assert(
N &&
"Can't insert a null Value into SlotTracker!");
1488 unsigned ID =
N->getContext().pImpl->getMetadataPrintID(
N);
1489 if (!mdnMap.try_emplace(
N, ID).second)
1492 for (
const MDOperand &
Op :
N->operands())
1494 CreateMetadataSlot(OpNode);
1497void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1500 if (asMap.try_emplace(AS, asNext).second)
1505void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1506 ModulePathMap[
Path] = ModulePathNext++;
1511 GUIDMap[
GUID] = GUIDNext++;
1515void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1516 TypeIdMap[
Id] = TypeIdNext++;
1520void SlotTracker::CreateTypeIdCompatibleVtableSlot(
StringRef Id) {
1521 TypeIdCompatibleVtableMap[
Id] = TypeIdCompatibleVtableNext++;
1526struct AsmWriterContext {
1527 TypePrinting *TypePrinter =
nullptr;
1528 SlotTracker *
Machine =
nullptr;
1530 const ModuleSlotTracker *MST =
nullptr;
1532 AsmWriterContext(TypePrinting *TP, SlotTracker *ST,
const Module *M =
nullptr,
1533 const ModuleSlotTracker *MST =
nullptr)
1536 static AsmWriterContext &getEmpty() {
1537 static AsmWriterContext EmptyCtx(
nullptr,
nullptr);
1543 virtual void onWriteMetadataAsOperand(
const Metadata *) {}
1545 virtual ~AsmWriterContext() =
default;
1554 AsmWriterContext &WriterCtx,
1555 bool PrintType =
false);
1558 AsmWriterContext &WriterCtx,
1559 bool FromValue =
false);
1563 Out << FPO->getFastMathFlags();
1566 if (OBO->hasNoUnsignedWrap())
1568 if (OBO->hasNoSignedWrap())
1574 if (PDI->isDisjoint())
1577 if (
GEP->isInBounds())
1579 else if (
GEP->hasNoUnsignedSignedWrap())
1581 if (
GEP->hasNoUnsignedWrap())
1584 Out <<
" inrange(" <<
InRange->getLower() <<
", " <<
InRange->getUpper()
1588 if (NNI->hasNonNeg())
1591 if (TI->hasNoUnsignedWrap())
1593 if (TI->hasNoSignedWrap())
1596 if (ICmp->hasSameSign())
1599 if (ASC->hasNonNull())
1607 unsigned NumDigits = std::max((Val.
getBitWidth() + 3) / 4, 1U);
1609 for (
unsigned i = 0; i < NumDigits - Bits.size(); i++)
1615 bool ForceBitwiseOutput =
false;
1621 ForceBitwiseOutput = !HiWord.
isZero();
1624 if (!ForceBitwiseOutput) {
1627 Out << (APF.
isNegative() ?
'-' :
'+') <<
"inf";
1669 AsmWriterContext &WriterCtx) {
1671 Type *Ty = CI->getType();
1673 if (Ty->isVectorTy()) {
1675 WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);
1679 if (Ty->getScalarType()->isIntegerTy(1))
1680 Out << (CI->getZExtValue() ?
"true" :
"false");
1682 Out << CI->getValue();
1684 if (Ty->isVectorTy())
1691 Type *Ty = CB->getType();
1693 if (Ty->isVectorTy()) {
1695 WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);
1699 Out << CB->getValue();
1701 if (Ty->isVectorTy())
1708 Type *Ty = CFP->getType();
1710 if (Ty->isVectorTy()) {
1711 if (CFP->getValue().bitcastToAPInt().isZero()) {
1712 Out <<
"zeroinitializer";
1717 WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);
1723 if (Ty->isVectorTy())
1730 Out <<
"zeroinitializer";
1735 Out <<
"blockaddress(";
1744 Out <<
"dso_local_equivalent ";
1759 unsigned NumOpsToWrite = 2;
1760 if (!CPA->getOperand(2)->isNullValue())
1768 for (
unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {
1780 for (
const Value *
Op : CA->operands()) {
1791 if (CA->isString()) {
1800 for (
uint64_t i = 0, e = CA->getNumElements(); i != e; ++i) {
1810 if (CS->getType()->isPacked())
1813 if (CS->getNumOperands() != 0) {
1816 for (
const Value *
Op : CS->operands()) {
1823 if (CS->getType()->isPacked())
1848 for (
unsigned i = 0, e = CVVTy->getNumElements(); i != e; ++i) {
1892 if (CE->getOpcode() == Instruction::ShuffleVector) {
1893 if (
auto *SplatVal = CE->getSplatValue()) {
1904 Out << CE->getOpcodeName();
1909 WriterCtx.TypePrinter->print(
GEP->getSourceElementType(), Out);
1914 for (
const Value *
Op : CE->operands()) {
1921 WriterCtx.TypePrinter->print(CE->getType(), Out);
1924 if (CE->getOpcode() == Instruction::ShuffleVector)
1931 Out <<
"<placeholder or erroneous Constant>";
1935 AsmWriterContext &WriterCtx) {
1943 Value *V = MDV->getValue();
1947 WriterCtx.onWriteMetadataAsOperand(MD);
1956struct MDFieldPrinter {
1959 AsmWriterContext &WriterCtx;
1961 explicit MDFieldPrinter(raw_ostream &Out)
1962 :
Out(
Out), WriterCtx(AsmWriterContext::getEmpty()) {}
1963 MDFieldPrinter(raw_ostream &Out, AsmWriterContext &Ctx)
1964 :
Out(
Out), WriterCtx(Ctx) {}
1966 void printTag(
const DINode *
N);
1967 void printMacinfoType(
const DIMacroNode *
N);
1968 void printChecksum(
const DIFile::ChecksumInfo<StringRef> &
N);
1969 void printString(StringRef Name, StringRef
Value,
1970 bool ShouldSkipEmpty =
true);
1971 void printMetadata(StringRef Name,
const Metadata *MD,
1972 bool ShouldSkipNull =
true);
1973 void printMetadataOrInt(StringRef Name,
const Metadata *MD,
bool IsUnsigned,
1974 bool ShouldSkipZero =
true);
1975 template <
class IntTy>
1976 void printInt(StringRef Name, IntTy
Int,
bool ShouldSkipZero =
true);
1977 void printAPInt(StringRef Name,
const APInt &
Int,
bool IsUnsigned,
1978 bool ShouldSkipZero);
1979 void printBool(StringRef Name,
bool Value,
1980 std::optional<bool>
Default = std::nullopt);
1983 template <
class IntTy,
class Stringifier>
1984 void printDwarfEnum(StringRef Name, IntTy
Value, Stringifier
toString,
1985 bool ShouldSkipZero =
true);
1987 void printNameTableKind(StringRef Name,
1994void MDFieldPrinter::printTag(
const DINode *
N) {
1995 Out <<
FS <<
"tag: ";
2003void MDFieldPrinter::printMacinfoType(
const DIMacroNode *
N) {
2004 Out <<
FS <<
"type: ";
2009 Out <<
N->getMacinfoType();
2012void MDFieldPrinter::printChecksum(
2015 printString(
"checksum", Checksum.
Value,
false);
2019 bool ShouldSkipEmpty) {
2020 if (ShouldSkipEmpty &&
Value.empty())
2029 AsmWriterContext &WriterCtx) {
2035 WriterCtx.onWriteMetadataAsOperand(MD);
2039 bool ShouldSkipNull) {
2040 if (ShouldSkipNull && !MD)
2048 bool IsUnsigned,
bool ShouldSkipZero) {
2055 printInt(Name, CV->getZExtValue(), ShouldSkipZero);
2057 printInt(Name, CV->getSExtValue(), ShouldSkipZero);
2059 printMetadata(Name, MD);
2062template <
class IntTy>
2063void MDFieldPrinter::printInt(
StringRef Name, IntTy
Int,
bool ShouldSkipZero) {
2064 if (ShouldSkipZero && !
Int)
2071 bool IsUnsigned,
bool ShouldSkipZero) {
2072 if (ShouldSkipZero &&
Int.isZero())
2076 Int.print(Out, !IsUnsigned);
2080 std::optional<bool>
Default) {
2096 for (
auto F : SplitFlags) {
2098 assert(!StringF.empty() &&
"Expected valid flag");
2099 Out << FlagsFS << StringF;
2101 if (Extra || SplitFlags.empty())
2102 Out << FlagsFS << Extra;
2105void MDFieldPrinter::printDISPFlags(
StringRef Name,
2120 for (
auto F : SplitFlags) {
2122 assert(!StringF.empty() &&
"Expected valid flag");
2123 Out << FlagsFS << StringF;
2125 if (Extra || SplitFlags.empty())
2126 Out << FlagsFS << Extra;
2129void MDFieldPrinter::printEmissionKind(
StringRef Name,
2134void MDFieldPrinter::printNameTableKind(
StringRef Name,
2141void MDFieldPrinter::printFixedPointKind(
StringRef Name,
2146template <
class IntTy,
class Stringifier>
2148 Stringifier
toString,
bool ShouldSkipZero) {
2149 if (ShouldSkipZero && !
Value)
2161 AsmWriterContext &WriterCtx) {
2162 Out <<
"!GenericDINode(";
2163 MDFieldPrinter
Printer(Out, WriterCtx);
2165 Printer.printString(
"header",
N->getHeader());
2166 if (
N->getNumDwarfOperands()) {
2167 Out <<
Printer.FS <<
"operands: {";
2169 for (
auto &
I :
N->dwarf_operands()) {
2179 AsmWriterContext &WriterCtx) {
2180 Out <<
"!DILocation(";
2181 MDFieldPrinter
Printer(Out, WriterCtx);
2183 Printer.printInt(
"line",
DL->getLine(),
false);
2184 Printer.printInt(
"column",
DL->getColumn());
2185 Printer.printMetadata(
"scope",
DL->getRawScope(),
false);
2186 Printer.printMetadata(
"inlinedAt",
DL->getRawInlinedAt());
2187 Printer.printBool(
"isImplicitCode",
DL->isImplicitCode(),
2189 Printer.printInt(
"atomGroup",
DL->getAtomGroup());
2190 Printer.printInt<
unsigned>(
"atomRank",
DL->getAtomRank());
2191 Printer.printMetadata(
"irlayers",
DL->getRawIRLayers());
2196 AsmWriterContext &WriterCtx) {
2197 Out <<
"!DILayerLoc(";
2198 MDFieldPrinter
Printer(Out, WriterCtx);
2199 Printer.printInt(
"line",
N->getLine(),
false);
2200 Printer.printInt(
"column",
N->getColumn());
2201 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2202 Printer.printString(
"kind",
N->getKind(),
false);
2207 AsmWriterContext &WriterCtx) {
2208 Out <<
"!DILayerLocList(";
2218 AsmWriterContext &WriterCtx) {
2219 Out <<
"!DIAssignID()";
2220 MDFieldPrinter
Printer(Out, WriterCtx);
2224 AsmWriterContext &WriterCtx) {
2225 Out <<
"!DISubrange(";
2226 MDFieldPrinter
Printer(Out, WriterCtx);
2228 Printer.printMetadataOrInt(
"count",
N->getRawCountNode(),
2234 Printer.printMetadataOrInt(
"lowerBound",
N->getRawLowerBound(),
2237 Printer.printMetadataOrInt(
"upperBound",
N->getRawUpperBound(),
2240 Printer.printMetadataOrInt(
"stride",
N->getRawStride(),
2248 AsmWriterContext &WriterCtx) {
2249 Out <<
"!DIGenericSubrange(";
2250 MDFieldPrinter
Printer(Out, WriterCtx);
2252 auto GetConstant = [&](
Metadata *Bound) -> std::optional<int64_t> {
2255 return std::nullopt;
2256 if (BE->isConstant() &&
2258 *BE->isConstant()) {
2259 return static_cast<int64_t
>(BE->getElement(1));
2261 return std::nullopt;
2264 auto *
Count =
N->getRawCountNode();
2265 if (
auto ConstantCount = GetConstant(
Count))
2266 Printer.printInt(
"count", *ConstantCount,
2271 auto *LBound =
N->getRawLowerBound();
2272 if (
auto ConstantLBound = GetConstant(LBound))
2273 Printer.printInt(
"lowerBound", *ConstantLBound,
2276 Printer.printMetadata(
"lowerBound", LBound,
true);
2278 auto *UBound =
N->getRawUpperBound();
2279 if (
auto ConstantUBound = GetConstant(UBound))
2280 Printer.printInt(
"upperBound", *ConstantUBound,
2283 Printer.printMetadata(
"upperBound", UBound,
true);
2285 auto *Stride =
N->getRawStride();
2286 if (
auto ConstantStride = GetConstant(Stride))
2287 Printer.printInt(
"stride", *ConstantStride,
2290 Printer.printMetadata(
"stride", Stride,
true);
2296 AsmWriterContext &) {
2297 Out <<
"!DIEnumerator(";
2299 Printer.printString(
"name",
N->getName(),
false);
2300 Printer.printAPInt(
"value",
N->getValue(),
N->isUnsigned(),
2302 if (
N->isUnsigned())
2303 Printer.printBool(
"isUnsigned",
true);
2308 AsmWriterContext &WriterCtx) {
2309 Out <<
"!DIBasicType(";
2310 MDFieldPrinter
Printer(Out, WriterCtx);
2311 if (
N->getTag() != dwarf::DW_TAG_base_type)
2313 Printer.printString(
"name",
N->getName());
2314 Printer.printMetadata(
"scope",
N->getRawScope());
2315 Printer.printMetadata(
"file",
N->getRawFile());
2316 Printer.printInt(
"line",
N->getLine());
2317 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2318 Printer.printInt(
"align",
N->getAlignInBits());
2319 Printer.printInt(
"dataSize",
N->getDataSizeInBits());
2320 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2322 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2323 Printer.printDIFlags(
"flags",
N->getFlags());
2328 AsmWriterContext &WriterCtx) {
2329 Out <<
"!DIFixedPointType(";
2330 MDFieldPrinter
Printer(Out, WriterCtx);
2331 if (
N->getTag() != dwarf::DW_TAG_base_type)
2333 Printer.printString(
"name",
N->getName());
2334 Printer.printMetadata(
"scope",
N->getRawScope());
2335 Printer.printMetadata(
"file",
N->getRawFile());
2336 Printer.printInt(
"line",
N->getLine());
2337 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2338 Printer.printInt(
"align",
N->getAlignInBits());
2339 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2341 Printer.printDIFlags(
"flags",
N->getFlags());
2342 Printer.printFixedPointKind(
"kind",
N->getKind());
2343 if (
N->isRational()) {
2344 bool IsUnsigned = !
N->isSigned();
2345 Printer.printAPInt(
"numerator",
N->getNumerator(), IsUnsigned,
false);
2346 Printer.printAPInt(
"denominator",
N->getDenominator(), IsUnsigned,
false);
2348 Printer.printInt(
"factor",
N->getFactor());
2354 AsmWriterContext &WriterCtx) {
2355 Out <<
"!DIStringType(";
2356 MDFieldPrinter
Printer(Out, WriterCtx);
2357 if (
N->getTag() != dwarf::DW_TAG_string_type)
2359 Printer.printString(
"name",
N->getName());
2360 Printer.printMetadata(
"stringLength",
N->getRawStringLength());
2361 Printer.printMetadata(
"stringLengthExpression",
N->getRawStringLengthExp());
2362 Printer.printMetadata(
"stringLocationExpression",
2363 N->getRawStringLocationExp());
2364 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2365 Printer.printInt(
"align",
N->getAlignInBits());
2366 Printer.printDwarfEnum(
"encoding",
N->getEncoding(),
2368 Printer.printMetadata(
"charType",
N->getRawCharType());
2373 AsmWriterContext &WriterCtx) {
2374 Out <<
"!DIDerivedType(";
2375 MDFieldPrinter
Printer(Out, WriterCtx);
2377 Printer.printString(
"name",
N->getName());
2378 Printer.printMetadata(
"scope",
N->getRawScope());
2379 Printer.printMetadata(
"file",
N->getRawFile());
2380 Printer.printInt(
"line",
N->getLine());
2381 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2383 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2384 Printer.printInt(
"align",
N->getAlignInBits());
2385 Printer.printMetadataOrInt(
"offset",
N->getRawOffsetInBits(),
true);
2386 Printer.printDIFlags(
"flags",
N->getFlags());
2387 Printer.printMetadata(
"extraData",
N->getRawExtraData());
2388 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
2389 Printer.printInt(
"dwarfAddressSpace", *DWARFAddressSpace,
2391 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2392 if (
auto PtrAuthData =
N->getPtrAuthData()) {
2393 Printer.printInt(
"ptrAuthKey", PtrAuthData->key());
2394 Printer.printBool(
"ptrAuthIsAddressDiscriminated",
2395 PtrAuthData->isAddressDiscriminated());
2396 Printer.printInt(
"ptrAuthExtraDiscriminator",
2397 PtrAuthData->extraDiscriminator());
2398 Printer.printBool(
"ptrAuthIsaPointer", PtrAuthData->isaPointer());
2399 Printer.printBool(
"ptrAuthAuthenticatesNullValues",
2400 PtrAuthData->authenticatesNullValues());
2406 AsmWriterContext &WriterCtx) {
2407 Out <<
"!DISubrangeType(";
2408 MDFieldPrinter
Printer(Out, WriterCtx);
2409 Printer.printString(
"name",
N->getName());
2410 Printer.printMetadata(
"scope",
N->getRawScope());
2411 Printer.printMetadata(
"file",
N->getRawFile());
2412 Printer.printInt(
"line",
N->getLine());
2413 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2414 Printer.printInt(
"align",
N->getAlignInBits());
2415 Printer.printDIFlags(
"flags",
N->getFlags());
2416 Printer.printMetadata(
"baseType",
N->getRawBaseType(),
2418 Printer.printMetadata(
"lowerBound",
N->getRawLowerBound());
2419 Printer.printMetadata(
"upperBound",
N->getRawUpperBound());
2420 Printer.printMetadata(
"stride",
N->getRawStride());
2421 Printer.printMetadata(
"bias",
N->getRawBias());
2426 AsmWriterContext &WriterCtx) {
2427 Out <<
"!DICompositeType(";
2428 MDFieldPrinter
Printer(Out, WriterCtx);
2430 Printer.printString(
"name",
N->getName());
2431 Printer.printMetadata(
"scope",
N->getRawScope());
2432 Printer.printMetadata(
"file",
N->getRawFile());
2433 Printer.printInt(
"line",
N->getLine());
2434 Printer.printMetadata(
"baseType",
N->getRawBaseType());
2435 Printer.printMetadataOrInt(
"size",
N->getRawSizeInBits(),
true);
2436 Printer.printInt(
"align",
N->getAlignInBits());
2437 Printer.printMetadataOrInt(
"offset",
N->getRawOffsetInBits(),
true);
2438 Printer.printInt(
"num_extra_inhabitants",
N->getNumExtraInhabitants());
2439 Printer.printDIFlags(
"flags",
N->getFlags());
2440 Printer.printMetadata(
"elements",
N->getRawElements());
2441 Printer.printDwarfEnum(
"runtimeLang",
N->getRuntimeLang(),
2443 Printer.printMetadata(
"vtableHolder",
N->getRawVTableHolder());
2444 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2445 Printer.printString(
"identifier",
N->getIdentifier());
2446 Printer.printMetadata(
"discriminator",
N->getRawDiscriminator());
2447 Printer.printMetadata(
"dataLocation",
N->getRawDataLocation());
2448 Printer.printMetadata(
"associated",
N->getRawAssociated());
2449 Printer.printMetadata(
"allocated",
N->getRawAllocated());
2450 if (
auto *RankConst =
N->getRankConst())
2451 Printer.printInt(
"rank", RankConst->getSExtValue(),
2454 Printer.printMetadata(
"rank",
N->getRawRank(),
true);
2455 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2456 if (
auto *Specification =
N->getRawSpecification())
2457 Printer.printMetadata(
"specification", Specification);
2459 if (
auto EnumKind =
N->getEnumKind())
2463 Printer.printMetadata(
"bitStride",
N->getRawBitStride());
2468 AsmWriterContext &WriterCtx) {
2469 Out <<
"!DISubroutineType(";
2470 MDFieldPrinter
Printer(Out, WriterCtx);
2471 Printer.printDIFlags(
"flags",
N->getFlags());
2473 Printer.printMetadata(
"types",
N->getRawTypeArray(),
2481 Printer.printString(
"filename",
N->getFilename(),
2483 Printer.printString(
"directory",
N->getDirectory(),
2486 if (
N->getChecksum())
2487 Printer.printChecksum(*
N->getChecksum());
2489 Printer.printString(
"source", *
N->getSource(),
2495 AsmWriterContext &WriterCtx) {
2496 Out <<
"!DICompileUnit(";
2497 MDFieldPrinter
Printer(Out, WriterCtx);
2503 "sourceLanguageName",
2515 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2516 Printer.printString(
"producer",
N->getProducer());
2517 Printer.printBool(
"isOptimized",
N->isOptimized());
2518 Printer.printString(
"flags",
N->getFlags());
2519 Printer.printInt(
"runtimeVersion",
N->getRuntimeVersion(),
2521 Printer.printString(
"splitDebugFilename",
N->getSplitDebugFilename());
2522 Printer.printEmissionKind(
"emissionKind",
N->getEmissionKind());
2523 Printer.printMetadata(
"enums",
N->getRawEnumTypes());
2524 Printer.printMetadata(
"retainedTypes",
N->getRawRetainedTypes());
2525 Printer.printMetadata(
"globals",
N->getRawGlobalVariables());
2526 Printer.printMetadata(
"imports",
N->getRawImportedEntities());
2527 Printer.printMetadata(
"macros",
N->getRawMacros());
2528 Printer.printInt(
"dwoId",
N->getDWOId());
2529 Printer.printBool(
"splitDebugInlining",
N->getSplitDebugInlining(),
true);
2530 Printer.printBool(
"debugInfoForProfiling",
N->getDebugInfoForProfiling(),
2532 Printer.printNameTableKind(
"nameTableKind",
N->getNameTableKind());
2533 Printer.printBool(
"rangesBaseAddress",
N->getRangesBaseAddress(),
false);
2534 Printer.printString(
"sysroot",
N->getSysRoot());
2535 Printer.printString(
"sdk",
N->getSDK());
2542 AsmWriterContext &WriterCtx) {
2543 Out <<
"!DISubprogram(";
2544 MDFieldPrinter
Printer(Out, WriterCtx);
2545 Printer.printString(
"name",
N->getName());
2546 Printer.printString(
"linkageName",
N->getLinkageName());
2547 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2548 Printer.printMetadata(
"file",
N->getRawFile());
2549 Printer.printInt(
"line",
N->getLine());
2550 Printer.printMetadata(
"type",
N->getRawType());
2551 Printer.printInt(
"scopeLine",
N->getScopeLine());
2552 Printer.printMetadata(
"containingType",
N->getRawContainingType());
2553 if (
N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||
2554 N->getVirtualIndex() != 0)
2555 Printer.printInt(
"virtualIndex",
N->getVirtualIndex(),
false);
2556 Printer.printInt(
"thisAdjustment",
N->getThisAdjustment());
2557 Printer.printDIFlags(
"flags",
N->getFlags());
2558 Printer.printDISPFlags(
"spFlags",
N->getSPFlags());
2559 Printer.printMetadata(
"unit",
N->getRawUnit());
2560 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2561 Printer.printMetadata(
"declaration",
N->getRawDeclaration());
2562 Printer.printMetadata(
"retainedNodes",
N->getRawRetainedNodes());
2563 Printer.printMetadata(
"thrownTypes",
N->getRawThrownTypes());
2564 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2565 Printer.printString(
"targetFuncName",
N->getTargetFuncName());
2566 Printer.printBool(
"keyInstructions",
N->getKeyInstructionsEnabled(),
false);
2571 AsmWriterContext &WriterCtx) {
2572 Out <<
"!DILexicalBlock(";
2573 MDFieldPrinter
Printer(Out, WriterCtx);
2574 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2575 Printer.printMetadata(
"file",
N->getRawFile());
2576 Printer.printInt(
"line",
N->getLine());
2577 Printer.printInt(
"column",
N->getColumn());
2583 AsmWriterContext &WriterCtx) {
2584 Out <<
"!DILexicalBlockFile(";
2585 MDFieldPrinter
Printer(Out, WriterCtx);
2586 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2587 Printer.printMetadata(
"file",
N->getRawFile());
2588 Printer.printInt(
"discriminator",
N->getDiscriminator(),
2594 AsmWriterContext &WriterCtx) {
2595 Out <<
"!DINamespace(";
2596 MDFieldPrinter
Printer(Out, WriterCtx);
2597 Printer.printString(
"name",
N->getName());
2598 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2599 Printer.printBool(
"exportSymbols",
N->getExportSymbols(),
false);
2604 AsmWriterContext &WriterCtx) {
2605 Out <<
"!DICommonBlock(";
2606 MDFieldPrinter
Printer(Out, WriterCtx);
2607 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2608 Printer.printMetadata(
"declaration",
N->getRawDecl(),
false);
2609 Printer.printString(
"name",
N->getName());
2610 Printer.printMetadata(
"file",
N->getRawFile());
2611 Printer.printInt(
"line",
N->getLineNo());
2616 AsmWriterContext &WriterCtx) {
2618 MDFieldPrinter
Printer(Out, WriterCtx);
2620 Printer.printInt(
"line",
N->getLine());
2621 Printer.printString(
"name",
N->getName());
2622 Printer.printString(
"value",
N->getValue());
2627 AsmWriterContext &WriterCtx) {
2628 Out <<
"!DIMacroFile(";
2629 MDFieldPrinter
Printer(Out, WriterCtx);
2630 Printer.printInt(
"line",
N->getLine());
2631 Printer.printMetadata(
"file",
N->getRawFile(),
false);
2632 Printer.printMetadata(
"nodes",
N->getRawElements());
2637 AsmWriterContext &WriterCtx) {
2638 Out <<
"!DIModule(";
2639 MDFieldPrinter
Printer(Out, WriterCtx);
2640 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2641 Printer.printString(
"name",
N->getName());
2642 Printer.printString(
"configMacros",
N->getConfigurationMacros());
2643 Printer.printString(
"includePath",
N->getIncludePath());
2644 Printer.printString(
"apinotes",
N->getAPINotesFile());
2645 Printer.printMetadata(
"file",
N->getRawFile());
2646 Printer.printInt(
"line",
N->getLineNo());
2647 Printer.printBool(
"isDecl",
N->getIsDecl(),
false);
2653 AsmWriterContext &WriterCtx) {
2654 Out <<
"!DITemplateTypeParameter(";
2655 MDFieldPrinter
Printer(Out, WriterCtx);
2656 Printer.printString(
"name",
N->getName());
2657 Printer.printMetadata(
"type",
N->getRawType(),
false);
2658 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2664 AsmWriterContext &WriterCtx) {
2665 Out <<
"!DITemplateValueParameter(";
2666 MDFieldPrinter
Printer(Out, WriterCtx);
2667 if (
N->getTag() != dwarf::DW_TAG_template_value_parameter)
2669 Printer.printString(
"name",
N->getName());
2670 Printer.printMetadata(
"type",
N->getRawType());
2671 Printer.printBool(
"defaulted",
N->isDefault(),
false);
2672 Printer.printMetadata(
"value",
N->getValue(),
false);
2677 AsmWriterContext &WriterCtx) {
2678 Out <<
"!DIGlobalVariable(";
2679 MDFieldPrinter
Printer(Out, WriterCtx);
2680 Printer.printString(
"name",
N->getName());
2681 Printer.printString(
"linkageName",
N->getLinkageName());
2682 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2683 Printer.printMetadata(
"file",
N->getRawFile());
2684 Printer.printInt(
"line",
N->getLine());
2685 Printer.printMetadata(
"type",
N->getRawType());
2686 Printer.printBool(
"isLocal",
N->isLocalToUnit());
2687 Printer.printBool(
"isDefinition",
N->isDefinition());
2688 Printer.printMetadata(
"declaration",
N->getRawStaticDataMemberDeclaration());
2689 Printer.printMetadata(
"templateParams",
N->getRawTemplateParams());
2690 Printer.printInt(
"align",
N->getAlignInBits());
2691 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2696 AsmWriterContext &WriterCtx) {
2697 Out <<
"!DILocalVariable(";
2698 MDFieldPrinter
Printer(Out, WriterCtx);
2699 Printer.printString(
"name",
N->getName());
2700 Printer.printInt(
"arg",
N->getArg());
2701 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2702 Printer.printMetadata(
"file",
N->getRawFile());
2703 Printer.printInt(
"line",
N->getLine());
2704 Printer.printMetadata(
"type",
N->getRawType());
2705 Printer.printDIFlags(
"flags",
N->getFlags());
2706 Printer.printInt(
"align",
N->getAlignInBits());
2707 Printer.printMetadata(
"annotations",
N->getRawAnnotations());
2712 AsmWriterContext &WriterCtx) {
2714 MDFieldPrinter
Printer(Out, WriterCtx);
2715 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2716 Printer.printString(
"name",
N->getName());
2717 Printer.printMetadata(
"file",
N->getRawFile());
2718 Printer.printInt(
"line",
N->getLine(),
false);
2719 Printer.printInt(
"column",
N->getColumn());
2720 Printer.printBool(
"isArtificial",
N->isArtificial(),
false);
2721 if (
N->getCoroSuspendIdx())
2722 Printer.printInt(
"coroSuspendIdx", *
N->getCoroSuspendIdx(),
2728 AsmWriterContext &WriterCtx) {
2729 Out <<
"!DIExpression(";
2734 assert(!OpStr.empty() &&
"Expected valid opcode");
2738 Out << FS << Convert.getBitSize();
2741 for (
unsigned A = 0, AE =
Op.getNumArgs();
A != AE; ++
A)
2742 Out << FS <<
Op.getArg(
A);
2746 for (
const auto &
I :
N->getElements())
2753 AsmWriterContext &WriterCtx,
2754 bool FromValue =
false) {
2756 "Unexpected DIArgList metadata outside of value argument");
2757 Out <<
"!DIArgList(";
2759 MDFieldPrinter
Printer(Out, WriterCtx);
2760 for (
const Metadata *Arg :
N->getArgs()) {
2769 AsmWriterContext &WriterCtx) {
2770 Out <<
"!DIGlobalVariableExpression(";
2771 MDFieldPrinter
Printer(Out, WriterCtx);
2772 Printer.printMetadata(
"var",
N->getVariable());
2773 Printer.printMetadata(
"expr",
N->getExpression());
2778 AsmWriterContext &WriterCtx) {
2779 Out <<
"!DIObjCProperty(";
2780 MDFieldPrinter
Printer(Out, WriterCtx);
2781 Printer.printString(
"name",
N->getName());
2782 Printer.printMetadata(
"file",
N->getRawFile());
2783 Printer.printInt(
"line",
N->getLine());
2784 Printer.printString(
"setter",
N->getSetterName());
2785 Printer.printString(
"getter",
N->getGetterName());
2786 Printer.printInt(
"attributes",
N->getAttributes());
2787 Printer.printMetadata(
"type",
N->getRawType());
2792 AsmWriterContext &WriterCtx) {
2793 Out <<
"!DIProperty(";
2794 MDFieldPrinter
Printer(Out, WriterCtx);
2795 Printer.printString(
"name",
N->getName());
2796 Printer.printMetadata(
"file",
N->getRawFile());
2797 Printer.printInt(
"line",
N->getLine());
2798 Printer.printMetadata(
"type",
N->getRawType());
2799 Printer.printMetadata(
"backing_storage",
N->getRawBackingStorage());
2804 AsmWriterContext &WriterCtx) {
2805 Out <<
"!DIImportedEntity(";
2806 MDFieldPrinter
Printer(Out, WriterCtx);
2808 Printer.printString(
"name",
N->getName());
2809 Printer.printMetadata(
"scope",
N->getRawScope(),
false);
2810 Printer.printMetadata(
"entity",
N->getRawEntity());
2811 Printer.printMetadata(
"file",
N->getRawFile());
2812 Printer.printInt(
"line",
N->getLine());
2813 Printer.printMetadata(
"elements",
N->getRawElements());
2818 AsmWriterContext &Ctx) {
2819 if (
Node->isDistinct())
2821 else if (
Node->isTemporary())
2822 Out <<
"<temporary!> ";
2824 switch (
Node->getMetadataID()) {
2827#define HANDLE_MDNODE_LEAF(CLASS) \
2828 case Metadata::CLASS##Kind: \
2829 write##CLASS(Out, cast<CLASS>(Node), Ctx); \
2831#include "llvm/IR/Metadata.def"
2838 AsmWriterContext &WriterCtx,
2841 WriterCtx.TypePrinter->print(V->getType(), Out);
2852 assert(WriterCtx.TypePrinter &&
"Constants require TypePrinting!");
2859 if (IA->hasSideEffects())
2860 Out <<
"sideeffect ";
2861 if (IA->isAlignStack())
2862 Out <<
"alignstack ";
2865 Out <<
"inteldialect ";
2884 auto *
Machine = WriterCtx.Machine;
2888 Slot =
Machine->getGlobalSlot(GV);
2891 Slot =
Machine->getLocalSlot(V);
2898 Slot =
Machine->getLocalSlot(V);
2905 Slot =
Machine->getGlobalSlot(GV);
2908 Slot =
Machine->getLocalSlot(V);
2917 Out << Prefix << Slot;
2923 AsmWriterContext &WriterCtx,
2938 Loc && WriterCtx.MST &&
2944 std::unique_ptr<SlotTracker> MachineStorage;
2946 if (!WriterCtx.Machine) {
2947 MachineStorage = std::make_unique<SlotTracker>(WriterCtx.Context);
2948 WriterCtx.Machine = MachineStorage.get();
2958 Out <<
"<" <<
N <<
">";
2972 assert(WriterCtx.TypePrinter &&
"TypePrinter required for metadata values");
2974 "Unexpected function-local metadata outside of value argument");
2981class AssemblyWriter {
2982 formatted_raw_ostream &
Out;
2983 const Module *TheModule =
nullptr;
2984 const ModuleSummaryIndex *TheIndex =
nullptr;
2985 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2987 TypePrinting TypePrinter;
2988 AssemblyAnnotationWriter *AnnotationWriter =
nullptr;
2990 bool ShouldPreserveUseListOrder;
2995 DenseMap<const GlobalValueSummary *, GlobalValue::GUID> SummaryToGUIDMap;
2999 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M,
3000 AssemblyAnnotationWriter *AAW,
bool IsForDebug,
3001 bool ShouldPreserveUseListOrder =
false);
3003 AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
3004 const ModuleSummaryIndex *Index,
bool IsForDebug);
3007 return AsmWriterContext(&TypePrinter, &
Machine, TheModule);
3010 void printMDNodeBody(
const MDNode *MD);
3011 void printNamedMDNode(
const NamedMDNode *NMD);
3013 void printModule(
const Module *M);
3015 void writeOperand(
const Value *
Op,
bool PrintType);
3016 void writeParamOperand(
const Value *Operand, AttributeSet Attrs);
3017 void writeOperandBundles(
const CallBase *
Call);
3018 void writeSyncScope(
const LLVMContext &
Context,
3020 void writeAtomic(
const LLVMContext &
Context,
3023 void writeAtomicCmpXchg(
const LLVMContext &
Context,
3028 void writeAllMDNodes();
3029 void writeMDNode(
unsigned Slot,
const MDNode *Node);
3030 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
3031 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
3032 void writeAllAttributeGroups();
3034 void printTypeIdentities();
3035 void printGlobal(
const GlobalVariable *GV);
3036 void printAlias(
const GlobalAlias *GA);
3037 void printIFunc(
const GlobalIFunc *GI);
3038 void printComdat(
const Comdat *
C);
3040 void printArgument(
const Argument *FA, AttributeSet Attrs);
3042 void printInstructionLine(
const Instruction &
I);
3043 void printInstruction(
const Instruction &
I);
3044 void printDbgMarker(
const DbgMarker &DPI);
3045 void printDbgVariableRecord(
const DbgVariableRecord &DVR);
3046 void printDbgLabelRecord(
const DbgLabelRecord &DLR);
3047 void printDbgRecord(
const DbgRecord &DR);
3048 void printDbgRecordLine(
const DbgRecord &DR);
3050 void printUseListOrder(
const Value *V, ArrayRef<unsigned> Shuffle);
3053 void printModuleSummaryIndex();
3054 void printSummaryInfo(
unsigned Slot,
const ValueInfo &VI);
3055 void printSummary(
const GlobalValueSummary &Summary);
3056 void printAliasSummary(
const AliasSummary *AS);
3057 void printGlobalVarSummary(
const GlobalVarSummary *GS);
3058 void printFunctionSummary(
const FunctionSummary *FS);
3059 void printTypeIdSummary(
const TypeIdSummary &TIS);
3061 void printTypeTestResolution(
const TypeTestResolution &TTRes);
3062 void printArgs(ArrayRef<uint64_t> Args);
3063 void printWPDRes(
const WholeProgramDevirtResolution &WPDRes);
3064 void printTypeIdInfo(
const FunctionSummary::TypeIdInfo &TIDInfo);
3065 void printVFuncId(
const FunctionSummary::VFuncId VFId);
3073 void printMetadataAttachments(
3074 const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,
3075 StringRef Separator);
3079 void printInfoComment(
const Value &V,
bool isMaterializable =
false);
3083 void printGCRelocateComment(
const GCRelocateInst &Relocate);
3090 bool IsForDebug,
bool ShouldPreserveUseListOrder)
3091 :
Out(
o), TheModule(
M),
Machine(Mac), TypePrinter(
M), AnnotationWriter(AAW),
3092 IsForDebug(IsForDebug),
3093 ShouldPreserveUseListOrder(
3096 : ShouldPreserveUseListOrder) {}
3100 :
Out(
o), TheIndex(Index),
Machine(Mac), TypePrinter(nullptr),
3101 IsForDebug(IsForDebug),
3104void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
3106 Out <<
"<null operand!>";
3113void AssemblyWriter::writeSyncScope(
const LLVMContext &
Context,
3121 Context.getSyncScopeNames(SSNs);
3123 Out <<
" syncscope(\"";
3131void AssemblyWriter::writeAtomic(
const LLVMContext &
Context,
3134 if (Ordering == AtomicOrdering::NotAtomic)
3137 writeSyncScope(
Context, SSID);
3141void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &
Context,
3145 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&
3146 FailureOrdering != AtomicOrdering::NotAtomic);
3148 writeSyncScope(
Context, SSID);
3153void AssemblyWriter::writeParamOperand(
const Value *Operand,
3154 AttributeSet Attrs) {
3156 Out <<
"<null operand!>";
3161 TypePrinter.print(Operand->
getType(), Out);
3163 if (
Attrs.hasAttributes()) {
3165 writeAttributeSet(Attrs);
3173void AssemblyWriter::writeOperandBundles(
const CallBase *
Call) {
3189 ListSeparator InnerLS;
3191 for (
const auto &Input : BU.
Inputs) {
3193 if (Input ==
nullptr)
3194 Out <<
"<null operand bundle!>";
3205void AssemblyWriter::printModule(
const Module *M) {
3208 if (ShouldPreserveUseListOrder)
3211 if (!
M->getModuleIdentifier().empty() &&
3214 M->getModuleIdentifier().find(
'\n') == std::string::npos)
3215 Out <<
"; ModuleID = '" <<
M->getModuleIdentifier() <<
"'\n";
3217 if (!
M->getSourceFileName().empty()) {
3218 Out <<
"source_filename = \"";
3223 const std::string &
DL =
M->getDataLayoutStr();
3225 Out <<
"target datalayout = \"" <<
DL <<
"\"\n";
3226 if (!
M->getTargetTriple().empty())
3227 Out <<
"target triple = \"" <<
M->getTargetTriple().str() <<
"\"\n";
3229 if (
M->hasModuleInlineAsm()) {
3232 for (
const Module::GlobalAsmFragment &Frag :
M->getModuleInlineAsm()) {
3233 Out <<
"module asm";
3235 Frag.Props.getAsStrings();
3236 if (!Props.
empty()) {
3241 Out <<
Key <<
": \"";
3249 StringRef
Asm = Frag.Asm;
3252 std::tie(Front, Asm) =
Asm.split(
'\n');
3259 }
while (!
Asm.empty());
3263 printTypeIdentities();
3267 SmallPtrSet<const Comdat *, 8> PrintedComdats;
3268 for (
const GlobalObject &GO :
M->global_objects()) {
3270 if (!
C || !PrintedComdats.
insert(
C).second)
3278 if (!
M->global_empty()) Out <<
'\n';
3279 for (
const GlobalVariable &GV :
M->globals()) {
3280 printGlobal(&GV); Out <<
'\n';
3284 if (!
M->alias_empty()) Out <<
"\n";
3285 for (
const GlobalAlias &GA :
M->aliases())
3289 if (!
M->ifunc_empty()) Out <<
"\n";
3290 for (
const GlobalIFunc &GI :
M->ifuncs())
3300 printUseLists(
nullptr);
3305 writeAllAttributeGroups();
3309 if (!
M->named_metadata_empty()) Out <<
'\n';
3311 for (
const NamedMDNode &Node :
M->named_metadata())
3312 printNamedMDNode(&Node);
3321void AssemblyWriter::printModuleSummaryIndex() {
3323 int NumSlots =
Machine.initializeIndexIfNeeded();
3329 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
3330 std::string RegularLTOModuleName =
3333 for (
auto &[ModPath, ModHash] : TheIndex->
modulePaths())
3334 moduleVec[
Machine.getModulePathSlot(ModPath)] = std::make_pair(
3337 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);
3340 for (
auto &ModPair : moduleVec) {
3341 Out <<
"^" << i++ <<
" = module: (";
3344 Out <<
"\", hash: (";
3346 for (
auto Hash : ModPair.second)
3356 for (
const auto &GlobalList : SortedGVS) {
3357 auto GUID = GlobalList.first;
3358 for (
auto &Summary : GlobalList.second.getSummaryList())
3363 for (
const auto &GlobalList : SortedGVS) {
3364 auto GUID = GlobalList.first;
3366 printSummaryInfo(
Machine.getGUIDSlot(GUID), VI);
3370 for (
const auto &TID : TheIndex->
typeIds()) {
3371 Out <<
"^" <<
Machine.getTypeIdSlot(TID.second.first)
3372 <<
" = typeid: (name: \"" << TID.second.first <<
"\"";
3373 printTypeIdSummary(TID.second.second);
3374 Out <<
") ; guid = " << TID.first <<
"\n";
3380 Out <<
"^" <<
Machine.getTypeIdCompatibleVtableSlot(TId.first)
3381 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
3382 printTypeIdCompatibleVtableSummary(TId.second);
3383 Out <<
") ; guid = " <<
GUID <<
"\n";
3388 Out <<
"^" << NumSlots <<
" = flags: " << TheIndex->
getFlags() <<
"\n";
3392 Out <<
"^" << NumSlots <<
" = blockcount: " << TheIndex->
getBlockCount()
3402 return "singleImpl";
3404 return "branchFunnel";
3415 return "uniformRetVal";
3417 return "uniqueRetVal";
3419 return "virtualConstProp";
3442void AssemblyWriter::printTypeTestResolution(
const TypeTestResolution &TTRes) {
3449 Out <<
", alignLog2: " << TTRes.
AlignLog2;
3451 Out <<
", sizeM1: " << TTRes.
SizeM1;
3454 Out <<
", bitMask: " << (unsigned)TTRes.
BitMask;
3461void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
3462 Out <<
", summary: (";
3463 printTypeTestResolution(TIS.
TTRes);
3464 if (!TIS.
WPDRes.empty()) {
3465 Out <<
", wpdResolutions: (";
3467 for (
auto &WPDRes : TIS.
WPDRes) {
3469 Out <<
"(offset: " << WPDRes.first <<
", ";
3470 printWPDRes(WPDRes.second);
3478void AssemblyWriter::printTypeIdCompatibleVtableSummary(
3480 Out <<
", summary: (";
3482 for (
auto &
P : TI) {
3484 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
3485 Out <<
"^" <<
Machine.getGUIDSlot(
P.VTableVI.getGUID());
3491void AssemblyWriter::printArgs(ArrayRef<uint64_t> Args) {
3495void AssemblyWriter::printWPDRes(
const WholeProgramDevirtResolution &WPDRes) {
3496 Out <<
"wpdRes: (kind: ";
3503 Out <<
", resByArg: (";
3505 for (
auto &ResByArg : WPDRes.
ResByArg) {
3507 printArgs(ResByArg.first);
3508 Out <<
", byArg: (kind: ";
3510 if (ResByArg.second.TheKind ==
3512 ResByArg.second.TheKind ==
3514 Out <<
", info: " << ResByArg.second.Info;
3518 if (ResByArg.second.Byte || ResByArg.second.Bit)
3519 Out <<
", byte: " << ResByArg.second.Byte
3520 <<
", bit: " << ResByArg.second.Bit;
3541void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
3542 Out <<
", aliasee: ";
3552void AssemblyWriter::printGlobalVarSummary(
const GlobalVarSummary *GS) {
3553 auto VTableFuncs =
GS->vTableFuncs();
3554 Out <<
", varFlags: (readonly: " <<
GS->VarFlags.MaybeReadOnly <<
", "
3555 <<
"writeonly: " <<
GS->VarFlags.MaybeWriteOnly <<
", "
3556 <<
"constant: " <<
GS->VarFlags.Constant;
3557 if (!VTableFuncs.empty())
3559 <<
"vcall_visibility: " <<
GS->VarFlags.VCallVisibility;
3562 if (!VTableFuncs.empty()) {
3563 Out <<
", vTableFuncs: (";
3565 for (
auto &
P : VTableFuncs) {
3567 Out <<
"(virtFunc: ^" <<
Machine.getGUIDSlot(
P.FuncVI.getGUID())
3568 <<
", offset: " <<
P.VTableOffset;
3586 return "linkonce_odr";
3596 return "extern_weak";
3598 return "available_externally";
3627 return "definition";
3629 return "declaration";
3634void AssemblyWriter::printFunctionSummary(
const FunctionSummary *FS) {
3635 Out <<
", insts: " <<
FS->instCount();
3636 if (
FS->fflags().anyFlagSet())
3637 Out <<
", " <<
FS->fflags();
3639 if (!
FS->calls().empty()) {
3640 Out <<
", calls: (";
3642 for (
auto &
Call :
FS->calls()) {
3644 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.first.getGUID());
3645 if (
Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)
3649 if (
Call.second.HasTailCall)
3656 if (
const auto *TIdInfo =
FS->getTypeIdInfo())
3657 printTypeIdInfo(*TIdInfo);
3661 auto AllocTypeName = [](uint8_t
Type) ->
const char * {
3663 case (uint8_t)AllocationType::None:
3665 case (uint8_t)AllocationType::NotCold:
3667 case (uint8_t)AllocationType::Cold:
3669 case (uint8_t)AllocationType::Hot:
3675 if (!
FS->allocs().empty()) {
3676 Out <<
", allocs: (";
3678 for (
auto &AI :
FS->allocs()) {
3680 Out <<
"(versions: (";
3682 for (
auto V : AI.Versions) {
3684 Out << AllocTypeName(V);
3686 Out <<
"), memProf: (";
3687 ListSeparator MIBFS;
3688 for (
auto &MIB : AI.MIBs) {
3690 Out <<
"(type: " << AllocTypeName((uint8_t)MIB.AllocType);
3691 Out <<
", stackIds: (";
3692 ListSeparator SIDFS;
3693 for (
auto Id : MIB.StackIdIndices) {
3704 if (!
FS->callsites().empty()) {
3705 Out <<
", callsites: (";
3707 for (
auto &CI :
FS->callsites()) {
3710 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(CI.Callee.getGUID());
3712 Out <<
"(callee: null";
3713 Out <<
", clones: (";
3715 for (
auto V : CI.Clones) {
3719 Out <<
"), stackIds: (";
3720 ListSeparator SIDFS;
3721 for (
auto Id : CI.StackIdIndices) {
3730 auto PrintRange = [&](
const ConstantRange &
Range) {
3734 if (!
FS->paramAccesses().empty()) {
3735 Out <<
", params: (";
3737 for (
auto &PS :
FS->paramAccesses()) {
3739 Out <<
"(param: " << PS.ParamNo;
3740 Out <<
", offset: ";
3742 if (!PS.Calls.empty()) {
3743 Out <<
", calls: (";
3745 for (
auto &
Call : PS.Calls) {
3747 Out <<
"(callee: ^" <<
Machine.getGUIDSlot(
Call.Callee.getGUID());
3748 Out <<
", param: " <<
Call.ParamNo;
3749 Out <<
", offset: ";
3750 PrintRange(
Call.Offsets);
3761void AssemblyWriter::printTypeIdInfo(
3762 const FunctionSummary::TypeIdInfo &TIDInfo) {
3763 Out <<
", typeIdInfo: (";
3764 ListSeparator TIDFS;
3767 Out <<
"typeTests: (";
3770 auto TidIter = TheIndex->
typeIds().equal_range(GUID);
3771 if (TidIter.first == TidIter.second) {
3777 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3779 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3797 "typeTestAssumeConstVCalls");
3802 "typeCheckedLoadConstVCalls");
3807void AssemblyWriter::printVFuncId(
const FunctionSummary::VFuncId VFId) {
3808 auto TidIter = TheIndex->
typeIds().equal_range(VFId.
GUID);
3809 if (TidIter.first == TidIter.second) {
3810 Out <<
"vFuncId: (";
3811 Out <<
"guid: " << VFId.
GUID;
3812 Out <<
", offset: " << VFId.
Offset;
3818 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
3820 Out <<
"vFuncId: (";
3821 auto Slot =
Machine.getTypeIdSlot(TypeIdPair.first);
3824 Out <<
", offset: " << VFId.
Offset;
3829void AssemblyWriter::printNonConstVCalls(
3831 Out <<
Tag <<
": (";
3833 for (
auto &VFuncId : VCallList) {
3835 printVFuncId(VFuncId);
3840void AssemblyWriter::printConstVCalls(
3842 Out <<
Tag <<
": (";
3844 for (
auto &ConstVCall : VCallList) {
3847 printVFuncId(ConstVCall.VFunc);
3848 if (!ConstVCall.Args.empty()) {
3850 printArgs(ConstVCall.Args);
3857void AssemblyWriter::printSummary(
const GlobalValueSummary &Summary) {
3858 GlobalValueSummary::GVFlags GVFlags =
Summary.flags();
3861 Out <<
"(module: ^" <<
Machine.getModulePathSlot(
Summary.modulePath())
3864 Out <<
", visibility: "
3867 Out <<
", live: " << GVFlags.
Live;
3868 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3870 Out <<
", importType: "
3882 auto RefList =
Summary.refs();
3883 if (!RefList.empty()) {
3886 for (
auto &
Ref : RefList) {
3888 if (
Ref.isReadOnly())
3890 else if (
Ref.isWriteOnly())
3891 Out <<
"writeonly ";
3892 Out <<
"^" <<
Machine.getGUIDSlot(
Ref.getGUID());
3900void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &VI) {
3901 Out <<
"^" <<
Slot <<
" = gv: (";
3902 if (
VI.hasName() && !
VI.name().empty())
3903 Out <<
"name: \"" <<
VI.name() <<
"\"";
3905 Out <<
"guid: " <<
VI.getGUID();
3906 if (!
VI.getSummaryList().empty()) {
3907 Out <<
", summaries: (";
3909 for (
auto &Summary :
VI.getSummaryList()) {
3911 printSummary(*Summary);
3916 if (
VI.hasName() && !
VI.name().empty())
3917 Out <<
" ; guid = " <<
VI.getGUID();
3924 Out <<
"<empty name> ";
3926 unsigned char FirstC =
static_cast<unsigned char>(Name[0]);
3927 if (isalpha(FirstC) || FirstC ==
'-' || FirstC ==
'$' || FirstC ==
'.' ||
3932 for (
unsigned i = 1, e = Name.size(); i != e; ++i) {
3933 unsigned char C = Name[i];
3934 if (isalnum(
C) ||
C ==
'-' ||
C ==
'$' ||
C ==
'.' ||
C ==
'_')
3942void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3977 Out <<
"dso_local ";
3995 Out <<
"thread_local ";
3998 Out <<
"thread_local(localdynamic) ";
4001 Out <<
"thread_local(initialexec) ";
4004 Out <<
"thread_local(localexec) ";
4014 return "local_unnamed_addr";
4016 return "unnamed_addr";
4039void AssemblyWriter::printGlobal(
const GlobalVariable *GV) {
4041 Out <<
"; Materializable\n";
4062 Out << (GV->
isConstant() ?
"constant " :
"global ");
4071 Out <<
", section \"";
4076 Out <<
", partition \"";
4081 Out <<
", code_model \"";
4106 Out <<
", no_sanitize_address";
4108 Out <<
", no_sanitize_hwaddress";
4110 Out <<
", sanitize_memtag";
4112 Out <<
", sanitize_address_dyninit";
4117 Out <<
", align " <<
A->value();
4121 printMetadataAttachments(MDs,
", ");
4124 if (
Attrs.hasAttributes())
4125 Out <<
" #" <<
Machine.getAttributeGroupSlot(Attrs);
4130void AssemblyWriter::printAlias(
const GlobalAlias *GA) {
4132 Out <<
"; Materializable\n";
4152 if (
const Constant *Aliasee = GA->
getAliasee()) {
4155 TypePrinter.print(GA->
getType(), Out);
4156 Out <<
" <<NULL ALIASEE>>";
4160 Out <<
", partition \"";
4169void AssemblyWriter::printIFunc(
const GlobalIFunc *GI) {
4171 Out <<
"; Materializable\n";
4186 if (
const Constant *Resolver = GI->
getResolver()) {
4189 TypePrinter.print(GI->
getType(), Out);
4190 Out <<
" <<NULL RESOLVER>>";
4194 Out <<
", partition \"";
4201 printMetadataAttachments(MDs,
", ");
4208void AssemblyWriter::printComdat(
const Comdat *
C) {
4212void AssemblyWriter::printTypeIdentities() {
4213 if (TypePrinter.empty())
4219 auto &NumberedTypes = TypePrinter.getNumberedTypes();
4220 for (
unsigned I = 0,
E = NumberedTypes.size();
I !=
E; ++
I) {
4221 Out <<
'%' <<
I <<
" = type ";
4225 TypePrinter.printStructBody(NumberedTypes[
I], Out);
4229 auto &NamedTypes = TypePrinter.getNamedTypes();
4230 for (StructType *NamedType : NamedTypes) {
4236 TypePrinter.printStructBody(NamedType, Out);
4242void AssemblyWriter::printFunction(
const Function *
F) {
4243 if (
F->isMaterializable())
4244 Out <<
"; Materializable\n";
4245 else if (AnnotationWriter)
4248 const AttributeList &
Attrs =
F->getAttributes();
4249 if (
Attrs.hasFnAttrs()) {
4250 AttributeSet AS =
Attrs.getFnAttrs();
4251 std::string AttrStr;
4254 if (!Attr.isStringAttribute()) {
4255 if (!AttrStr.empty()) AttrStr +=
' ';
4256 AttrStr += Attr.getAsString();
4260 if (!AttrStr.empty())
4261 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
4265 Out <<
"; Unknown intrinsic\n";
4269 if (
F->isDeclaration()) {
4272 F->getAllMetadata(MDs);
4273 printMetadataAttachments(MDs,
" ");
4284 if (
F->getCallingConv() != CallingConv::C) {
4289 FunctionType *FT =
F->getFunctionType();
4290 if (
Attrs.hasRetAttrs())
4291 Out <<
Attrs.getAsString(AttributeList::ReturnIndex) <<
' ';
4292 TypePrinter.print(
F->getReturnType(), Out);
4299 if (
F->isDeclaration() && !IsForDebug) {
4302 for (
unsigned I = 0,
E = FT->getNumParams();
I !=
E; ++
I) {
4305 TypePrinter.print(FT->getParamType(
I), Out);
4307 AttributeSet ArgAttrs =
Attrs.getParamAttrs(
I);
4310 writeAttributeSet(ArgAttrs);
4316 for (
const Argument &Arg :
F->args()) {
4318 printArgument(&Arg,
Attrs.getParamAttrs(Arg.getArgNo()));
4323 if (FT->isVarArg()) {
4324 if (FT->getNumParams()) Out <<
", ";
4335 bool ForcePrintAddressSpace =
4336 !
Mod ||
Mod->getDataLayout().getProgramAddressSpace() != 0;
4338 "", ForcePrintAddressSpace);
4339 if (
Attrs.hasFnAttrs())
4340 Out <<
" #" <<
Machine.getAttributeGroupSlot(
Attrs.getFnAttrs());
4341 if (
F->hasSection()) {
4342 Out <<
" section \"";
4346 if (
F->hasPartition()) {
4347 Out <<
" partition \"";
4352 if (MaybeAlign
A =
F->getAlign())
4353 Out <<
" align " <<
A->value();
4354 if (MaybeAlign
A =
F->getPreferredAlignment())
4355 Out <<
" prefalign(" <<
A->value() <<
')';
4357 Out <<
" gc \"" <<
F->getGC() <<
'"';
4358 if (
F->hasPrefixData()) {
4360 writeOperand(
F->getPrefixData(),
true);
4362 if (
F->hasPrologueData()) {
4363 Out <<
" prologue ";
4364 writeOperand(
F->getPrologueData(),
true);
4366 if (
F->hasPersonalityFn()) {
4367 Out <<
" personality ";
4368 writeOperand(
F->getPersonalityFn(),
true);
4372 if (
auto *MDProf =
F->getMetadata(LLVMContext::MD_prof)) {
4374 MDProf->print(Out, TheModule,
true);
4378 if (
F->isDeclaration()) {
4382 F->getAllMetadata(MDs);
4383 printMetadataAttachments(MDs,
" ");
4387 for (
const BasicBlock &BB : *
F)
4401void AssemblyWriter::printArgument(
const Argument *Arg, AttributeSet Attrs) {
4403 TypePrinter.print(Arg->
getType(), Out);
4406 if (
Attrs.hasAttributes()) {
4408 writeAttributeSet(Attrs);
4417 assert(Slot != -1 &&
"expect argument in function here");
4418 Out <<
" %" <<
Slot;
4429 }
else if (!IsEntryBlock) {
4431 int Slot =
Machine.getLocalSlot(BB);
4438 if (!IsEntryBlock) {
4443 Out <<
" No predecessors!";
4449 writeOperand(Pred,
false);
4460 for (
const DbgRecord &DR :
I.getDbgRecordRange())
4461 printDbgRecordLine(DR);
4462 printInstructionLine(
I);
4469void AssemblyWriter::printInstructionLine(
const Instruction &
I) {
4470 printInstruction(
I);
4476void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
4479 writeOperand(BasePtr,
false);
4484 writeOperand(DerivedPtr,
false);
4492void AssemblyWriter::printInfoComment(
const Value &V,
bool isMaterializable) {
4494 printGCRelocateComment(*Relocate);
4496 if (AnnotationWriter && !isMaterializable)
4501 if (
I->getDebugLoc()) {
4503 I->getDebugLoc().print(Out);
4509 if (
auto *MD =
I->getMetadata(LLVMContext::MD_prof)) {
4511 MD->print(Out, TheModule,
true);
4522 if (Operand ==
nullptr) {
4523 Out <<
" <cannot get addrspace!>";
4533 bool ForcePrintAddrSpace =
4534 !
Mod ||
Mod->getDataLayout().getProgramAddressSpace() != 0;
4536 ForcePrintAddrSpace);
4540void AssemblyWriter::printInstruction(
const Instruction &
I) {
4550 }
else if (!
I.getType()->isVoidTy()) {
4552 int SlotNum =
Machine.getLocalSlot(&
I);
4554 Out <<
"<badref> = ";
4556 Out <<
'%' << SlotNum <<
" = ";
4560 if (CI->isMustTailCall())
4562 else if (CI->isTailCall())
4564 else if (CI->isNoTailCall())
4569 Out <<
I.getOpcodeName();
4589 Out <<
" elementwise";
4596 Out <<
' ' << CI->getPredicate();
4600 if (RMWI->isElementwise())
4601 Out <<
" elementwise";
4606 const Value *Operand =
I.getNumOperands() ?
I.getOperand(0) :
nullptr;
4611 writeOperand(BI->getCondition(),
true);
4613 writeOperand(BI->getSuccessor(0),
true);
4615 writeOperand(BI->getSuccessor(1),
true);
4620 writeOperand(
SI.getCondition(),
true);
4622 writeOperand(
SI.getDefaultDest(),
true);
4624 for (
auto Case :
SI.cases()) {
4626 writeOperand(Case.getCaseValue(),
true);
4628 writeOperand(Case.getCaseSuccessor(),
true);
4634 writeOperand(Operand,
true);
4638 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i) {
4640 writeOperand(
I.getOperand(i),
true);
4645 TypePrinter.print(
I.getType(), Out);
4649 for (
const auto &[V,
Block] :
4650 zip_equal(PN->incoming_values(), PN->blocks())) {
4652 writeOperand(V,
false);
4654 writeOperand(
Block,
false);
4659 writeOperand(
I.getOperand(0),
true);
4664 writeOperand(
I.getOperand(0),
true); Out <<
", ";
4665 writeOperand(
I.getOperand(1),
true);
4670 TypePrinter.print(
I.getType(), Out);
4671 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
4674 if (LPI->isCleanup())
4677 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
4678 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
4679 if (LPI->isCatch(i))
4684 writeOperand(LPI->getClause(i),
true);
4688 writeOperand(CatchSwitch->getParentPad(),
false);
4691 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
4693 writeOperand(PadBB,
true);
4696 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
4697 writeOperand(UnwindDest,
true);
4702 writeOperand(FPI->getParentPad(),
false);
4705 for (
const Value *
Op : FPI->arg_operands()) {
4707 writeOperand(
Op,
true);
4714 writeOperand(CRI->getOperand(0),
false);
4717 writeOperand(CRI->getOperand(1),
true);
4720 writeOperand(CRI->getOperand(0),
false);
4723 if (CRI->hasUnwindDest())
4724 writeOperand(CRI->getOperand(1),
true);
4729 if (CI->getCallingConv() != CallingConv::C) {
4734 Operand = CI->getCalledOperand();
4735 FunctionType *FTy = CI->getFunctionType();
4736 Type *RetTy = FTy->getReturnType();
4737 const AttributeList &PAL = CI->getAttributes();
4739 if (PAL.hasRetAttrs())
4740 Out <<
' ' << PAL.getAsString(AttributeList::ReturnIndex);
4749 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);
4751 writeOperand(Operand,
false);
4753 bool HasPrettyPrintedArgs =
4758 Function *CalledFunc = CI->getCalledFunction();
4759 auto PrintArgComment = [&](
unsigned ArgNo) {
4761 if (!ConstArg || !CalledFunc)
4763 std::string ArgComment;
4764 raw_string_ostream ArgCommentStream(ArgComment);
4767 if (ArgComment.empty())
4769 Out <<
"/* " << ArgComment <<
" */ ";
4771 if (HasPrettyPrintedArgs) {
4772 for (
unsigned ArgNo = 0, NumArgs = CI->arg_size(); ArgNo < NumArgs;
4775 PrintArgComment(ArgNo);
4776 writeParamOperand(CI->getArgOperand(ArgNo), PAL.getParamAttrs(ArgNo));
4779 for (
unsigned ArgNo = 0, NumArgs = CI->arg_size(); ArgNo < NumArgs;
4782 writeParamOperand(CI->getArgOperand(ArgNo), PAL.getParamAttrs(ArgNo));
4787 if (CI->isMustTailCall() && CI->getParent() &&
4788 CI->getParent()->getParent() &&
4789 CI->getParent()->getParent()->isVarArg()) {
4790 if (CI->arg_size() > 0)
4796 if (PAL.hasFnAttrs())
4797 Out <<
" #" <<
Machine.getAttributeGroupSlot(PAL.getFnAttrs());
4799 writeOperandBundles(CI);
4801 Operand =
II->getCalledOperand();
4802 FunctionType *FTy =
II->getFunctionType();
4803 Type *RetTy = FTy->getReturnType();
4804 const AttributeList &PAL =
II->getAttributes();
4807 if (
II->getCallingConv() != CallingConv::C) {
4812 if (PAL.hasRetAttrs())
4813 Out <<
' ' << PAL.getAsString(AttributeList::ReturnIndex);
4823 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);
4825 writeOperand(Operand,
false);
4828 for (
unsigned op = 0, Eop =
II->arg_size();
op < Eop; ++
op) {
4830 writeParamOperand(
II->getArgOperand(
op), PAL.getParamAttrs(
op));
4834 if (PAL.hasFnAttrs())
4835 Out <<
" #" <<
Machine.getAttributeGroupSlot(PAL.getFnAttrs());
4837 writeOperandBundles(
II);
4840 writeOperand(
II->getNormalDest(),
true);
4842 writeOperand(
II->getUnwindDest(),
true);
4844 Operand = CBI->getCalledOperand();
4845 FunctionType *FTy = CBI->getFunctionType();
4846 Type *RetTy = FTy->getReturnType();
4847 const AttributeList &PAL = CBI->getAttributes();
4850 if (CBI->getCallingConv() != CallingConv::C) {
4855 if (PAL.hasRetAttrs())
4856 Out <<
' ' << PAL.getAsString(AttributeList::ReturnIndex);
4863 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);
4865 writeOperand(Operand,
false);
4867 ListSeparator ArgLS;
4868 for (
unsigned op = 0, Eop = CBI->arg_size();
op < Eop; ++
op) {
4870 writeParamOperand(CBI->getArgOperand(
op), PAL.getParamAttrs(
op));
4874 if (PAL.hasFnAttrs())
4875 Out <<
" #" <<
Machine.getAttributeGroupSlot(PAL.getFnAttrs());
4877 writeOperandBundles(CBI);
4880 writeOperand(CBI->getDefaultDest(),
true);
4882 ListSeparator DestLS;
4883 for (
const BasicBlock *Dest : CBI->getIndirectDests()) {
4885 writeOperand(Dest,
true);
4890 if (AI->isUsedWithInAlloca())
4892 if (AI->isSwiftError())
4893 Out <<
"swifterror ";
4894 TypePrinter.print(AI->getAllocatedType(), Out);
4900 if (!AI->getArraySize() || AI->isArrayAllocation() ||
4901 !AI->getArraySize()->getType()->isIntegerTy(32)) {
4903 writeOperand(AI->getArraySize(),
true);
4905 if (MaybeAlign
A = AI->getAlign()) {
4906 Out <<
", align " <<
A->value();
4914 writeOperand(Operand,
true);
4917 TypePrinter.print(
I.getType(), Out);
4921 writeOperand(Operand,
true);
4924 TypePrinter.print(
I.getType(), Out);
4925 }
else if (Operand) {
4928 TypePrinter.print(
GEP->getSourceElementType(), Out);
4932 TypePrinter.print(
I.getType(), Out);
4939 bool PrintAllTypes =
false;
4947 PrintAllTypes =
true;
4949 for (
unsigned i = 1,
E =
I.getNumOperands(); i !=
E; ++i) {
4950 Operand =
I.getOperand(i);
4953 if (Operand && Operand->
getType() != TheType) {
4954 PrintAllTypes =
true;
4960 if (!PrintAllTypes) {
4962 TypePrinter.print(TheType, Out);
4967 for (
const Value *
Op :
I.operands()) {
4969 writeOperand(
Op, PrintAllTypes);
4976 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4977 if (MaybeAlign
A = LI->getAlign())
4978 Out <<
", align " <<
A->value();
4981 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4982 if (MaybeAlign
A =
SI->getAlign())
4983 Out <<
", align " <<
A->value();
4985 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4986 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4987 Out <<
", align " << CXI->getAlign().value();
4989 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4990 RMWI->getSyncScopeID());
4991 Out <<
", align " << RMWI->getAlign().value();
4993 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
5001 printMetadataAttachments(InstMD,
", ");
5004 printInfoComment(
I);
5007void AssemblyWriter::printDbgMarker(
const DbgMarker &Marker) {
5011 printDbgRecord(DPR);
5015 Out <<
" DbgMarker -> { ";
5020void AssemblyWriter::printDbgRecord(
const DbgRecord &DR) {
5022 printDbgVariableRecord(*DVR);
5024 printDbgLabelRecord(*DLR);
5029void AssemblyWriter::printDbgVariableRecord(
const DbgVariableRecord &DVR) {
5033 case DbgVariableRecord::LocationType::Value:
5036 case DbgVariableRecord::LocationType::Declare:
5039 case DbgVariableRecord::LocationType::DeclareValue:
5040 Out <<
"declare_value";
5042 case DbgVariableRecord::LocationType::Assign:
5047 "Tried to print a DbgVariableRecord with an invalid LocationType!");
5078void AssemblyWriter::printDbgRecordLine(
const DbgRecord &DR) {
5085void AssemblyWriter::printDbgLabelRecord(
const DbgLabelRecord &Label) {
5087 Out <<
"#dbg_label(";
5094void AssemblyWriter::printMetadataAttachments(
5095 const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,
5096 StringRef Separator) {
5100 if (MDNames.empty())
5101 MDs[0].second->getContext().getMDKindNames(MDNames);
5104 for (
const auto &
I : MDs) {
5105 unsigned Kind =
I.first;
5107 if (Kind < MDNames.size()) {
5111 Out <<
"!<unknown kind #" <<
Kind <<
">";
5117void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
5118 if (AnnotationWriter)
5121 Out <<
'!' <<
Slot <<
" = ";
5122 printMDNodeBody(Node);
5126void AssemblyWriter::writeAllMDNodes() {
5133 for (
auto [Slot, Node] : Nodes)
5134 writeMDNode(Slot, Node);
5137void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
5142void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
5148 Out << Attribute::getNameFromAttrKind(Attr.
getKindAsEnum());
5151 TypePrinter.print(Ty, Out);
5156void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
5158 ListSeparator
LS(
" ");
5159 for (
const auto &Attr : AttrSet) {
5161 writeAttribute(Attr, InAttrGroup);
5165void AssemblyWriter::writeAllAttributeGroups() {
5166 std::vector<std::pair<AttributeSet, unsigned>> asVec;
5167 asVec.resize(
Machine.as_size());
5170 asVec[
I.second] =
I;
5172 for (
const auto &
I : asVec)
5173 Out <<
"attributes #" <<
I.second <<
" = { "
5174 <<
I.first.getAsString(
true) <<
" }\n";
5177void AssemblyWriter::printUseListOrder(
const Value *V,
5178 ArrayRef<unsigned> Shuffle) {
5182 Out <<
"uselistorder ";
5183 writeOperand(V,
true);
5185 assert(Shuffle.
size() >= 2 &&
"Shuffle too small");
5189void AssemblyWriter::printUseLists(
const Function *
F) {
5190 auto It = UseListOrders.find(
F);
5191 if (It == UseListOrders.end())
5194 Out <<
"\n; uselistorder directives\n";
5195 for (
const auto &Pair : It->second)
5196 printUseListOrder(Pair.first, Pair.second);
5204 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
5207 AssemblyWriter W(OS, SlotTable, this->
getParent(), AAW, IsForDebug,
5208 ShouldPreserveUseListOrder);
5209 W.printFunction(
this);
5213 bool ShouldPreserveUseListOrder,
5214 bool IsForDebug)
const {
5217 AssemblyWriter W(OS, SlotTable, this->
getModule(), AAW, IsForDebug,
5218 ShouldPreserveUseListOrder);
5219 W.printBasicBlock(
this);
5223 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
5226 AssemblyWriter W(OS, SlotTable,
this, AAW, IsForDebug,
5227 ShouldPreserveUseListOrder);
5228 W.printModule(
this);
5234 AssemblyWriter W(OS, SlotTable,
getParent(),
nullptr, IsForDebug);
5235 W.printNamedMDNode(
this);
5239 bool IsForDebug)
const {
5240 std::optional<SlotTracker> LocalST;
5246 SlotTable = &*LocalST;
5250 AssemblyWriter W(OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
5251 W.printNamedMDNode(
this);
5256 ROS <<
" = comdat ";
5263 ROS <<
"exactmatch";
5269 ROS <<
"nodeduplicate";
5281 TP.print(
const_cast<Type*
>(
this), OS);
5290 TP.printStructBody(STy, OS);
5297 print(ROS, MST, IsForDebug);
5303 print(ROS, MST, IsForDebug);
5307 bool IsForDebug)
const {
5315 AssemblyWriter W(OS, SlotTable,
getModuleFromDPI(
this),
nullptr, IsForDebug);
5316 W.printDbgMarker(*
this);
5322 print(ROS, MST, IsForDebug);
5326 bool IsForDebug)
const {
5332 ?
Marker->getParent()->getParent()
5336 AssemblyWriter W(OS, SlotTable,
getModuleFromDPI(
this),
nullptr, IsForDebug);
5337 W.printDbgVariableRecord(*
this);
5341 bool IsForDebug)
const {
5347 Marker->getParent() ?
Marker->getParent()->getParent() :
nullptr;
5351 AssemblyWriter W(OS, SlotTable,
getModuleFromDPI(
this),
nullptr, IsForDebug);
5352 W.printDbgLabelRecord(*
this);
5357 F->print(ROS,
nullptr,
false, IsForDebug);
5361 BB->print(ROS,
nullptr,
false, IsForDebug);
5366 print(ROS, MST, IsForDebug);
5370 bool IsForDebug)
const {
5375 auto IncorporateFunction = [&](
const Function *
F) {
5381 IncorporateFunction(
I->getParent() ?
I->getParent()->getParent() :
nullptr);
5383 W.printInstruction(*
I);
5385 IncorporateFunction(BB->getParent());
5386 AssemblyWriter W(OS, SlotTable,
getModuleFromVal(BB),
nullptr, IsForDebug);
5387 W.printBasicBlock(BB);
5389 AssemblyWriter W(OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
5403 TypePrinting TypePrinter;
5404 TypePrinter.print(
C->getType(), OS);
5406 AsmWriterContext WriterCtx(&TypePrinter, MST.
getMachine());
5422 AsmWriterContext WriterCtx(
nullptr,
Machine, M);
5431 TypePrinting TypePrinter(MST.
getModule());
5461 AsmWriterContext &WriterCtx) {
5474struct MDTreeAsmWriterContext :
public AsmWriterContext {
5477 using EntryTy = std::pair<unsigned, std::string>;
5481 SmallPtrSet<const Metadata *, 4> Visited;
5483 raw_ostream &MainOS;
5485 MDTreeAsmWriterContext(TypePrinting *TP, SlotTracker *ST,
const Module *M,
5486 const ModuleSlotTracker *MST, raw_ostream &OS,
5488 : AsmWriterContext(TP,
ST,
M, MST),
Level(0
U), Visited({InitMD}),
5491 void onWriteMetadataAsOperand(
const Metadata *MD)
override {
5492 if (!Visited.
insert(MD).second)
5496 raw_string_ostream
SS(Str);
5501 unsigned InsertIdx = Buffer.
size() - 1;
5504 Buffer[InsertIdx].second = std::move(
SS.str());
5508 ~MDTreeAsmWriterContext()
override {
5509 for (
const auto &Entry : Buffer) {
5511 unsigned NumIndent =
Entry.first * 2U;
5520 bool OnlyAsOperand,
bool PrintAsTree =
false) {
5523 TypePrinting TypePrinter(M);
5525 std::unique_ptr<AsmWriterContext> WriterCtx;
5526 if (PrintAsTree && !OnlyAsOperand)
5527 WriterCtx = std::make_unique<MDTreeAsmWriterContext>(
5528 &TypePrinter, MST.
getMachine(), M, &MST, OS, &MD);
5530 WriterCtx = std::make_unique<AsmWriterContext>(&TypePrinter,
5560 const Module *M,
bool )
const {
5579 AssemblyWriter W(OS, SlotTable,
this, IsForDebug);
5580 W.printModuleSummaryIndex();
5589 L.push_back(std::make_pair(
I.second,
I.first));
5592#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu next use AMDGPU Next Use Analysis Printer
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)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void printDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out)
static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void WriteFullHexAPInt(raw_ostream &Out, const APInt &Val)
static void writeAPFloatInternal(raw_ostream &Out, const APFloat &APF)
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand, bool PrintAsTree=false)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT)
static cl::opt< bool > PreserveAssemblyUseListOrder("preserve-ll-uselistorder", cl::Hidden, cl::init(false), cl::desc("Preserve use-list order when writing LLVM assembly."))
static std::vector< unsigned > predictValueUseListOrder(const Value *V, unsigned ID, const OrderMap &OM)
static void writeDILayerLocList(raw_ostream &Out, const DILayerLocList *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void orderValue(const Value *V, OrderMap &OM)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)
static void writeDILayerLoc(raw_ostream &Out, const DILayerLoc *N, AsmWriterContext &WriterCtx)
static void writeMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, AsmWriterContext &Ctx)
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 cl::opt< bool > PrintAddrspaceName("print-addrspace-name", cl::Hidden, cl::init(false), cl::desc("Print address space names"))
static void writeOptimizationInfo(raw_ostream &Out, const User *U)
#define CC_VLS_CASE(ABI_VLEN)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static void printShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef< int > Mask)
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 writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static const char * getSummaryKindName(GlobalValueSummary::SummaryKind SK)
static OrderMap orderModule(const Module *M)
static const char * getVisibilityName(GlobalValue::VisibilityTypes Vis)
static void printCallingConv(unsigned cc, raw_ostream &Out)
static void printAddressSpace(const Module *M, unsigned AS, raw_ostream &OS, StringRef Prefix=" ", StringRef Suffix="", bool ForcePrint=false)
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 writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
DenseMap< const Function *, MapVector< const Value *, std::vector< unsigned > > > UseListOrderMap
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static UseListOrderMap predictUseListOrder(const Module *M)
static void printThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
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 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 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 writeDIProperty(raw_ostream &Out, const DIProperty *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeConstantInternal(raw_ostream &Out, const Constant *CV, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeAsOperandInternal(raw_ostream &Out, const Value *V, AsmWriterContext &WriterCtx, bool PrintType=false)
static void printVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
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 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 void printDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#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...
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...
GlobalValue::SanitizerMetadata SanitizerMetadata
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.
Machine Check Debug Module
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...
static bool processModule(Module &M, NVPTXTargetMachine &TM)
static bool processFunction(Function &F, NVPTXTargetMachine &TM)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
Function const char TargetMachine * Machine
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
static StringRef getName(Value *V)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file provides utility classes that use RAII to save and restore values.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
static UseListOrderStack predictUseListOrder(const Module &M)
static const fltSemantics & PPCDoubleDouble()
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
const fltSemantics & getSemantics() const
APInt bitcastToAPInt() const
APInt getNaNPayload() const
If the value is a NaN value, return an integer containing the payload of this value.
Class for arbitrary precision integers.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
void toStringUnsigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
unsigned getBitWidth() const
Return the number of bits in the APInt.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Abstract interface of slot tracker storage.
virtual ~AbstractSlotTrackerStorage()
const GlobalValueSummary & getAliasee() const
This class represents an incoming formal argument to a Function.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
virtual void emitMDNodeAnnot(const MDNode *, formatted_raw_ostream &)
emitMDNodeAnnot - This may be implemented to emit a string right before a metadata node is emitted.
virtual void emitBasicBlockStartAnnot(const BasicBlock *, formatted_raw_ostream &)
emitBasicBlockStartAnnot - This may be implemented to emit a string right after the basic block label...
virtual void emitBasicBlockEndAnnot(const BasicBlock *, formatted_raw_ostream &)
emitBasicBlockEndAnnot - This may be implemented to emit a string right after the basic block.
virtual void emitFunctionAnnot(const Function *, formatted_raw_ostream &)
emitFunctionAnnot - This may be implemented to emit a string right before the start of a function.
virtual void emitInstructionAnnot(const Instruction *, formatted_raw_ostream &)
emitInstructionAnnot - This may be implemented to emit a string right before an instruction is emitte...
virtual void printInfoComment(const Value &, formatted_raw_ostream &)
printInfoComment - This may be implemented to emit a comment to the right of an instruction or global...
virtual ~AssemblyAnnotationWriter()
static LLVM_ABI StringRef getOperationName(BinOp Op)
This class holds the attributes for a particular argument, parameter, function, or return value.
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).
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.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) 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
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
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).
A sequence of DILayerLoc entries.
A single intermediate-IR layer location.
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)
A property of a class or structure.
Wrapper structure that holds source language identity metadata that includes language name,...
uint32_t getVersion() const
Returns language version. Only valid for versioned language names.
uint16_t getDialect() const
bool hasVersionedName() const
uint16_t getName() const
Returns a versioned or unversioned language name.
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.
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.
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
LLVM_ABI MDNode * getAsMDNode() const
Return this as a bar MDNode.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
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.
const Function & getFunction() const
const Argument * const_arg_iterator
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.
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
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
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
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...
A helper class to return the specified delimiter string after the first invocation of operator String...
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.
Tracking metadata reference owned by Metadata.
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.
const Module * getModule() const
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
void renumberMetadataForAssembly(ArrayRef< const MDNode * > AdditionalMetadata, MachineMDNodeListType *AdditionalMetadataNodes=nullptr) const
Renumber module metadata and then additional metadata for canonical assembly output.
void collectMDNodes(MachineMDNodeListType &L) const
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *)>)
virtual ~ModuleSlotTracker()
Destructor to clean up storage.
void collectAdditionalMetadata(ArrayRef< const MDNode * > AdditionalMetadata, MachineMDNodeListType &AdditionalMetadataNodes) const
Collect metadata reachable from AdditionalMetadata but not from the module.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
virtual bool shouldPrintDebugLocationInline(const DILocation *) const
Return whether a debug location should be printed inline instead of by ID.
SlotTracker * getMachine()
Lazily creates a slot tracker.
SmallVector< std::pair< unsigned, const MDNode * >, 0 > MachineMDNodeListType
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...
uint64_t getBlockCount() const
const TypeIdSummaryMapTy & typeIds() const
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
static constexpr const char * getRegularLTOModuleName()
const auto & typeIdCompatibleVtableMap() const
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
LLVM_ABI void dump() const
Dump to stderr (for debugging).
GlobalValueSummaryMapTy::SortedEntriesRange sortedGlobalValueSummariesRange() const
uint64_t getStackIdAtIndex(unsigned Index) const
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
LLVM_ABI uint64_t getFlags() const
A Module instance is used to store all the information related to an LLVM module.
void renumberMetadataForAssembly()
Renumber the IDs stored in metadata nodes into canonical assembly order.
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
iterator_range< op_iterator > operands()
unsigned getAddressSpace() const
Return the address space of the Pointer type.
This class provides computation of slot numbers for LLVM Assembly writing.
DenseMap< const Value *, unsigned > ValueMap
ValueMap - A mapping of Values to slot numbers.
int getMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
~SlotTracker() override=default
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.
SlotTracker(const Module *M, bool ShouldTrackMetadataDefinitions=false)
Construct from a module.
const Function * getFunction() const
DenseMap< GlobalValue::GUID, unsigned >::iterator guid_iterator
GUID map iterators.
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)
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *)>)
void createMetadataSlot(const MDNode *N) override
getMetadataSlot - Get the slot number of a MDNode.
DenseMap< const MDNode *, unsigned >::iterator mdn_iterator
MDNode map iterators.
SlotTracker & operator=(const SlotTracker &)=delete
int getGUIDSlot(GlobalValue::GUID GUID)
int initializeIndexIfNeeded()
DenseMap< AttributeSet, unsigned >::iterator as_iterator
AttributeSet map iterators.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
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.
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.
LLVM_ABI void run(const Module &M, bool onlyNamed)
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM_ABI StringRef getTargetExtName() const
Type(LLVMContext &C, TypeID tid)
LLVM_ABI void dump() const
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
LLVM_ABI unsigned getByteBitWidth() const
TypeID getTypeID() const
Return the type id for the type.
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 getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
iterator_range< user_iterator > users()
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.
iterator_range< use_iterator > uses()
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.
LLVM_ABI StringRef LanguageDialectString(unsigned LanguageDialect)
LLVM_ABI StringRef SourceLanguageNameString(SourceLanguageName Lang)
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.
@ 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).
@ CHERIoT_CompartmentCall
Calling convention used for CHERIoT when crossing a protection boundary.
@ 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).
@ CHERIoT_CompartmentCallee
Calling convention used for the callee of CHERIoT_CompartmentCall.
@ 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.
@ CHERIoT_LibraryCall
Calling convention used for CHERIoT for cross-library calls to a stateless compartment.
@ 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.
@ WASM_EmscriptenInvoke
For emscripten __invoke_* functions.
@ 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).
@ X86_FastCall
'fast' analog of X86_StdCall.
LLVM_ABI void printImmArg(ID IID, unsigned ArgIdx, raw_ostream &OS, const Constant *ImmArgVal)
Print the argument info for the arguments with ArgInfo.
LLVM_ABI bool hasPrettyPrintedArgs(ID id)
Returns true if the intrinsic has pretty printed immediate arguments.
constexpr bool isAtomic(const T &...O)
@ System
Synchronized with respect to all concurrently executing threads.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
bool isElementwise(const VPValue *V)
Return true if V is elementwise, i.e. none of the lanes are permuted.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
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)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
auto dyn_cast_or_null(const Y &Val)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).
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...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
constexpr int PoisonMaskElem
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Ref
The access may reference the value stored in memory.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Printable printBasicBlock(const BasicBlock *BB)
Print BasicBlock BB as an operand or print "<nullptr>" if BB is a nullptr.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
auto predecessors(const MachineBasicBlock *BB)
bool pred_empty(const BasicBlock *BB)
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
static auto filterDbgVars(iterator_range< simple_ilist< DbgRecord >::iterator > R)
Filter the DbgRecord range to DbgVariableRecord types only and downcast.
LLVM_ABI void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
A single checksum, represented by a Kind and a Value (a string).
T Value
The string value of the checksum.
StringRef getKindAsString() const
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....
unsigned NoRenameOnPromotion
This field is written by the ThinLTO prelink stage to decide whether a particular static global value...
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 ...
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
@ 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:...