2013-11-10 02:03:59 +01:00
|
|
|
//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
|
2012-12-11 22:25:42 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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-11 22:25:42 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 17:54:18 +02:00
|
|
|
/// AMDGPU Assembly printer class.
|
2012-12-11 22:25:42 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 09:00:27 +01:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2017-03-27 16:04:01 +02:00
|
|
|
#include "AMDGPU.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "AMDKernelCodeT.h"
|
2018-07-10 22:07:22 +02:00
|
|
|
#include "AMDGPUHSAMetadataStreamer.h"
|
2018-07-10 19:31:32 +02:00
|
|
|
#include "SIProgramInfo.h"
|
2017-01-20 18:52:16 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-11 22:25:42 +01:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2018-06-12 20:02:46 +02:00
|
|
|
#include "llvm/Support/AMDHSAKernelDescriptor.h"
|
2017-01-20 18:52:16 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2013-10-12 07:02:51 +02:00
|
|
|
#include <vector>
|
2012-12-11 22:25:42 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-01-20 18:52:16 +01:00
|
|
|
|
2018-05-25 19:25:12 +02:00
|
|
|
class AMDGPUMachineFunction;
|
2017-03-22 23:32:22 +01:00
|
|
|
class AMDGPUTargetStreamer;
|
2016-10-06 19:19:11 +02:00
|
|
|
class MCOperand;
|
2018-07-11 22:59:01 +02:00
|
|
|
class GCNSubtarget;
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2016-03-11 09:00:27 +01:00
|
|
|
class AMDGPUAsmPrinter final : public AsmPrinter {
|
2013-12-05 06:15:35 +01:00
|
|
|
private:
|
2017-05-02 19:14:00 +02: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;
|
|
|
|
int32_t NumExplicitSGPR = 0;
|
2017-11-14 21:33:14 +01:00
|
|
|
uint64_t PrivateSegmentSize = 0;
|
2017-05-02 19:14:00 +02:00
|
|
|
bool UsesVCC = false;
|
|
|
|
bool UsesFlatScratch = false;
|
|
|
|
bool HasDynamicallySizedStack = false;
|
|
|
|
bool HasRecursion = false;
|
|
|
|
|
2018-07-11 22:59:01 +02:00
|
|
|
int32_t getTotalNumSGPRs(const GCNSubtarget &ST) const;
|
2017-05-02 19:14:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SIProgramInfo CurrentProgramInfo;
|
|
|
|
DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;
|
2017-10-12 00:59:35 +02:00
|
|
|
|
2018-12-12 20:39:27 +01:00
|
|
|
std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
|
2017-10-12 00:41:09 +02:00
|
|
|
std::map<uint32_t, uint32_t> PALMetadataMap;
|
2017-05-02 19:14:00 +02:00
|
|
|
|
2017-04-17 21:48:30 +02:00
|
|
|
uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
|
2017-05-02 19:14:00 +02:00
|
|
|
SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF) const;
|
|
|
|
|
2017-10-12 00:41:09 +02:00
|
|
|
void readPALMetadata(Module &M);
|
2017-05-02 19:14:00 +02:00
|
|
|
void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
|
2017-03-22 23:54:39 +01:00
|
|
|
void getAmdKernelCode(amd_kernel_code_t &Out, const SIProgramInfo &KernelInfo,
|
|
|
|
const MachineFunction &MF) const;
|
2014-07-13 05:06:43 +02:00
|
|
|
void findNumUsedRegistersSI(const MachineFunction &MF,
|
2013-12-05 06:15:35 +01:00
|
|
|
unsigned &NumSGPR,
|
|
|
|
unsigned &NumVGPR) const;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Emit register usage information so that the GPU driver
|
2013-12-05 06:15:35 +01:00
|
|
|
/// can correctly setup the GPU state.
|
2017-10-12 00:41:09 +02:00
|
|
|
void EmitProgramInfoSI(const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &KernelInfo);
|
|
|
|
void EmitPALMetadata(const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &KernelInfo);
|
2017-05-02 19:14:00 +02:00
|
|
|
void emitCommonFunctionComments(uint32_t NumVGPR,
|
|
|
|
uint32_t NumSGPR,
|
2017-11-14 21:33:14 +01:00
|
|
|
uint64_t ScratchSize,
|
2018-05-25 19:25:12 +02:00
|
|
|
uint64_t CodeSize,
|
|
|
|
const AMDGPUMachineFunction* MFI);
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2018-06-12 20:02:46 +02:00
|
|
|
uint16_t getAmdhsaKernelCodeProperties(
|
|
|
|
const MachineFunction &MF) const;
|
|
|
|
|
|
|
|
amdhsa::kernel_descriptor_t getAmdhsaKernelDescriptor(
|
|
|
|
const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &PI) const;
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
public:
|
2015-01-18 21:29:04 +01:00
|
|
|
explicit AMDGPUAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer);
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2016-10-01 04:56:57 +02:00
|
|
|
StringRef getPassName() const override;
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2017-03-22 23:32:22 +01:00
|
|
|
const MCSubtargetInfo* getSTI() const;
|
|
|
|
|
2017-10-15 00:16:26 +02:00
|
|
|
AMDGPUTargetStreamer* getTargetStreamer() const;
|
2017-03-22 23:32:22 +01:00
|
|
|
|
2017-05-02 19:14:00 +02:00
|
|
|
bool doFinalization(Module &M) override;
|
2017-03-22 23:32:22 +01:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
|
2016-10-06 19:19:11 +02:00
|
|
|
/// pseudo lowering.
|
|
|
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Lower the specified LLVM Constant to an MCExpr.
|
2017-02-07 01:43:21 +01: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 17:54:18 +02:00
|
|
|
/// tblgen'erated driver function for lowering simple MI->MC pseudo
|
2016-10-06 19:19:11 +02:00
|
|
|
/// instructions.
|
|
|
|
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
|
|
|
|
const MachineInstr *MI);
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
/// Implemented in AMDGPUMCInstLower.cpp
|
2014-04-29 09:57:24 +02:00
|
|
|
void EmitInstruction(const MachineInstr *MI) override;
|
2013-10-12 07:02:51 +02:00
|
|
|
|
2015-06-26 23:14:58 +02:00
|
|
|
void EmitFunctionBodyStart() override;
|
|
|
|
|
2018-06-12 20:02:46 +02:00
|
|
|
void EmitFunctionBodyEnd() override;
|
|
|
|
|
2015-11-06 12:45:14 +01:00
|
|
|
void EmitFunctionEntryLabel() override;
|
|
|
|
|
2017-12-08 15:09:34 +01:00
|
|
|
void EmitBasicBlockStart(const MachineBasicBlock &MBB) const override;
|
|
|
|
|
2015-12-02 18:00:42 +01:00
|
|
|
void EmitGlobalVariable(const GlobalVariable *GV) override;
|
|
|
|
|
2016-01-12 18:18:17 +01:00
|
|
|
void EmitStartOfAsmFile(Module &M) override;
|
|
|
|
|
2017-03-22 23:32:22 +01:00
|
|
|
void EmitEndOfAsmFile(Module &M) override;
|
|
|
|
|
2016-10-06 18:20:41 +02:00
|
|
|
bool isBlockOnlyReachableByFallthrough(
|
|
|
|
const MachineBasicBlock *MBB) const override;
|
|
|
|
|
2015-04-08 03:09:26 +02:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2015-04-08 04:07:05 +02:00
|
|
|
raw_ostream &O) override;
|
2015-04-08 03:09:26 +02:00
|
|
|
|
2013-10-12 07:02:51 +02:00
|
|
|
protected:
|
2017-12-08 15:09:34 +01:00
|
|
|
mutable std::vector<std::string> DisasmLines, HexLines;
|
|
|
|
mutable size_t DisasmLineMaxLen;
|
2012-12-11 22:25:42 +01:00
|
|
|
};
|
|
|
|
|
2017-01-20 18:52:16 +01:00
|
|
|
} // end namespace llvm
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2017-01-20 18:52:16 +01:00
|
|
|
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|