2013-11-10 09:03:59 +08:00
|
|
|
//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// AMDGPU Assembly printer class.
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2017-03-27 22:04:01 +08:00
|
|
|
#include "AMDGPU.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "AMDKernelCodeT.h"
|
2018-07-11 04:07:22 +08:00
|
|
|
#include "AMDGPUHSAMetadataStreamer.h"
|
2018-07-11 01:31:32 +08:00
|
|
|
#include "SIProgramInfo.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2018-06-13 02:02:46 +08:00
|
|
|
#include "llvm/Support/AMDHSAKernelDescriptor.h"
|
2017-01-21 01:52:16 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2013-10-12 13:02:51 +08:00
|
|
|
#include <vector>
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-01-21 01:52:16 +08:00
|
|
|
|
2018-05-26 01:25:12 +08:00
|
|
|
class AMDGPUMachineFunction;
|
2017-03-23 06:32:22 +08:00
|
|
|
class AMDGPUTargetStreamer;
|
2019-05-15 00:17:14 +08:00
|
|
|
class MCCodeEmitter;
|
2016-10-07 01:19:11 +08:00
|
|
|
class MCOperand;
|
2018-07-12 04:59:01 +08:00
|
|
|
class GCNSubtarget;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
class AMDGPUAsmPrinter final : public AsmPrinter {
|
2013-12-05 13:15:35 +08:00
|
|
|
private:
|
2017-05-03 01:14:00 +08:00
|
|
|
// Track resource usage for callee functions.
|
|
|
|
struct SIFunctionResourceInfo {
|
|
|
|
// Track the number of explicitly used VGPRs. Special registers reserved at
|
|
|
|
// the end are tracked separately.
|
|
|
|
int32_t NumVGPR = 0;
|
2019-10-02 08:26:58 +08:00
|
|
|
int32_t NumAGPR = 0;
|
2017-05-03 01:14:00 +08:00
|
|
|
int32_t NumExplicitSGPR = 0;
|
2017-11-15 04:33:14 +08:00
|
|
|
uint64_t PrivateSegmentSize = 0;
|
2017-05-03 01:14:00 +08:00
|
|
|
bool UsesVCC = false;
|
|
|
|
bool UsesFlatScratch = false;
|
|
|
|
bool HasDynamicallySizedStack = false;
|
|
|
|
bool HasRecursion = false;
|
|
|
|
|
2018-07-12 04:59:01 +08:00
|
|
|
int32_t getTotalNumSGPRs(const GCNSubtarget &ST) const;
|
2019-10-02 08:26:58 +08:00
|
|
|
int32_t getTotalNumVGPRs(const GCNSubtarget &ST) const;
|
2017-05-03 01:14:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
SIProgramInfo CurrentProgramInfo;
|
|
|
|
DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;
|
2017-10-12 06:59:35 +08:00
|
|
|
|
2018-12-13 03:39:27 +08:00
|
|
|
std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
|
2017-05-03 01:14:00 +08:00
|
|
|
|
2019-05-15 00:17:14 +08:00
|
|
|
MCCodeEmitter *DumpCodeInstEmitter = nullptr;
|
|
|
|
|
2017-04-18 03:48:30 +08:00
|
|
|
uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
|
2017-05-03 01:14:00 +08:00
|
|
|
SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF) const;
|
|
|
|
|
|
|
|
void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
|
2017-03-23 06:54:39 +08:00
|
|
|
void getAmdKernelCode(amd_kernel_code_t &Out, const SIProgramInfo &KernelInfo,
|
|
|
|
const MachineFunction &MF) const;
|
2014-07-13 11:06:43 +08:00
|
|
|
void findNumUsedRegistersSI(const MachineFunction &MF,
|
2013-12-05 13:15:35 +08:00
|
|
|
unsigned &NumSGPR,
|
|
|
|
unsigned &NumVGPR) const;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Emit register usage information so that the GPU driver
|
2013-12-05 13:15:35 +08:00
|
|
|
/// can correctly setup the GPU state.
|
2017-10-12 06:41:09 +08:00
|
|
|
void EmitProgramInfoSI(const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &KernelInfo);
|
|
|
|
void EmitPALMetadata(const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &KernelInfo);
|
2017-05-03 01:14:00 +08:00
|
|
|
void emitCommonFunctionComments(uint32_t NumVGPR,
|
2019-10-02 08:26:58 +08:00
|
|
|
Optional<uint32_t> NumAGPR,
|
|
|
|
uint32_t TotalNumVGPR,
|
2017-05-03 01:14:00 +08:00
|
|
|
uint32_t NumSGPR,
|
2017-11-15 04:33:14 +08:00
|
|
|
uint64_t ScratchSize,
|
2018-05-26 01:25:12 +08:00
|
|
|
uint64_t CodeSize,
|
|
|
|
const AMDGPUMachineFunction* MFI);
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2018-06-13 02:02:46 +08:00
|
|
|
uint16_t getAmdhsaKernelCodeProperties(
|
|
|
|
const MachineFunction &MF) const;
|
|
|
|
|
|
|
|
amdhsa::kernel_descriptor_t getAmdhsaKernelDescriptor(
|
|
|
|
const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &PI) const;
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
public:
|
2015-01-19 04:29:04 +08:00
|
|
|
explicit AMDGPUAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer);
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2019-02-13 07:44:13 +08:00
|
|
|
const MCSubtargetInfo* getGlobalSTI() const;
|
2017-03-23 06:32:22 +08:00
|
|
|
|
2017-10-15 06:16:26 +08:00
|
|
|
AMDGPUTargetStreamer* getTargetStreamer() const;
|
2017-03-23 06:32:22 +08:00
|
|
|
|
2017-05-03 01:14:00 +08:00
|
|
|
bool doFinalization(Module &M) override;
|
2017-03-23 06:32:22 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
|
2016-10-07 01:19:11 +08:00
|
|
|
/// pseudo lowering.
|
|
|
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Lower the specified LLVM Constant to an MCExpr.
|
2017-02-07 08:43:21 +08:00
|
|
|
/// The AsmPrinter::lowerConstantof does not know how to lower
|
|
|
|
/// addrspacecast, therefore they should be lowered by this function.
|
|
|
|
const MCExpr *lowerConstant(const Constant *CV) override;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// tblgen'erated driver function for lowering simple MI->MC pseudo
|
2016-10-07 01:19:11 +08:00
|
|
|
/// instructions.
|
|
|
|
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
|
|
|
|
const MachineInstr *MI);
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
/// Implemented in AMDGPUMCInstLower.cpp
|
2014-04-29 15:57:24 +08:00
|
|
|
void EmitInstruction(const MachineInstr *MI) override;
|
2013-10-12 13:02:51 +08:00
|
|
|
|
2015-06-27 05:14:58 +08:00
|
|
|
void EmitFunctionBodyStart() override;
|
|
|
|
|
2018-06-13 02:02:46 +08:00
|
|
|
void EmitFunctionBodyEnd() override;
|
|
|
|
|
2015-11-06 19:45:14 +08:00
|
|
|
void EmitFunctionEntryLabel() override;
|
|
|
|
|
2019-08-20 13:13:57 +08:00
|
|
|
void EmitBasicBlockStart(const MachineBasicBlock &MBB) override;
|
2017-12-08 22:09:34 +08:00
|
|
|
|
2015-12-03 01:00:42 +08:00
|
|
|
void EmitGlobalVariable(const GlobalVariable *GV) override;
|
|
|
|
|
2016-01-13 01:18:17 +08:00
|
|
|
void EmitStartOfAsmFile(Module &M) override;
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
void EmitEndOfAsmFile(Module &M) override;
|
|
|
|
|
2016-10-07 00:20:41 +08:00
|
|
|
bool isBlockOnlyReachableByFallthrough(
|
|
|
|
const MachineBasicBlock *MBB) const override;
|
|
|
|
|
2015-04-08 09:09:26 +08:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
const char *ExtraCode, raw_ostream &O) override;
|
2015-04-08 09:09:26 +08:00
|
|
|
|
2013-10-12 13:02:51 +08:00
|
|
|
protected:
|
2019-08-20 13:13:57 +08:00
|
|
|
std::vector<std::string> DisasmLines, HexLines;
|
|
|
|
size_t DisasmLineMaxLen;
|
2012-12-12 05:25:42 +08:00
|
|
|
};
|
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
} // end namespace llvm
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|