Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Target / AMDGPU / AMDGPUAsmPrinter.h
blobf70a60aef007367548cfbf4ec13d335e73abd093
1 //===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// AMDGPU Assembly printer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
15 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
17 #include "SIProgramInfo.h"
18 #include "llvm/CodeGen/AsmPrinter.h"
20 namespace llvm {
22 class AMDGPUMachineFunction;
23 struct AMDGPUResourceUsageAnalysis;
24 class AMDGPUTargetStreamer;
25 class MCCodeEmitter;
26 class MCOperand;
28 namespace AMDGPU {
29 struct MCKernelDescriptor;
30 struct AMDGPUMCKernelCodeT;
31 namespace HSAMD {
32 class MetadataStreamer;
34 } // namespace AMDGPU
36 class AMDGPUAsmPrinter final : public AsmPrinter {
37 private:
38 unsigned CodeObjectVersion;
39 void initializeTargetID(const Module &M);
41 AMDGPUResourceUsageAnalysis *ResourceUsage;
43 SIProgramInfo CurrentProgramInfo;
45 std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
47 MCCodeEmitter *DumpCodeInstEmitter = nullptr;
49 uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
51 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
52 void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,
53 const SIProgramInfo &KernelInfo,
54 const MachineFunction &MF) const;
56 /// Emit register usage information so that the GPU driver
57 /// can correctly setup the GPU state.
58 void EmitProgramInfoSI(const MachineFunction &MF,
59 const SIProgramInfo &KernelInfo);
60 void EmitPALMetadata(const MachineFunction &MF,
61 const SIProgramInfo &KernelInfo);
62 void emitPALFunctionMetadata(const MachineFunction &MF);
63 void emitCommonFunctionComments(uint32_t NumVGPR,
64 std::optional<uint32_t> NumAGPR,
65 uint32_t TotalNumVGPR, uint32_t NumSGPR,
66 uint64_t ScratchSize, uint64_t CodeSize,
67 const AMDGPUMachineFunction *MFI);
68 void emitCommonFunctionComments(const MCExpr *NumVGPR, const MCExpr *NumAGPR,
69 const MCExpr *TotalNumVGPR,
70 const MCExpr *NumSGPR,
71 const MCExpr *ScratchSize, uint64_t CodeSize,
72 const AMDGPUMachineFunction *MFI);
73 void emitResourceUsageRemarks(const MachineFunction &MF,
74 const SIProgramInfo &CurrentProgramInfo,
75 bool isModuleEntryFunction, bool hasMAIInsts);
77 const MCExpr *getAmdhsaKernelCodeProperties(const MachineFunction &MF) const;
79 AMDGPU::MCKernelDescriptor
80 getAmdhsaKernelDescriptor(const MachineFunction &MF,
81 const SIProgramInfo &PI) const;
83 void initTargetStreamer(Module &M);
85 SmallString<128> getMCExprStr(const MCExpr *Value);
87 public:
88 explicit AMDGPUAsmPrinter(TargetMachine &TM,
89 std::unique_ptr<MCStreamer> Streamer);
91 StringRef getPassName() const override;
93 const MCSubtargetInfo* getGlobalSTI() const;
95 AMDGPUTargetStreamer* getTargetStreamer() const;
97 bool doInitialization(Module &M) override;
98 bool doFinalization(Module &M) override;
99 bool runOnMachineFunction(MachineFunction &MF) override;
101 /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
102 /// pseudo lowering.
103 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
105 /// Lower the specified LLVM Constant to an MCExpr.
106 /// The AsmPrinter::lowerConstantof does not know how to lower
107 /// addrspacecast, therefore they should be lowered by this function.
108 const MCExpr *lowerConstant(const Constant *CV) override;
110 /// tblgen'erated driver function for lowering simple MI->MC pseudo
111 /// instructions.
112 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
113 const MachineInstr *MI);
115 /// Implemented in AMDGPUMCInstLower.cpp
116 void emitInstruction(const MachineInstr *MI) override;
118 void emitFunctionBodyStart() override;
120 void emitFunctionBodyEnd() override;
122 void emitImplicitDef(const MachineInstr *MI) const override;
124 void emitFunctionEntryLabel() override;
126 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
128 void emitGlobalVariable(const GlobalVariable *GV) override;
130 void emitStartOfAsmFile(Module &M) override;
132 void emitEndOfAsmFile(Module &M) override;
134 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
135 const char *ExtraCode, raw_ostream &O) override;
137 protected:
138 void getAnalysisUsage(AnalysisUsage &AU) const override;
140 std::vector<std::string> DisasmLines, HexLines;
141 size_t DisasmLineMaxLen;
142 bool IsTargetStreamerInitialized;
145 } // end namespace llvm
147 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H