62#include "llvm/Config/config.h"
132#define DEBUG_TYPE "asm-printer"
136 cl::desc(
"Basic block profile dump for external cost modelling. If "
137 "matching up BBs with afterwards, the compilation must be "
138 "performed with -basic-block-sections=labels. Enabling this "
139 "flag during in-process ThinLTO is not supported."));
156STATISTIC(EmittedInsts,
"Number of machine instrs printed");
158char AsmPrinter::ID = 0;
161class AddrLabelMapCallbackPtr final :
CallbackVH {
165 AddrLabelMapCallbackPtr() =
default;
181 struct AddrLabelSymEntry {
193 std::vector<AddrLabelMapCallbackPtr> BBCallbacks;
199 DeletedAddrLabelsNeedingEmission;
206 "Some labels for deleted blocks never got emitted");
212 std::vector<MCSymbol *> &Result);
220 "Shouldn't get label for block without address taken");
221 AddrLabelSymEntry &Entry = AddrLabelSymbols[BB];
224 if (!Entry.Symbols.empty()) {
226 return Entry.Symbols;
231 BBCallbacks.emplace_back(BB);
232 BBCallbacks.back().setMap(
this);
233 Entry.Index = BBCallbacks.size() - 1;
237 Entry.Symbols.push_back(
Sym);
238 return Entry.Symbols;
243 Function *
F, std::vector<MCSymbol *> &Result) {
245 DeletedAddrLabelsNeedingEmission.find(
F);
248 if (
I == DeletedAddrLabelsNeedingEmission.end())
253 DeletedAddrLabelsNeedingEmission.erase(
I);
261 if (!AddrLabelSymbols)
262 AddrLabelSymbols = std::make_unique<AddrLabelMap>(
OutContext);
263 return AddrLabelSymbols->getAddrLabelSymbolToEmit(
268 const Function *
F, std::vector<MCSymbol *> &Result) {
270 if (!AddrLabelSymbols)
272 return AddrLabelSymbols->takeDeletedSymbolsForFunction(
280 AddrLabelSymEntry Entry = std::move(AddrLabelSymbols[BB]);
281 AddrLabelSymbols.erase(BB);
282 assert(!Entry.Symbols.empty() &&
"Didn't have a symbol, why a callback?");
283 BBCallbacks[Entry.Index] =
nullptr;
285#if !LLVM_MEMORY_SANITIZER_BUILD
288 "Block/parent mismatch");
292 if (
Sym->isDefined())
299 DeletedAddrLabelsNeedingEmission[Entry.Fn].push_back(
Sym);
305 AddrLabelSymEntry OldEntry = std::move(AddrLabelSymbols[Old]);
306 AddrLabelSymbols.erase(Old);
307 assert(!OldEntry.Symbols.empty() &&
"Didn't have a symbol, why a callback?");
309 AddrLabelSymEntry &NewEntry = AddrLabelSymbols[New];
312 if (NewEntry.Symbols.empty()) {
313 BBCallbacks[OldEntry.Index].setPtr(New);
314 NewEntry = std::move(OldEntry);
318 BBCallbacks[OldEntry.Index] =
nullptr;
324void AddrLabelMapCallbackPtr::deleted() {
325 Map->UpdateForDeletedBlock(cast<BasicBlock>(getValPtr()));
328void AddrLabelMapCallbackPtr::allUsesReplacedWith(
Value *V2) {
329 Map->UpdateForRAUWBlock(cast<BasicBlock>(getValPtr()), cast<BasicBlock>(V2));
338 Alignment =
DL.getPreferredAlign(GVar);
341 if (InAlign > Alignment)
349 assert(GVAlign &&
"GVAlign must be set");
354 Alignment = *GVAlign;
360 OutContext(Streamer->getContext()), OutStreamer(
std::
move(Streamer)),
363 DwarfUsesRelocationsAcrossSections =
369 "Debug/EH info didn't get finalized");
386 assert(
MMI &&
"MMI could not be nullptr!");
397 assert(
MF &&
"getSubtargetInfo requires a valid MachineFunction!");
408 "Expected assembly output mode.");
432 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
433 MMI = MMIWP ? &MMIWP->getMMI() :
nullptr;
434 HasSplitStack =
false;
435 HasNoSplitStack =
false;
437 AddrLabelSymbols =
nullptr;
444 .getModuleMetadata(M);
457 Triple TVT(M.getDarwinTargetVariantTriple());
459 Target, M.getSDKVersion(),
460 M.getDarwinTargetVariantTriple().empty() ?
nullptr : &TVT,
461 M.getDarwinTargetVariantSDKVersion());
475 FileName = M.getSourceFileName();
478 const char VerStr[] =
479 PACKAGE_VENDOR
" " PACKAGE_NAME
" version " PACKAGE_VERSION;
481 const char VerStr[] = PACKAGE_NAME
" version " PACKAGE_VERSION;
484 OutStreamer->emitFileDirective(FileName, VerStr,
"",
"");
493 emitModuleCommandLines(M);
496 assert(
MI &&
"AsmPrinter didn't require GCModuleInfo?");
497 for (
const auto &
I : *
MI)
499 MP->beginAssembly(M, *
MI, *
this);
502 if (!M.getModuleInlineAsm().empty()) {
503 OutStreamer->AddComment(
"Start of file scope inline assembly");
507 OutStreamer->AddComment(
"End of file scope inline assembly");
512 bool EmitCodeView = M.getCodeViewFlag();
514 Handlers.emplace_back(std::make_unique<CodeViewDebug>(
this),
519 if (!EmitCodeView || M.getDwarfVersion()) {
520 assert(
MMI &&
"MMI could not be nullptr here!");
543 for (
auto &
F : M.getFunctionList()) {
595 if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(
"cfguard")))
603 HI.Handler->beginModule(&M);
607 std::error_code PossibleFileError;
608 MBBProfileDumpFileOutput = std::make_unique<raw_fd_ostream>(
610 if (PossibleFileError) {
611 M.getContext().emitError(
"Failed to open file for MBB Profile Dump: " +
612 PossibleFileError.message() +
"\n");
696 "No emulated TLS variables in the common section");
735 "tagged symbols (-fsanitize=memtag-globals) are "
736 "only supported on AArch64 Android");
746 "' is already defined");
763 HI.TimerGroupName, HI.TimerGroupDescription,
765 HI.Handler->setSymbolSize(GVSym,
Size);
859 unsigned PtrSize =
DL.getPointerTypeSize(GV->
getType());
878 if (LocalAlias != EmittedInitSym)
899void AsmPrinter::emitFunctionHeaderComment() {}
903void AsmPrinter::emitFunctionHeader() {
908 <<
"-- Begin function "
936 if (
F.hasFnAttribute(Attribute::Cold))
940 if (
F.hasPrefixData()) {
963 unsigned PatchableFunctionPrefix = 0;
964 unsigned PatchableFunctionEntry = 0;
965 (void)
F.getFnAttribute(
"patchable-function-prefix")
967 .getAsInteger(10, PatchableFunctionPrefix);
968 (void)
F.getFnAttribute(
"patchable-function-entry")
970 .getAsInteger(10, PatchableFunctionEntry);
971 if (PatchableFunctionPrefix) {
976 }
else if (PatchableFunctionEntry) {
983 if (
const MDNode *MD =
F.getMetadata(LLVMContext::MD_func_sanitize)) {
984 assert(MD->getNumOperands() == 2);
986 auto *PrologueSig = mdconst::extract<Constant>(MD->getOperand(0));
987 auto *TypeHash = mdconst::extract<Constant>(MD->getOperand(1));
994 false,
F.getParent());
995 emitFunctionHeaderComment();
1013 std::vector<MCSymbol*> DeadBlockSyms;
1015 for (
MCSymbol *DeadBlockSym : DeadBlockSyms) {
1016 OutStreamer->AddComment(
"Address taken block that was later removed");
1032 for (
const HandlerInfo &HI :
Handlers) {
1035 HI.Handler->beginFunction(
MF);
1037 for (
const HandlerInfo &HI :
Handlers) {
1040 HI.Handler->beginBasicBlockSection(
MF->
front());
1044 if (
F.hasPrologueData())
1057 "' is a protected alias");
1082 std::optional<unsigned>
Size;
1084 CommentOS << *
Size <<
"-byte Reload\n";
1085 }
else if ((
Size =
MI.getFoldedRestoreSize(
TII))) {
1088 CommentOS <<
"Unknown-size Folded Reload\n";
1090 CommentOS << *
Size <<
"-byte Folded Reload\n";
1092 }
else if ((
Size =
MI.getSpillSize(
TII))) {
1093 CommentOS << *
Size <<
"-byte Spill\n";
1094 }
else if ((
Size =
MI.getFoldedSpillSize(
TII))) {
1097 CommentOS <<
"Unknown-size Folded Spill\n";
1099 CommentOS << *
Size <<
"-byte Folded Spill\n";
1105 CommentOS <<
" Reload Reuse\n";
1115 OS <<
"implicit-def: "
1127 assert(
Op.isReg() &&
"KILL instruction must have only register operands");
1128 OS <<
' ' << (
Op.isDef() ?
"def " :
"killed ")
1140 if (
MI->isNonListDebugValue() &&
MI->getNumOperands() != 4)
1145 OS <<
"DEBUG_VALUE: ";
1148 if (
auto *SP = dyn_cast<DISubprogram>(V->getScope())) {
1160 Expr = *NonVariadicExpr;
1167 for (
unsigned I = 0;
I <
Op.getNumArgs(); ++
I)
1168 OS <<
' ' <<
Op.getArg(
I);
1175 if (&
Op !=
MI->debug_operands().begin())
1177 switch (
Op.getType()) {
1180 Type *ImmTy =
Op.getFPImm()->getType();
1199 Op.getCImm()->getValue().
print(
OS,
false );
1203 OS <<
"!target-index(" <<
Op.getIndex() <<
"," <<
Op.getOffset() <<
")";
1209 std::optional<StackOffset>
Offset;
1223 if (
MI->isIndirectDebugValue())
1229 OS <<
'+' <<
Offset->getFixed() <<
']';
1246 if (
MI->getNumOperands() != 1)
1251 OS <<
"DEBUG_LABEL: ";
1254 if (
auto *SP = dyn_cast<DISubprogram>(
1255 V->getScope()->getNonLexicalBlockFileScope())) {
1270 if (
F.isDeclarationForLinker())
1274 F.needsUnwindTableEntry())
1280 assert(
MMI !=
nullptr &&
"Invalid machine module info");
1312 auto *
MBB =
MI.getParent();
1313 auto I = std::next(
MI.getIterator());
1314 while (
I !=
MBB->
end() &&
I->isTransient())
1321 unsigned CFIIndex =
MI.getOperand(0).getCFIIndex();
1328 MCSymbol *FrameAllocSym =
MI.getOperand(0).getMCSymbol();
1329 int FrameOffset =
MI.getOperand(1).getImm();
1351 assert(BBAddrMapSection &&
".llvm_bb_addr_map section is not initialized.");
1358 uint8_t BBAddrMapVersion =
OutStreamer->getContext().getBBAddrMapVersion();
1364 OutStreamer->AddComment(
"number of basic blocks");
1366 const MCSymbol *PrevMBBEndSymbol = FunctionSymbol;
1372 if (BBAddrMapVersion > 1) {
1402 OutStreamer->emitAbsoluteSymbolDiff(Symbol, Loc, 4);
1409 if (
const MDNode *MD =
F.getMetadata(LLVMContext::MD_kcfi_type))
1411 mdconst::extract<ConstantInt>(MD->getOperand(0)));
1416 auto GUID =
MI.getOperand(0).getImm();
1417 auto Index =
MI.getOperand(1).getImm();
1418 auto Type =
MI.getOperand(2).getImm();
1419 auto Attr =
MI.getOperand(3).getImm();
1431 if (!StackSizeSection)
1462 if (StackUsageStream ==
nullptr) {
1467 errs() <<
"Could not open file: " << EC.message();
1474 *StackUsageStream <<
':' << DSP->getLine();
1476 *StackUsageStream <<
':' <<
MF.
getName() <<
'\t' << StackSize <<
'\t';
1478 *StackUsageStream <<
"dynamic\n";
1480 *StackUsageStream <<
"static\n";
1487 PCSectionsSymbols[&MD].emplace_back(S);
1492 if (PCSectionsSymbols.empty() && !
F.hasMetadata(LLVMContext::MD_pcsections))
1496 const unsigned RelativeRelocSize =
1506 assert(S &&
"PC section is not initialized");
1517 bool ConstULEB128 =
false;
1519 if (
auto *S = dyn_cast<MDString>(MDO)) {
1523 const StringRef SecWithOpt = S->getString();
1524 const size_t OptStart = SecWithOpt.
find(
'!');
1530 assert((O ==
'!' || O ==
'C') &&
"Invalid !pcsections options");
1533 const MCSymbol *Prev = Syms.front();
1535 if (
Sym == Prev || !Deltas) {
1554 assert(isa<MDNode>(MDO) &&
"expecting either string or tuple");
1555 const auto *AuxMDs = cast<MDNode>(MDO);
1556 for (
const MDOperand &AuxMDO : AuxMDs->operands()) {
1557 assert(isa<ConstantAsMetadata>(AuxMDO) &&
"expecting a constant");
1558 const Constant *
C = cast<ConstantAsMetadata>(AuxMDO)->getValue();
1562 if (
auto *CI = dyn_cast<ConstantInt>(
C);
1563 CI && ConstULEB128 &&
Size > 1 &&
Size <= 8) {
1575 if (
const MDNode *MD =
F.getMetadata(LLVMContext::MD_pcsections))
1578 for (
const auto &MS : PCSectionsSymbols)
1579 EmitForMD(*MS.first, MS.second,
false);
1581 PCSectionsSymbols.clear();
1603 emitFunctionHeader();
1610 MDT = getAnalysisIfAvailable<MachineDominatorTree>();
1612 OwnedMDT = std::make_unique<MachineDominatorTree>();
1613 OwnedMDT->getBase().recalculate(*
MF);
1614 MDT = OwnedMDT.get();
1618 MLI = getAnalysisIfAvailable<MachineLoopInfo>();
1620 OwnedMLI = std::make_unique<MachineLoopInfo>();
1622 MLI = OwnedMLI.get();
1627 bool HasAnyRealCode =
false;
1628 int NumInstsInFunction = 0;
1632 for (
auto &
MBB : *
MF) {
1636 for (
auto &
MI :
MBB) {
1638 if (!
MI.isPosition() && !
MI.isImplicitDef() && !
MI.isKill() &&
1639 !
MI.isDebugInstr()) {
1640 HasAnyRealCode =
true;
1641 ++NumInstsInFunction;
1648 if (
MDNode *MD =
MI.getPCSections())
1654 HI.Handler->beginInstruction(&
MI);
1660 switch (
MI.getOpcode()) {
1661 case TargetOpcode::CFI_INSTRUCTION:
1664 case TargetOpcode::LOCAL_ESCAPE:
1667 case TargetOpcode::ANNOTATION_LABEL:
1668 case TargetOpcode::GC_LABEL:
1671 case TargetOpcode::EH_LABEL:
1681 auto MI2 = std::next(
MI.getIterator());
1682 if (IsEHa && MI2 !=
MBB.
end() &&
1683 (MI2->mayLoadOrStore() || MI2->mayRaiseFPException()))
1687 case TargetOpcode::INLINEASM:
1688 case TargetOpcode::INLINEASM_BR:
1691 case TargetOpcode::DBG_VALUE:
1692 case TargetOpcode::DBG_VALUE_LIST:
1698 case TargetOpcode::DBG_INSTR_REF:
1703 case TargetOpcode::DBG_PHI:
1707 case TargetOpcode::DBG_LABEL:
1713 case TargetOpcode::IMPLICIT_DEF:
1716 case TargetOpcode::KILL:
1719 case TargetOpcode::PSEUDO_PROBE:
1722 case TargetOpcode::ARITH_FENCE:
1726 case TargetOpcode::MEMBARRIER:
1729 case TargetOpcode::JUMP_TABLE_DEBUG_INFO:
1735 if (CanDoExtraAnalysis) {
1752 HI.Handler->endInstruction();
1773 OutStreamer->emitELFSize(CurrentSectionBeginSym, SizeExp);
1781 if (CanDoExtraAnalysis) {
1792 for (
auto &KV : MnemonicCounts)
1795 sort(MnemonicVec, [](
const std::pair<StringRef, unsigned> &
A,
1796 const std::pair<StringRef, unsigned> &
B) {
1797 if (
A.second >
B.second)
1799 if (
A.second ==
B.second)
1804 for (
auto &KV : MnemonicVec) {
1805 auto Name = (
Twine(
"INST_") + getToken(KV.first.trim()).first).str();
1806 R << KV.first <<
": " <<
ore::NV(
Name, KV.second) <<
"\n";
1812 EmittedInsts += NumInstsInFunction;
1816 R <<
ore::NV(
"NumInstructions", NumInstsInFunction)
1817 <<
" instructions in function";
1830 (TT.isOSWindows() && TT.isOSBinFormatCOFF()))) {
1836 OutStreamer->AddComment(
"avoids zero-length function");
1845 for (
const auto &BB :
F) {
1846 if (!BB.hasAddressTaken())
1849 if (
Sym->isDefined())
1851 OutStreamer->AddComment(
"Address of block that was removed by CodeGen");
1870 if (EmitFunctionSize) {
1887 HI.Handler->endBasicBlockSection(
MF->
back());
1893 HI.Handler->markFunctionEnd();
1906 HI.Handler->endFunction(
MF);
1926 OutStreamer->getCommentOS() <<
"-- End function\n";
1932 if (MBBProfileDumpFileOutput) {
1936 "Unable to find BB labels for MBB profile dump. -mbb-profile-dump "
1937 "must be called with -basic-block-sections=labels");
1939 getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
1940 for (
const auto &
MBB : *
MF) {
1941 *MBBProfileDumpFileOutput.get()
1953 if (isa<GlobalVariable>(
C))
1956 unsigned NumUses = 0;
1957 for (
const auto *
CU :
C->users())
1969 unsigned &NumGOTEquivUsers) {
1980 for (
const auto *U : GV->
users())
1983 return NumGOTEquivUsers > 0;
1997 for (
const auto &
G : M.globals()) {
1998 unsigned NumGOTEquivUsers = 0;
2017 unsigned Cnt =
I.second.second;
2023 for (
const auto *GV : FailedCandidates)
2041 "Visibility should be handled with emitLinkage() on AIX.");
2088 if (LocalAlias !=
Name)
2107 "IFunc is not supported on AIX.");
2125 if (LocalAlias !=
Name)
2135 std::optional<SmallString<128>> Filename;
2136 if (std::optional<StringRef> FilenameRef = RS.
getFilename()) {
2137 Filename = *FilenameRef;
2139 assert(!Filename->empty() &&
"The filename can't be empty.");
2144 std::unique_ptr<remarks::MetaSerializer> MetaSerializer =
2147 MetaSerializer->emit();
2170 for (
const auto &
G : M.globals())
2180 if (!
F.isDeclarationForLinker())
2195 if (
F.isIntrinsic())
2222 if (!Stubs.empty()) {
2227 for (
const auto &Stub : Stubs) {
2229 OutStreamer->emitSymbolValue(Stub.second.getPointer(),
2230 DL.getPointerSize());
2241 if (!Stubs.empty()) {
2244 for (
const auto &Stub : Stubs) {
2256 OutStreamer->emitSymbolValue(Stub.second.getPointer(),
2257 DL.getPointerSize());
2265 TS->emitConstantPools();
2277 HI.Handler->endModule();
2294 for (
const auto &GO : M.global_objects()) {
2295 if (!GO.hasExternalWeakLinkage())
2300 auto SymbolName =
"swift_async_extendedFramePointerFlags";
2301 auto Global = M.getGlobalVariable(SymbolName);
2318 for (
const auto &Alias : M.aliases()) {
2319 if (Alias.hasAvailableExternallyLinkage())
2322 Cur = dyn_cast<GlobalAlias>(Cur->getAliasee())) {
2323 if (!AliasVisited.
insert(Cur).second)
2328 emitGlobalAlias(M, *AncestorAlias);
2331 for (
const auto &IFunc : M.ifuncs())
2332 emitGlobalIFunc(M, IFunc);
2335 assert(
MI &&
"AsmPrinter didn't require GCModuleInfo?");
2338 MP->finishAssembly(M, *
MI, *
this);
2341 emitModuleIdents(M);
2346 emitModuleCommandLines(M);
2353 if (HasNoSplitStack)
2360 Function *InitTrampolineIntrinsic = M.getFunction(
"llvm.init.trampoline");
2361 if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->
use_empty())
2369 if (!GV.use_empty() && !GV.isThreadLocal() &&
2370 !GV.hasDLLImportStorageClass() && !GV.getName().startswith(
"llvm.") &&
2371 !GV.hasAtLeastLocalUnnamedAddr())
2378 unsigned UniqueID = 0;
2380 if (!GV.hasPartition() || GV.isDeclarationForLinker() ||
2386 "",
false, ++UniqueID,
nullptr));
2400 AddrLabelSymbols =
nullptr;
2414 return Res.first->second;
2424 HasSplitStack =
true;
2427 HasNoSplitStack =
true;
2429 HasNoSplitStack =
true;
2436 "Only AIX uses the function descriptor hooks.");
2441 " initalized first.");
2450 CurrentSectionBeginSym =
nullptr;
2452 MBBSectionExceptionSyms.clear();
2454 if (
F.hasFnAttribute(
"patchable-function-entry") ||
2455 F.hasFnAttribute(
"function-instrument") ||
2456 F.hasFnAttribute(
"xray-instruction-threshold") ||
2460 if (NeedsLocalForSize)
2464 ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
2486 const std::vector<MachineConstantPoolEntry> &CP = MCP->
getConstants();
2487 if (CP.empty())
return;
2492 for (
unsigned i = 0, e = CP.size(); i != e; ++i) {
2508 unsigned SecIdx = CPSections.
size();
2509 while (SecIdx != 0) {
2510 if (CPSections[--SecIdx].S == S) {
2516 SecIdx = CPSections.
size();
2517 CPSections.
push_back(SectionCPs(S, Alignment));
2520 if (Alignment > CPSections[SecIdx].Alignment)
2521 CPSections[SecIdx].Alignment = Alignment;
2528 for (
unsigned i = 0, e = CPSections.
size(); i != e; ++i) {
2529 for (
unsigned j = 0, ee = CPSections[i].CPEs.
size(); j != ee; ++j) {
2530 unsigned CPI = CPSections[i].CPEs[j];
2532 if (!
Sym->isUndefined())
2535 if (CurSection != CPSections[i].S) {
2538 CurSection = CPSections[i].S;
2566 const std::vector<MachineJumpTableEntry> &JT = MJTI->
getJumpTables();
2567 if (JT.empty())
return;
2577 if (JTInDiffSection) {
2587 if (!JTInDiffSection)
2590 for (
unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {
2591 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
2594 if (JTBBs.empty())
continue;
2620 if (JTInDiffSection &&
DL.hasLinkerPrivateGlobalPrefix())
2630 emitJumpTableEntry(MJTI,
MBB, JTI);
2632 if (!JTInDiffSection)
2640 unsigned UID)
const {
2706 if (GV->
getName() ==
"llvm.used") {
2721 if (GV->
getName() ==
"llvm.global_ctors") {
2728 if (GV->
getName() ==
"llvm.global_dtors") {
2740void AsmPrinter::emitLLVMUsedList(
const ConstantArray *InitList) {
2742 for (
unsigned i = 0, e = InitList->
getNumOperands(); i != e; ++i) {
2755 if (!isa<ConstantArray>(
List))
2759 for (
Value *O : cast<ConstantArray>(
List)->operands()) {
2760 auto *CS = cast<ConstantStruct>(O);
2761 if (CS->getOperand(1)->isNullValue())
2763 ConstantInt *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
2770 if (!CS->getOperand(2)->isNullValue()) {
2773 "associated data of XXStructor list is not yet supported on AIX");
2775 dyn_cast<GlobalValue>(CS->getOperand(2)->stripPointerCasts());
2781 return L.Priority < R.Priority;
2791 if (Structors.
empty())
2797 std::reverse(Structors.
begin(), Structors.
end());
2825void AsmPrinter::emitModuleIdents(
Module &M) {
2829 if (
const NamedMDNode *NMD = M.getNamedMetadata(
"llvm.ident")) {
2830 for (
unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
2831 const MDNode *
N = NMD->getOperand(i);
2832 assert(
N->getNumOperands() == 1 &&
2833 "llvm.ident metadata entry can have only one operand");
2834 const MDString *S = cast<MDString>(
N->getOperand(0));
2840void AsmPrinter::emitModuleCommandLines(
Module &M) {
2845 const NamedMDNode *NMD =
M.getNamedMetadata(
"llvm.commandline");
2854 assert(
N->getNumOperands() == 1 &&
2855 "llvm.commandline metadata entry can have only one operand");
2856 const MDString *S = cast<MDString>(
N->getOperand(0));
2886 unsigned PadTo)
const {
2902 unsigned Size)
const {
2917 bool IsSectionRelative)
const {
2941 unsigned MaxBytesToEmit)
const {
2945 if (Alignment ==
Align(1))
2954 OutStreamer->emitCodeAlignment(Alignment, STI, MaxBytesToEmit);
2956 OutStreamer->emitValueToAlignment(Alignment, 0, 1, MaxBytesToEmit);
2969 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
2972 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
2975 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV))
2978 if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV))
2992 switch (CE->getOpcode()) {
2995 case Instruction::AddrSpaceCast: {
2997 unsigned DstAS = CE->getType()->getPointerAddressSpace();
2998 unsigned SrcAS =
Op->getType()->getPointerAddressSpace();
3004 case Instruction::GetElementPtr: {
3007 cast<GEPOperator>(CE)->accumulateConstantOffset(
getDataLayout(), OffsetAI);
3018 case Instruction::Trunc:
3024 case Instruction::BitCast:
3027 case Instruction::IntToPtr: {
3038 case Instruction::PtrToInt: {
3044 Type *Ty = CE->getType();
3053 if (
DL.getTypeAllocSize(Ty).getFixedValue() <=
3054 DL.getTypeAllocSize(
Op->getType()).getFixedValue())
3060 case Instruction::Sub: {
3070 const MCExpr *RelocExpr =
3082 int64_t Addend = (LHSOffset - RHSOffset).getSExtValue();
3096 case Instruction::Add: {
3113 OS <<
"Unsupported expression in static initializer: ";
3114 CE->printAsOperand(
OS,
false,
3133 assert(!
Data.empty() &&
"Empty aggregates should be CAZ node");
3135 for (
unsigned i = 1, e =
Data.size(); i != e; ++i)
3136 if (
Data[i] !=
C)
return -1;
3137 return static_cast<uint8_t
>(
C);
3144 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
3150 if (!
Value.isSplat(8))
3153 return Value.zextOrTrunc(8).getZExtValue();
3158 assert(CA->getNumOperands() != 0 &&
"Should be a CAZ");
3165 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i)
3166 if (CA->getOperand(i) != Op0)
3181 if (AliasIt != AliasList->
end()) {
3225 unsigned EmittedSize =
3227 assert(EmittedSize <=
Size &&
"Size cannot be less than EmittedSize!");
3228 if (
unsigned Padding =
Size - EmittedSize)
3258 uint64_t ElementSizeInBits =
DL.getTypeSizeInBits(ElementType);
3259 uint64_t ElementAllocSizeInBits =
DL.getTypeAllocSizeInBits(ElementType);
3261 if (ElementSizeInBits != ElementAllocSizeInBits) {
3273 "Cannot lower vector global with unusual element type");
3277 EmittedSize =
DL.getTypeStoreSize(CV->
getType());
3288 if (
unsigned Padding =
Size - EmittedSize)
3312 SizeSoFar += FieldSize + PadSize;
3320 "Layout of constant struct may be incorrect!");
3324 assert(ET &&
"Unknown float type");
3333 AP.
OutStreamer->getCommentOS() <<
' ' << StrVal <<
'\n';
3340 unsigned TrailingBytes = NumBytes %
sizeof(
uint64_t);
3349 AP.
OutStreamer->emitIntValueInHexWithPadding(p[Chunk--], TrailingBytes);
3351 for (; Chunk >= 0; --Chunk)
3355 for (Chunk = 0; Chunk < NumBytes /
sizeof(
uint64_t); ++Chunk)
3359 AP.
OutStreamer->emitIntValueInHexWithPadding(p[Chunk], TrailingBytes);
3364 AP.
OutStreamer->emitZeros(
DL.getTypeAllocSize(ET) -
DL.getTypeStoreSize(ET));
3379 unsigned ExtraBitsSize =
BitWidth & 63;
3381 if (ExtraBitsSize) {
3389 if (
DL.isBigEndian()) {
3398 ExtraBitsSize =
alignTo(ExtraBitsSize, 8);
3400 (((
uint64_t)-1) >> (64 - ExtraBitsSize));
3411 for (
unsigned i = 0, e =
BitWidth / 64; i != e; ++i) {
3412 uint64_t Val =
DL.isBigEndian() ? RawData[e - i - 1] : RawData[i];
3416 if (ExtraBitsSize) {
3423 (ExtraBits & (((
uint64_t)-1) >> (64 - ExtraBitsSize)))
3424 == ExtraBits &&
"Directive too small for extra bits.");
3456 if (!(*ME)->evaluateAsRelocatable(MV,
nullptr,
nullptr) || MV.
isAbsolute())
3467 const GlobalValue *BaseGV = dyn_cast_or_null<GlobalValue>(BaseCst);
3475 if (!SymB || BaseSym != &SymB->
getSymbol())
3486 if (GOTPCRelCst < 0)
3508 int NumUses = (int)Result.second;
3531 BaseCV = dyn_cast<Constant>(CV->
user_back());
3533 if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(CV))
3536 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
3539 if (StoreSize <= 8) {
3542 <<
format(
"0x%" PRIx64
"\n", CI->getZExtValue());
3543 AP.
OutStreamer->emitIntValue(CI->getZExtValue(), StoreSize);
3549 if (
Size != StoreSize)
3555 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
3558 if (isa<ConstantPointerNull>(CV)) {
3572 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
3575 if (CE->getOpcode() == Instruction::BitCast)
3619 for (
auto &AliasPair : *AliasList) {
3674 if (
Sym->isUndefined())
3716 unsigned FunctionNumber) {
3720 <<
"Parent Loop BB" << FunctionNumber <<
"_"
3728 unsigned FunctionNumber) {
3732 <<
"Child Loop BB" << FunctionNumber <<
"_"
3733 << CL->getHeader()->getNumber() <<
" Depth " << CL->getLoopDepth()
3748 assert(Header &&
"No header for loop");
3752 if (Header != &
MBB) {
3753 AP.
OutStreamer->AddComment(
" in Loop: Header=BB" +
3784 HI.Handler->endFunclet();
3785 HI.Handler->beginFunclet(
MBB);
3801 if (Alignment !=
Align(1))
3823 if (BB->hasName()) {
3825 false, BB->getModule());
3830 assert(
MLI !=
nullptr &&
"MachineLoopInfo should has been computed");
3835 if (shouldEmitLabelForBasicBlock(
MBB)) {
3837 OutStreamer->AddComment(
"Label of block must be emitted");
3857 HI.Handler->beginBasicBlockSection(
MBB);
3865 HI.Handler->endBasicBlockSection(
MBB);
3869 bool IsDefinition)
const {
3872 switch (Visibility) {
3889bool AsmPrinter::shouldEmitLabelForBasicBlock(
3930 if (!
MI.isBranch() ||
MI.isIndirectBranch())
3939 if (
OP->isMBB() &&
OP->getMBB() ==
MBB)
3951 auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S,
nullptr});
3953 return GCPI->second.get();
3959 if (
Name == GCMetaPrinter.getName()) {
3960 std::unique_ptr<GCMetadataPrinter> GMP = GCMetaPrinter.instantiate();
3962 GCPI->second = std::move(GMP);
3963 return GCPI->second.get();
3971 assert(
MI &&
"AsmPrinter didn't require GCModuleInfo?");
3972 bool NeedsDefault =
false;
3973 if (
MI->begin() ==
MI->end())
3975 NeedsDefault =
true;
3977 for (
const auto &
I : *
MI) {
3979 if (MP->emitStackMaps(
SM, *
this))
3983 NeedsDefault =
true;
3999 auto Kind8 =
static_cast<uint8_t
>(
Kind);
4004 auto Padding = (4 * Bytes) - ((2 * Bytes) + 3);
4005 assert(Padding >= 0 &&
"Instrumentation map entry > 4 * Word Size");
4013 auto PrevSection =
OutStreamer->getCurrentSectionOnly();
4019 if (TT.isOSBinFormatELF()) {
4023 if (
F.hasComdat()) {
4025 GroupName =
F.getComdat()->getName();
4028 Flags, 0, GroupName,
F.hasComdat(),
4057 for (
const auto &Sled :
Sleds) {
4058 MCSymbol *Dot = Ctx.createTempSymbol();
4088 MCSymbol *Dot = Ctx.createLinkerPrivateSymbol(
"xray_fn_idx");
4104 auto Attr =
F.getFnAttribute(
"function-instrument");
4105 bool LogArgs =
F.hasFnAttribute(
"xray-log-args");
4106 bool AlwaysInstrument =
4107 Attr.isStringAttribute() && Attr.getValueAsString() ==
"xray-always";
4111 AlwaysInstrument, &
F, Version});
4116 unsigned PatchableFunctionPrefix = 0, PatchableFunctionEntry = 0;
4117 (void)
F.getFnAttribute(
"patchable-function-prefix")
4119 .getAsInteger(10, PatchableFunctionPrefix);
4120 (void)
F.getFnAttribute(
"patchable-function-entry")
4122 .getAsInteger(10, PatchableFunctionEntry);
4123 if (!PatchableFunctionPrefix && !PatchableFunctionEntry)
4135 if (
F.hasComdat()) {
4137 GroupName =
F.getComdat()->getName();
4150 return OutStreamer->getContext().getDwarfVersion();
4154 OutStreamer->getContext().setDwarfVersion(Version);
4180 const MCSymbol *BranchLabel)
const {
4182 const auto BaseExpr =
4184 const auto Base = &cast<MCSymbolRefExpr>(BaseExpr)->getSymbol();
4188 return std::make_tuple(
Base, 0, BranchLabel,
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP)
emitDebugValueComment - This method handles the target-independent form of DBG_VALUE,...
const char CFGuardDescription[]
static void emitGlobalConstantVector(const DataLayout &DL, const ConstantVector *CV, AsmPrinter &AP, AsmPrinter::AliasMapTy *AliasList)
static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB)
Returns the BB metadata to be emitted in the SHT_LLVM_BB_ADDR_MAP section for a given basic block.
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP)
static bool isGOTEquivalentCandidate(const GlobalVariable *GV, unsigned &NumGOTEquivUsers)
Only consider global GOT equivalents if at least one user is a cstexpr inside an initializer of anoth...
static unsigned getNumGlobalVariableUses(const Constant *C)
Compute the number of Global Variables that uses a Constant.
const char EHTimerDescription[]
const char CodeViewLineTablesGroupDescription[]
static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB, const MachineLoopInfo *LI, const AsmPrinter &AP)
emitBasicBlockLoopComments - Pretty-print comments for basic blocks.
static bool needFuncLabels(const MachineFunction &MF)
Returns true if function begin and end labels should be emitted.
static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME, const Constant *BaseCst, uint64_t Offset)
Transform a not absolute MCExpr containing a reference to a GOT equivalent global,...
static int isRepeatedByteSequence(const ConstantDataSequential *V)
isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of iden...
static void emitGlobalAliasInline(AsmPrinter &AP, uint64_t Offset, AsmPrinter::AliasMapTy *AliasList)
const char PPGroupDescription[]
const char PPTimerDescription[]
const char DWARFGroupDescription[]
static void PrintChildLoopComment(raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
PrintChildLoopComment - Print comments about child loops within the loop for this basic block,...
const char CodeViewLineTablesGroupName[]
static void PrintParentLoopComment(raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
PrintParentLoopComment - Print comments about parent loops of this one.
static void emitGlobalConstantStruct(const DataLayout &DL, const ConstantStruct *CS, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset, AsmPrinter::AliasMapTy *AliasList)
static void emitGlobalConstantDataSequential(const DataLayout &DL, const ConstantDataSequential *CDS, AsmPrinter &AP, AsmPrinter::AliasMapTy *AliasList)
static void emitKill(const MachineInstr *MI, AsmPrinter &AP)
const char DbgTimerName[]
static cl::opt< std::string > BasicBlockProfileDump("mbb-profile-dump", cl::Hidden, cl::desc("Basic block profile dump for external cost modelling. If " "matching up BBs with afterwards, the compilation must be " "performed with -basic-block-sections=labels. Enabling this " "flag during in-process ThinLTO is not supported."))
const char DbgTimerDescription[]
static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C, AsmPrinter &AP, const Constant *BaseCV=nullptr, uint64_t Offset=0, AsmPrinter::AliasMapTy *AliasList=nullptr)
const char DWARFGroupName[]
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS)
emitComments - Pretty-print comments for instructions.
static bool emitDebugLabelComment(const MachineInstr *MI, AsmPrinter &AP)
This method handles the target-independent form of DBG_LABEL, returning true if it was able to do so.
static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI)
static void emitGlobalConstantArray(const DataLayout &DL, const ConstantArray *CA, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset, AsmPrinter::AliasMapTy *AliasList)
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
const HexagonInstrInfo * TII
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
This file provides utility analysis objects describing memory locations.
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This file describes how to lower LLVM code to machine code.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getNumWords() const
Get the number of words.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
AddrLabelMap(MCContext &context)
void UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New)
void takeDeletedSymbolsForFunction(Function *F, std::vector< MCSymbol * > &Result)
If we have any deleted symbols for F, return them.
void UpdateForDeletedBlock(BasicBlock *BB)
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(BasicBlock *BB)