LLVM  14.0.0git
Macros | Typedefs | Functions | Variables
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/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/EHPersonalities.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/MachineBasicBlock.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/MachineMemOperand.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/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/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/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDirectives.h"
#include "llvm/MC/MCDwarf.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/MCSymbolELF.h"
#include "llvm/MC/MCSymbolXCOFF.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Pass.h"
#include "llvm/Remarks/Remark.h"
#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Remarks/RemarkStreamer.h"
#include "llvm/Remarks/RemarkStringTable.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/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstdint>
#include <iterator>
#include <limits>
#include <memory>
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "asm-printer"
 

Typedefs

using gcp_map_type = DenseMap< GCStrategy *, std::unique_ptr< GCMetadataPrinter > >
 

Functions

 STATISTIC (EmittedInsts, "Number of machine instrs printed")
 
static gcp_map_typegetGCMap (void *&P)
 
static bool canBeHidden (const GlobalValue *GV, const MCAsmInfo &MAI)
 
static void emitComments (const MachineInstr &MI, raw_ostream &CommentOS)
 emitComments - Pretty-print comments for instructions. More...
 
static void emitKill (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. More...
 
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. More...
 
static unsigned getBBAddrMapMetadata (const MachineBasicBlock &MBB)
 Returns the BB metadata to be emitted in the .llvm_bb_addr_map section for a given basic block. More...
 
static bool needFuncLabelsForEHOrDebugInfo (const MachineFunction &MF)
 
static unsigned getNumGlobalVariableUses (const Constant *C)
 Compute the number of Global Variables that uses a Constant. More...
 
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 another global variables. More...
 
static void emitGlobalConstantImpl (const DataLayout &DL, const Constant *C, AsmPrinter &AP, const Constant *BaseCV=nullptr, uint64_t Offset=0)
 
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. More...
 
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. More...
 
static void emitGlobalConstantDataSequential (const DataLayout &DL, const ConstantDataSequential *CDS, AsmPrinter &AP)
 
static void emitGlobalConstantArray (const DataLayout &DL, const ConstantArray *CA, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
 
static void emitGlobalConstantVector (const DataLayout &DL, const ConstantVector *CV, AsmPrinter &AP)
 
static void emitGlobalConstantStruct (const DataLayout &DL, const ConstantStruct *CS, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
 
static void emitGlobalConstantLargeInt (const ConstantInt *CI, AsmPrinter &AP)
 
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. More...
 
static void PrintParentLoopComment (raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
 PrintParentLoopComment - Print comments about parent loops of this one. More...
 
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. More...
 
static void emitBasicBlockLoopComments (const MachineBasicBlock &MBB, const MachineLoopInfo *LI, const AsmPrinter &AP)
 emitBasicBlockLoopComments - Pretty-print comments for basic blocks. More...
 

Variables

static cl::opt< bool > DisableDebugInfoPrinting ("disable-debug-info-print", cl::Hidden, cl::desc("Disable debug info printing"))
 
const char DWARFGroupName [] = "dwarf"
 
const char DWARFGroupDescription [] = "DWARF Emission"
 
const char DbgTimerName [] = "emit"
 
const char DbgTimerDescription [] = "Debug Info Emission"
 
const char EHTimerName [] = "write_exception"
 
const char EHTimerDescription [] = "DWARF Exception Writer"
 
const char CFGuardName [] = "Control Flow Guard"
 
const char CFGuardDescription [] = "Control Flow Guard"
 
const char CodeViewLineTablesGroupName [] = "linetables"
 
const char CodeViewLineTablesGroupDescription [] = "CodeView Line Tables"
 
const char PPTimerName [] = "emit"
 
const char PPTimerDescription [] = "Pseudo Probe Emission"
 
const char PPGroupName [] = "pseudo probe"
 
const char PPGroupDescription [] = "Pseudo Probe Emission"
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "asm-printer"

Definition at line 136 of file AsmPrinter.cpp.

Typedef Documentation

◆ gcp_map_type

using gcp_map_type = DenseMap<GCStrategy *, std::unique_ptr<GCMetadataPrinter> >

Definition at line 162 of file AsmPrinter.cpp.

Function Documentation

◆ canBeHidden()

static bool canBeHidden ( const GlobalValue GV,
const MCAsmInfo MAI 
)
static

◆ emitBasicBlockLoopComments()

static void emitBasicBlockLoopComments ( const MachineBasicBlock MBB,
const MachineLoopInfo LI,
const AsmPrinter AP 
)
static

◆ emitComments()

static void emitComments ( const MachineInstr MI,
raw_ostream CommentOS 
)
static

◆ emitDebugLabelComment()

static 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 1029 of file AsmPrinter.cpp.

References llvm::DILabel::getName(), llvm::DILocalScope::getNonLexicalBlockFileScope(), llvm::DILabel::getScope(), MI, llvm::AsmPrinter::OutStreamer, and llvm::raw_svector_ostream::str().

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

◆ emitDebugValueComment()

static bool emitDebugValueComment ( const MachineInstr MI,
AsmPrinter AP 
)
static

◆ emitGlobalConstantArray()

static void emitGlobalConstantArray ( const DataLayout DL,
const ConstantArray CA,
AsmPrinter AP,
const Constant BaseCV,
uint64_t  Offset 
)
static

◆ emitGlobalConstantDataSequential()

static void emitGlobalConstantDataSequential ( const DataLayout DL,
const ConstantDataSequential CDS,
AsmPrinter AP 
)
static

◆ emitGlobalConstantFP() [1/2]

static void emitGlobalConstantFP ( APFloat  APF,
Type ET,
AsmPrinter AP 
)
static

◆ emitGlobalConstantFP() [2/2]

static void emitGlobalConstantFP ( const ConstantFP CFP,
AsmPrinter AP 
)
static

◆ emitGlobalConstantImpl()

static void emitGlobalConstantImpl ( const DataLayout DL,
const Constant C,
AsmPrinter AP,
const Constant BaseCV = nullptr,
uint64_t  Offset = 0 
)
static

◆ emitGlobalConstantLargeInt()

static void emitGlobalConstantLargeInt ( const ConstantInt CI,
AsmPrinter AP 
)
static

◆ emitGlobalConstantStruct()

static void emitGlobalConstantStruct ( const DataLayout DL,
const ConstantStruct CS,
AsmPrinter AP,
const Constant BaseCV,
uint64_t  Offset 
)
static

◆ emitGlobalConstantVector()

static void emitGlobalConstantVector ( const DataLayout DL,
const ConstantVector CV,
AsmPrinter AP 
)
static

◆ emitKill()

static void emitKill ( const MachineInstr MI,
AsmPrinter AP 
)
static

◆ getBBAddrMapMetadata()

static unsigned getBBAddrMapMetadata ( const MachineBasicBlock MBB)
static

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

This can be used to capture more precise profile information. We use the last 4 bits (LSBs) to encode the following information:

  • (1): set if return block (ret or tail call).
  • (2): set if ends with a tail call.
  • (3): set if exception handling (EH) landing pad.
  • (4): set if the block can fall through to its next. The remaining bits are zero.

Definition at line 1126 of file AsmPrinter.cpp.

References llvm::MachineBasicBlock::back(), llvm::MachineBasicBlock::canFallThrough(), llvm::MachineBasicBlock::empty(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineBasicBlock::getParent(), llvm::MachineFunction::getSubtarget(), llvm::MachineBasicBlock::isEHPad(), llvm::MachineBasicBlock::isReturnBlock(), llvm::HexagonInstrInfo::isTailCall(), MBB, and TII.

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

◆ getGCMap()

static gcp_map_type& getGCMap ( void *&  P)
static

Definition at line 164 of file AsmPrinter.cpp.

References P.

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

◆ getNumGlobalVariableUses()

static unsigned getNumGlobalVariableUses ( const Constant C)
static

Compute the number of Global Variables that uses a Constant.

Definition at line 1527 of file AsmPrinter.cpp.

Referenced by isGOTEquivalentCandidate().

◆ handleIndirectSymViaGOTPCRel()

static void handleIndirectSymViaGOTPCRel ( AsmPrinter AP,
const MCExpr **  ME,
const Constant BaseCst,
uint64_t  Offset 
)
static

◆ isGOTEquivalentCandidate()

static bool isGOTEquivalentCandidate ( const GlobalVariable GV,
unsigned &  NumGOTEquivUsers 
)
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 1546 of file AsmPrinter.cpp.

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

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

◆ isRepeatedByteSequence() [1/2]

static 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 2670 of file AsmPrinter.cpp.

References assert(), llvm::Data, llvm::numbers::e, llvm::ConstantDataSequential::getRawDataValues(), and i.

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

◆ isRepeatedByteSequence() [2/2]

static 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 2682 of file AsmPrinter.cpp.

References assert(), DL, llvm::numbers::e, llvm::User::getOperand(), llvm::Value::getType(), i, isRepeatedByteSequence(), and llvm::Check::Size.

◆ needFuncLabelsForEHOrDebugInfo()

static bool needFuncLabelsForEHOrDebugInfo ( const MachineFunction MF)
static

◆ PrintChildLoopComment()

static 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 3206 of file AsmPrinter.cpp.

References llvm::raw_ostream::indent().

Referenced by emitBasicBlockLoopComments().

◆ PrintParentLoopComment()

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

PrintParentLoopComment - Print comments about parent loops of this one.

Definition at line 3194 of file AsmPrinter.cpp.

References llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopDepth(), llvm::LoopBase< BlockT, LoopT >::getParentLoop(), and llvm::raw_ostream::indent().

Referenced by emitBasicBlockLoopComments().

◆ STATISTIC()

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

Variable Documentation

◆ CFGuardDescription

const char CFGuardDescription[] = "Control Flow Guard"

Definition at line 150 of file AsmPrinter.cpp.

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

◆ CFGuardName

const char CFGuardName[] = "Control Flow Guard"

Definition at line 149 of file AsmPrinter.cpp.

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

◆ CodeViewLineTablesGroupDescription

const char CodeViewLineTablesGroupDescription[] = "CodeView Line Tables"

Definition at line 152 of file AsmPrinter.cpp.

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

◆ CodeViewLineTablesGroupName

const char CodeViewLineTablesGroupName[] = "linetables"

Definition at line 151 of file AsmPrinter.cpp.

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

◆ DbgTimerDescription

const char DbgTimerDescription[] = "Debug Info Emission"

Definition at line 146 of file AsmPrinter.cpp.

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

◆ DbgTimerName

const char DbgTimerName[] = "emit"

Definition at line 145 of file AsmPrinter.cpp.

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

◆ DisableDebugInfoPrinting

cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden, cl::desc("Disable debug info printing"))
static

◆ DWARFGroupDescription

const char DWARFGroupDescription[] = "DWARF Emission"

Definition at line 144 of file AsmPrinter.cpp.

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

◆ DWARFGroupName

const char DWARFGroupName[] = "dwarf"

Definition at line 143 of file AsmPrinter.cpp.

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

◆ EHTimerDescription

const char EHTimerDescription[] = "DWARF Exception Writer"

Definition at line 148 of file AsmPrinter.cpp.

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

◆ EHTimerName

const char EHTimerName[] = "write_exception"

Definition at line 147 of file AsmPrinter.cpp.

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

◆ PPGroupDescription

const char PPGroupDescription[] = "Pseudo Probe Emission"

Definition at line 156 of file AsmPrinter.cpp.

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

◆ PPGroupName

const char PPGroupName[] = "pseudo probe"

Definition at line 155 of file AsmPrinter.cpp.

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

◆ PPTimerDescription

const char PPTimerDescription[] = "Pseudo Probe Emission"

Definition at line 154 of file AsmPrinter.cpp.

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

◆ PPTimerName

const char PPTimerName[] = "emit"

Definition at line 153 of file AsmPrinter.cpp.

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