#include "llvm/CodeGen/AsmPrinter.h"
#include "CodeViewDebug.h"
#include "DwarfDebug.h"
#include "DwarfException.h"
#include "PseudoProbePrinter.h"
#include "WasmException.h"
#include "WinCFGuard.h"
#include "WinException.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/CodeGen/GCMetadataPrinter.h"
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBundle.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/config.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GCStrategy.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalIFunc.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PseudoProbe.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDirectives.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSectionXCOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCSymbolCOFF.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Object/ELFTypes.h"
#include "llvm/Pass.h"
#include "llvm/Remarks/RemarkStreamer.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VCSRevision.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstdint>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
usingnamespacellvm;
#define DEBUG_TYPE …
enum class PGOMapFeaturesEnum { … };
static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
"pgo-analysis-map", cl::Hidden, cl::CommaSeparated,
cl::values(clEnumValN(PGOMapFeaturesEnum::FuncEntryCount,
"func-entry-count", "Function Entry Count"),
clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
"Basic Block Frequency"),
clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob",
"Branch Probability")),
cl::desc(
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
"extracted from PGO related analysis."));
static cl::opt<bool> EmitJumpTableSizesSection(
"emit-jump-table-sizes-section",
cl::desc("Emit a section containing jump table addresses and sizes"),
cl::Hidden, cl::init(false));
STATISTIC(EmittedInsts, "Number of machine instrs printed");
char AsmPrinter::ID = …;
namespace {
class AddrLabelMapCallbackPtr final : CallbackVH { … };
}
class llvm::AddrLabelMap { … };
ArrayRef<MCSymbol *> AddrLabelMap::getAddrLabelSymbolToEmit(BasicBlock *BB) { … }
void AddrLabelMap::takeDeletedSymbolsForFunction(
Function *F, std::vector<MCSymbol *> &Result) { … }
ArrayRef<MCSymbol *>
AsmPrinter::getAddrLabelSymbolToEmit(const BasicBlock *BB) { … }
void AsmPrinter::takeDeletedSymbolsForFunction(
const Function *F, std::vector<MCSymbol *> &Result) { … }
void AddrLabelMap::UpdateForDeletedBlock(BasicBlock *BB) { … }
void AddrLabelMap::UpdateForRAUWBlock(BasicBlock *Old, BasicBlock *New) { … }
void AddrLabelMapCallbackPtr::deleted() { … }
void AddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { … }
Align AsmPrinter::getGVAlignment(const GlobalObject *GV, const DataLayout &DL,
Align InAlign) { … }
AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
: … { … }
AsmPrinter::~AsmPrinter() { … }
bool AsmPrinter::isPositionIndependent() const { … }
unsigned AsmPrinter::getFunctionNumber() const { … }
const TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const { … }
const DataLayout &AsmPrinter::getDataLayout() const { … }
unsigned AsmPrinter::getPointerSize() const { … }
const MCSubtargetInfo &AsmPrinter::getSubtargetInfo() const { … }
void AsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst) { … }
void AsmPrinter::emitInitialRawDwarfLocDirective(const MachineFunction &MF) { … }
const MCSection *AsmPrinter::getCurrentSection() const { … }
void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const { … }
bool AsmPrinter::doInitialization(Module &M) { … }
static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI) { … }
void AsmPrinter::emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const { … }
void AsmPrinter::getNameWithPrefix(SmallVectorImpl<char> &Name,
const GlobalValue *GV) const { … }
MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const { … }
MCSymbol *AsmPrinter::getSymbolPreferLocal(const GlobalValue &GV) const { … }
void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) { … }
void AsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const { … }
void AsmPrinter::emitFunctionHeaderComment() { … }
void AsmPrinter::emitFunctionPrefix(ArrayRef<const Constant *> Prefix) { … }
void AsmPrinter::emitFunctionHeader() { … }
void AsmPrinter::emitFunctionEntryLabel() { … }
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) { … }
void AsmPrinter::emitImplicitDef(const MachineInstr *MI) const { … }
static void emitKill(const MachineInstr *MI, AsmPrinter &AP) { … }
static void emitFakeUse(const MachineInstr *MI, AsmPrinter &AP) { … }
static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { … }
static bool emitDebugLabelComment(const MachineInstr *MI, AsmPrinter &AP) { … }
AsmPrinter::CFISection
AsmPrinter::getFunctionCFISectionType(const Function &F) const { … }
AsmPrinter::CFISection
AsmPrinter::getFunctionCFISectionType(const MachineFunction &MF) const { … }
bool AsmPrinter::needsSEHMoves() { … }
bool AsmPrinter::usesCFIWithoutEH() const { … }
void AsmPrinter::emitCFIInstruction(const MachineInstr &MI) { … }
void AsmPrinter::emitFrameAlloc(const MachineInstr &MI) { … }
static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) { … }
static llvm::object::BBAddrMap::Features
getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges) { … }
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { … }
void AsmPrinter::emitKCFITrapEntry(const MachineFunction &MF,
const MCSymbol *Symbol) { … }
void AsmPrinter::emitKCFITypeId(const MachineFunction &MF) { … }
void AsmPrinter::emitPseudoProbe(const MachineInstr &MI) { … }
void AsmPrinter::emitStackSizeSection(const MachineFunction &MF) { … }
void AsmPrinter::emitStackUsage(const MachineFunction &MF) { … }
void AsmPrinter::emitPCSectionsLabel(const MachineFunction &MF,
const MDNode &MD) { … }
void AsmPrinter::emitPCSections(const MachineFunction &MF) { … }
static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) { … }
void AsmPrinter::emitFunctionBody() { … }
static unsigned getNumGlobalVariableUses(const Constant *C) { … }
static bool isGOTEquivalentCandidate(const GlobalVariable *GV,
unsigned &NumGOTEquivUsers) { … }
void AsmPrinter::computeGlobalGOTEquivs(Module &M) { … }
void AsmPrinter::emitGlobalGOTEquivs() { … }
void AsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) { … }
void AsmPrinter::emitGlobalIFunc(Module &M, const GlobalIFunc &GI) { … }
void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { … }
bool AsmPrinter::doFinalization(Module &M) { … }
MCSymbol *AsmPrinter::getMBBExceptionSym(const MachineBasicBlock &MBB) { … }
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { … }
namespace {
struct SectionCPs { … };
}
void AsmPrinter::emitConstantPool() { … }
void AsmPrinter::emitJumpTableInfo() { … }
void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
const Function &F) const { … }
void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
const MachineBasicBlock *MBB,
unsigned UID) const { … }
bool AsmPrinter::emitSpecialLLVMGlobal(const GlobalVariable *GV) { … }
void AsmPrinter::emitLLVMUsedList(const ConstantArray *InitList) { … }
void AsmPrinter::preprocessXXStructorList(const DataLayout &DL,
const Constant *List,
SmallVector<Structor, 8> &Structors) { … }
void AsmPrinter::emitXXStructorList(const DataLayout &DL, const Constant *List,
bool IsCtor) { … }
void AsmPrinter::emitModuleIdents(Module &M) { … }
void AsmPrinter::emitModuleCommandLines(Module &M) { … }
void AsmPrinter::emitInt8(int Value) const { … }
void AsmPrinter::emitInt16(int Value) const { … }
void AsmPrinter::emitInt32(int Value) const { … }
void AsmPrinter::emitSLEB128(int64_t Value, const char *Desc) const { … }
void AsmPrinter::emitULEB128(uint64_t Value, const char *Desc,
unsigned PadTo) const { … }
void AsmPrinter::emitInt64(uint64_t Value) const { … }
void AsmPrinter::emitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
unsigned Size) const { … }
void AsmPrinter::emitLabelDifferenceAsULEB128(const MCSymbol *Hi,
const MCSymbol *Lo) const { … }
void AsmPrinter::emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
unsigned Size,
bool IsSectionRelative) const { … }
void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV,
unsigned MaxBytesToEmit) const { … }
const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) { … }
static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
AsmPrinter &AP,
const Constant *BaseCV = nullptr,
uint64_t Offset = 0,
AsmPrinter::AliasMapTy *AliasList = nullptr);
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP);
static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP);
static int isRepeatedByteSequence(const ConstantDataSequential *V) { … }
static int isRepeatedByteSequence(const Value *V, const DataLayout &DL) { … }
static void emitGlobalAliasInline(AsmPrinter &AP, uint64_t Offset,
AsmPrinter::AliasMapTy *AliasList) { … }
static void emitGlobalConstantDataSequential(
const DataLayout &DL, const ConstantDataSequential *CDS, AsmPrinter &AP,
AsmPrinter::AliasMapTy *AliasList) { … }
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 void emitGlobalConstantVector(const DataLayout &DL,
const ConstantVector *CV, AsmPrinter &AP,
AsmPrinter::AliasMapTy *AliasList) { … }
static void emitGlobalConstantStruct(const DataLayout &DL,
const ConstantStruct *CS, AsmPrinter &AP,
const Constant *BaseCV, uint64_t Offset,
AsmPrinter::AliasMapTy *AliasList) { … }
static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP) { … }
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) { … }
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) { … }
static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
const Constant *BaseCst,
uint64_t Offset) { … }
static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
AsmPrinter &AP, const Constant *BaseCV,
uint64_t Offset,
AsmPrinter::AliasMapTy *AliasList) { … }
void AsmPrinter::emitGlobalConstant(const DataLayout &DL, const Constant *CV,
AliasMapTy *AliasList) { … }
void AsmPrinter::emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { … }
void AsmPrinter::printOffset(int64_t Offset, raw_ostream &OS) const { … }
void AsmPrinter::emitNops(unsigned N) { … }
MCSymbol *AsmPrinter::createTempSymbol(const Twine &Name) const { … }
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA) const { … }
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BasicBlock *BB) const { … }
const MCExpr *AsmPrinter::lowerBlockAddressConstant(const BlockAddress &BA) { … }
MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const { … }
MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const { … }
MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const { … }
MCSymbol *AsmPrinter::getSymbolWithGlobalValueBase(const GlobalValue *GV,
StringRef Suffix) const { … }
MCSymbol *AsmPrinter::GetExternalSymbolSymbol(Twine Sym) const { … }
static void PrintParentLoopComment(raw_ostream &OS, const MachineLoop *Loop,
unsigned FunctionNumber) { … }
static void PrintChildLoopComment(raw_ostream &OS, const MachineLoop *Loop,
unsigned FunctionNumber) { … }
static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB,
const MachineLoopInfo *LI,
const AsmPrinter &AP) { … }
void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) { … }
void AsmPrinter::emitBasicBlockEnd(const MachineBasicBlock &MBB) { … }
void AsmPrinter::emitVisibility(MCSymbol *Sym, unsigned Visibility,
bool IsDefinition) const { … }
bool AsmPrinter::shouldEmitLabelForBasicBlock(
const MachineBasicBlock &MBB) const { … }
bool AsmPrinter::
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const { … }
GCMetadataPrinter *AsmPrinter::getOrCreateGCPrinter(GCStrategy &S) { … }
void AsmPrinter::emitStackMaps() { … }
void AsmPrinter::addAsmPrinterHandler(
std::unique_ptr<AsmPrinterHandler> Handler) { … }
void AsmPrinter::addDebugHandler(std::unique_ptr<DebugHandlerBase> Handler) { … }
AsmPrinterHandler::~AsmPrinterHandler() = default;
void AsmPrinterHandler::markFunctionEnd() { … }
void AsmPrinter::XRayFunctionEntry::emit(int Bytes, MCStreamer *Out) const { … }
void AsmPrinter::emitXRayTable() { … }
void AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI,
SledKind Kind, uint8_t Version) { … }
void AsmPrinter::emitPatchableFunctionEntries() { … }
uint16_t AsmPrinter::getDwarfVersion() const { … }
void AsmPrinter::setDwarfVersion(uint16_t Version) { … }
bool AsmPrinter::isDwarf64() const { … }
unsigned int AsmPrinter::getDwarfOffsetByteSize() const { … }
dwarf::FormParams AsmPrinter::getDwarfFormParams() const { … }
unsigned int AsmPrinter::getUnitLengthFieldByteSize() const { … }
std::tuple<const MCSymbol *, uint64_t, const MCSymbol *,
codeview::JumpTableEntrySize>
AsmPrinter::getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,
const MCSymbol *BranchLabel) const { … }