Path: blob/main/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
35269 views
//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8/// \file9/// AMDGPU Assembly printer class.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H14#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H1516#include "SIProgramInfo.h"17#include "llvm/CodeGen/AsmPrinter.h"1819namespace llvm {2021class AMDGPUMachineFunction;22struct AMDGPUResourceUsageAnalysis;23class AMDGPUTargetStreamer;24class MCCodeEmitter;25class MCOperand;2627namespace AMDGPU {28struct MCKernelDescriptor;29struct AMDGPUMCKernelCodeT;30namespace HSAMD {31class MetadataStreamer;32}33} // namespace AMDGPU3435class AMDGPUAsmPrinter final : public AsmPrinter {36private:37unsigned CodeObjectVersion;38void initializeTargetID(const Module &M);3940AMDGPUResourceUsageAnalysis *ResourceUsage;4142SIProgramInfo CurrentProgramInfo;4344std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;4546MCCodeEmitter *DumpCodeInstEmitter = nullptr;4748uint64_t getFunctionCodeSize(const MachineFunction &MF) const;4950void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);51void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,52const SIProgramInfo &KernelInfo,53const MachineFunction &MF) const;5455/// Emit register usage information so that the GPU driver56/// can correctly setup the GPU state.57void EmitProgramInfoSI(const MachineFunction &MF,58const SIProgramInfo &KernelInfo);59void EmitPALMetadata(const MachineFunction &MF,60const SIProgramInfo &KernelInfo);61void emitPALFunctionMetadata(const MachineFunction &MF);62void emitCommonFunctionComments(uint32_t NumVGPR,63std::optional<uint32_t> NumAGPR,64uint32_t TotalNumVGPR, uint32_t NumSGPR,65uint64_t ScratchSize, uint64_t CodeSize,66const AMDGPUMachineFunction *MFI);67void emitCommonFunctionComments(const MCExpr *NumVGPR, const MCExpr *NumAGPR,68const MCExpr *TotalNumVGPR,69const MCExpr *NumSGPR,70const MCExpr *ScratchSize, uint64_t CodeSize,71const AMDGPUMachineFunction *MFI);72void emitResourceUsageRemarks(const MachineFunction &MF,73const SIProgramInfo &CurrentProgramInfo,74bool isModuleEntryFunction, bool hasMAIInsts);7576const MCExpr *getAmdhsaKernelCodeProperties(const MachineFunction &MF) const;7778AMDGPU::MCKernelDescriptor79getAmdhsaKernelDescriptor(const MachineFunction &MF,80const SIProgramInfo &PI) const;8182void initTargetStreamer(Module &M);8384SmallString<128> getMCExprStr(const MCExpr *Value);8586public:87explicit AMDGPUAsmPrinter(TargetMachine &TM,88std::unique_ptr<MCStreamer> Streamer);8990StringRef getPassName() const override;9192const MCSubtargetInfo* getGlobalSTI() const;9394AMDGPUTargetStreamer* getTargetStreamer() const;9596bool doInitialization(Module &M) override;97bool doFinalization(Module &M) override;98bool runOnMachineFunction(MachineFunction &MF) override;99100/// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated101/// pseudo lowering.102bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;103104/// Lower the specified LLVM Constant to an MCExpr.105/// The AsmPrinter::lowerConstantof does not know how to lower106/// addrspacecast, therefore they should be lowered by this function.107const MCExpr *lowerConstant(const Constant *CV) override;108109/// tblgen'erated driver function for lowering simple MI->MC pseudo110/// instructions.111bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,112const MachineInstr *MI);113114/// Implemented in AMDGPUMCInstLower.cpp115void emitInstruction(const MachineInstr *MI) override;116117void emitFunctionBodyStart() override;118119void emitFunctionBodyEnd() override;120121void emitImplicitDef(const MachineInstr *MI) const override;122123void emitFunctionEntryLabel() override;124125void emitBasicBlockStart(const MachineBasicBlock &MBB) override;126127void emitGlobalVariable(const GlobalVariable *GV) override;128129void emitStartOfAsmFile(Module &M) override;130131void emitEndOfAsmFile(Module &M) override;132133bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,134const char *ExtraCode, raw_ostream &O) override;135136protected:137void getAnalysisUsage(AnalysisUsage &AU) const override;138139std::vector<std::string> DisasmLines, HexLines;140size_t DisasmLineMaxLen;141bool IsTargetStreamerInitialized;142};143144} // end namespace llvm145146#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H147148149