LLVM 22.0.0git
AsmPrinter.cpp File Reference
#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/MCSchedule.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/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>

Go to the source code of this file.

Classes

class  llvm::AddrLabelMap

Macros

#define DEBUG_TYPE   "asm-printer"

Enumerations

enum class  PGOMapFeaturesEnum {
  None , FuncEntryCount , BBFreq , BrProb ,
  All
}

Functions

 STATISTIC (EmittedInsts, "Number of machine instrs printed")
static bool canBeHidden (const GlobalValue *GV, const MCAsmInfo &MAI)
static void emitComments (const MachineInstr &MI, const MCSubtargetInfo *STI, raw_ostream &CommentOS)
 emitComments - Pretty-print comments for instructions.
static void emitKill (const MachineInstr *MI, AsmPrinter &AP)
static void emitFakeUse (const MachineInstr *MI, AsmPrinter &AP)
static bool emitDebugValueComment (const MachineInstr *MI, AsmPrinter &AP)
 emitDebugValueComment - This method handles the target-independent form of DBG_VALUE, returning true if it was able to do so.
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 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 llvm::object::BBAddrMap::Features getBBAddrMapFeature (const MachineFunction &MF, int NumMBBSectionRanges, bool HasCalls)
static ConstantIntextractNumericCGTypeId (const Function &F)
 Extracts a generalized numeric type identifier of a Function's type from type metadata.
static bool needFuncLabels (const MachineFunction &MF, const AsmPrinter &Asm)
 Returns true if function begin and end labels should be emitted.
static StringRef getMIMnemonic (const MachineInstr &MI, MCStreamer &Streamer)
static unsigned getNumGlobalVariableUses (const Constant *C, bool &HasNonGlobalUsers)
 Compute the number of Global Variables that uses a Constant.
static bool isGOTEquivalentCandidate (const GlobalVariable *GV, unsigned &NumGOTEquivUsers, bool &HasNonGlobalUsers)
 Only consider global GOT equivalents if at least one user is a cstexpr inside an initializer of another global variables.
static uint64_t globalSize (const llvm::GlobalVariable &G)
static bool shouldTagGlobal (const llvm::GlobalVariable &G)
static void tagGlobalDefinition (Module &M, GlobalVariable *G)
static void removeMemtagFromGlobal (GlobalVariable &G)
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)
 isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of identical bytes and return the byte value.
static int isRepeatedByteSequence (const Value *V, const DataLayout &DL)
 isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of identical bytes and return the byte value.
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 Constant *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 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, by a target specific GOT pc relative access to the final symbol.
static void PrintParentLoopComment (raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
 PrintParentLoopComment - Print comments about parent loops of this one.
static void PrintChildLoopComment (raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
 PrintChildLoopComment - Print comments about child loops within the loop for this basic block, with nesting.
static void emitBasicBlockLoopComments (const MachineBasicBlock &MBB, const MachineLoopInfo *LI, const AsmPrinter &AP)
 emitBasicBlockLoopComments - Pretty-print comments for basic blocks.

Variables

static cl::bits< PGOMapFeaturesEnumPgoAnalysisMapFeatures ("pgo-analysis-map", cl::Hidden, cl::CommaSeparated, cl::values(clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"), clEnumValN(PGOMapFeaturesEnum::FuncEntryCount, "func-entry-count", "Function Entry Count"), clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq", "Basic Block Frequency"), clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"), clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")), cl::desc("Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is " "extracted from PGO related analysis."))
static cl::opt< boolBBAddrMapSkipEmitBBEntries ("basic-block-address-map-skip-bb-entries", cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP " "section. It's used to save binary size when BB entries are " "unnecessary for some PGOAnalysisMap features."), cl::Hidden, cl::init(false))
static cl::opt< boolEmitJumpTableSizesSection ("emit-jump-table-sizes-section", cl::desc("Emit a section containing jump table addresses and sizes"), cl::Hidden, cl::init(false))
static cl::opt< boolPrintLatency ("asm-print-latency", cl::desc("Print instruction latencies as verbose asm comments"), cl::Hidden, cl::init(false))

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "asm-printer"

Definition at line 137 of file AsmPrinter.cpp.

Enumeration Type Documentation

◆ PGOMapFeaturesEnum

enum class PGOMapFeaturesEnum
strong
Enumerator
None 
FuncEntryCount 
BBFreq 
BrProb 
All 

Definition at line 143 of file AsmPrinter.cpp.

Function Documentation

◆ canBeHidden()

◆ emitBasicBlockLoopComments()

◆ emitComments()

◆ emitDebugLabelComment()

bool emitDebugLabelComment ( const MachineInstr * MI,
AsmPrinter & AP )
static

This method handles the target-independent form of DBG_LABEL, returning true if it was able to do so.

A false return means the target will need to handle MI in EmitInstruction.

Definition at line 1291 of file AsmPrinter.cpp.

References llvm::dyn_cast(), MI, llvm::AsmPrinter::OutStreamer, and llvm::raw_svector_ostream::str().

Referenced by llvm::AsmPrinter::emitFunctionBody().

◆ emitDebugValueComment()

◆ emitFakeUse()

◆ emitGlobalAliasInline()

void emitGlobalAliasInline ( AsmPrinter & AP,
uint64_t Offset,
AsmPrinter::AliasMapTy * AliasList )
static

◆ emitGlobalConstantArray()

◆ emitGlobalConstantDataSequential()

◆ emitGlobalConstantFP() [1/2]

◆ emitGlobalConstantFP() [2/2]

◆ emitGlobalConstantImpl()

◆ emitGlobalConstantLargeInt()

◆ emitGlobalConstantStruct()

◆ emitGlobalConstantVector()

◆ emitKill()

◆ extractNumericCGTypeId()

ConstantInt * extractNumericCGTypeId ( const Function & F)
static

Extracts a generalized numeric type identifier of a Function's type from type metadata.

Returns null if metadata cannot be found.

Definition at line 1659 of file AsmPrinter.cpp.

References llvm::cast(), F, llvm::Type::getInt64Ty(), llvm::MDString::getString(), and llvm::sampleprof::MD5Hash().

Referenced by llvm::AsmPrinter::emitCallGraphSection().

◆ getBBAddrMapFeature()

◆ getBBAddrMapMetadata()

uint32_t getBBAddrMapMetadata ( const MachineBasicBlock & MBB)
static

Returns the BB metadata to be emitted in the SHT_LLVM_BB_ADDR_MAP section for a given basic block.

This can be used to capture more precise profile information.

Definition at line 1384 of file AsmPrinter.cpp.

References llvm::object::BBAddrMap::BBEntry::Metadata::encode(), MBB, and TII.

Referenced by llvm::AsmPrinter::emitBBAddrMapSection().

◆ getMIMnemonic()

StringRef getMIMnemonic ( const MachineInstr & MI,
MCStreamer & Streamer )
static

◆ getNumGlobalVariableUses()

unsigned getNumGlobalVariableUses ( const Constant * C,
bool & HasNonGlobalUsers )
static

Compute the number of Global Variables that uses a Constant.

Definition at line 2265 of file AsmPrinter.cpp.

References llvm::CallingConv::C, llvm::dyn_cast(), getNumGlobalVariableUses(), and llvm::isa().

Referenced by getNumGlobalVariableUses(), and isGOTEquivalentCandidate().

◆ globalSize()

uint64_t globalSize ( const llvm::GlobalVariable & G)
static

Definition at line 2542 of file AsmPrinter.cpp.

References G, and llvm::Value::getType().

Referenced by shouldTagGlobal(), and tagGlobalDefinition().

◆ handleIndirectSymViaGOTPCRel()

◆ isGOTEquivalentCandidate()

bool isGOTEquivalentCandidate ( const GlobalVariable * GV,
unsigned & NumGOTEquivUsers,
bool & HasNonGlobalUsers )
static

Only consider global GOT equivalents if at least one user is a cstexpr inside an initializer of another global variables.

Also, don't handle cstexpr inside instructions. During global variable emission, candidates are skipped and are emitted later in case at least one cstexpr isn't replaced by a PC relative GOT entry access.

Definition at line 2288 of file AsmPrinter.cpp.

References llvm::dyn_cast(), getNumGlobalVariableUses(), llvm::User::getOperand(), llvm::GlobalValue::hasGlobalUnnamedAddr(), llvm::GlobalVariable::hasInitializer(), llvm::isa(), llvm::GlobalVariable::isConstant(), llvm::GlobalValue::isDiscardableIfUnused(), and llvm::Value::users().

Referenced by llvm::AsmPrinter::computeGlobalGOTEquivs().

◆ isRepeatedByteSequence() [1/2]

int isRepeatedByteSequence ( const ConstantDataSequential * V)
static

isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of identical bytes and return the byte value.

If it is not a repeated sequence, return -1.

Definition at line 3767 of file AsmPrinter.cpp.

References assert(), llvm::CallingConv::C, and llvm::Data.

Referenced by emitGlobalConstantArray(), emitGlobalConstantDataSequential(), and isRepeatedByteSequence().

◆ isRepeatedByteSequence() [2/2]

int isRepeatedByteSequence ( const Value * V,
const DataLayout & DL )
static

isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of identical bytes and return the byte value.

If it is not a repeated sequence, return -1.

Definition at line 3779 of file AsmPrinter.cpp.

References assert(), DL, llvm::dyn_cast(), llvm::User::getOperand(), isRepeatedByteSequence(), and Size.

◆ needFuncLabels()

◆ PrintChildLoopComment()

void PrintChildLoopComment ( raw_ostream & OS,
const MachineLoop * Loop,
unsigned FunctionNumber )
static

PrintChildLoopComment - Print comments about child loops within the loop for this basic block, with nesting.

Definition at line 4392 of file AsmPrinter.cpp.

References llvm::raw_ostream::indent(), and PrintChildLoopComment().

Referenced by emitBasicBlockLoopComments(), and PrintChildLoopComment().

◆ PrintParentLoopComment()

void PrintParentLoopComment ( raw_ostream & OS,
const MachineLoop * Loop,
unsigned FunctionNumber )
static

◆ removeMemtagFromGlobal()

void removeMemtagFromGlobal ( GlobalVariable & G)
static

Definition at line 2614 of file AsmPrinter.cpp.

References G.

Referenced by llvm::AsmPrinter::doFinalization().

◆ shouldTagGlobal()

bool shouldTagGlobal ( const llvm::GlobalVariable & G)
static

Definition at line 2548 of file AsmPrinter.cpp.

References G, and globalSize().

Referenced by llvm::AsmPrinter::doFinalization().

◆ STATISTIC()

STATISTIC ( EmittedInsts ,
"Number of machine instrs printed"  )

◆ tagGlobalDefinition()

Variable Documentation

◆ BBAddrMapSkipEmitBBEntries

cl::opt< bool > BBAddrMapSkipEmitBBEntries("basic-block-address-map-skip-bb-entries", cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP " "section. It's used to save binary size when BB entries are " "unnecessary for some PGOAnalysisMap features."), cl::Hidden, cl::init(false)) ( "basic-block-address-map-skip-bb-entries" ,
cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP " "section. It's used to save binary size when BB entries are " "unnecessary for some PGOAnalysisMap features.") ,
cl::Hidden ,
cl::init(false)  )
static

Referenced by getBBAddrMapFeature().

◆ EmitJumpTableSizesSection

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)) ( "emit-jump-table-sizes-section" ,
cl::desc("Emit a section containing jump table addresses and sizes") ,
cl::Hidden ,
cl::init(false)  )
static

◆ PgoAnalysisMapFeatures

cl::bits< PGOMapFeaturesEnum > PgoAnalysisMapFeatures("pgo-analysis-map", cl::Hidden, cl::CommaSeparated, cl::values( clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"), clEnumValN(PGOMapFeaturesEnum::FuncEntryCount, "func-entry-count", "Function Entry Count"), clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq", "Basic Block Frequency"), clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"), clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")), cl::desc( "Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is " "extracted from PGO related analysis.")) ( "pgo-analysis-map" ,
cl::Hidden ,
cl::CommaSeparated ,
cl::values( clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"), clEnumValN(PGOMapFeaturesEnum::FuncEntryCount, "func-entry-count", "Function Entry Count"), clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq", "Basic Block Frequency"), clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"), clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")) ,
cl::desc( "Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is " "extracted from PGO related analysis.")  )
static

◆ PrintLatency

cl::opt< bool > PrintLatency("asm-print-latency", cl::desc("Print instruction latencies as verbose asm comments"), cl::Hidden, cl::init(false)) ( "asm-print-latency" ,
cl::desc("Print instruction latencies as verbose asm comments") ,
cl::Hidden ,
cl::init(false)  )
static

Referenced by emitComments().