2013-11-10 09:03:59 +08:00
|
|
|
//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// \brief AMDGPU Assembly printer class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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"
|
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"
|
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
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
class AMDGPUTargetStreamer;
|
2016-10-07 01:19:11 +08:00
|
|
|
class MCOperand;
|
2017-05-03 01:14:00 +08:00
|
|
|
class SISubtarget;
|
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;
|
|
|
|
int32_t NumExplicitSGPR = 0;
|
|
|
|
uint32_t PrivateSegmentSize = 0;
|
|
|
|
bool UsesVCC = false;
|
|
|
|
bool UsesFlatScratch = false;
|
|
|
|
bool HasDynamicallySizedStack = false;
|
|
|
|
bool HasRecursion = false;
|
|
|
|
|
|
|
|
int32_t getTotalNumSGPRs(const SISubtarget &ST) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Track resource usage for kernels / entry functions.
|
2013-12-05 13:15:35 +08:00
|
|
|
struct SIProgramInfo {
|
2014-06-27 01:22:30 +08:00
|
|
|
// Fields set in PGM_RSRC1 pm4 packet.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint32_t VGPRBlocks = 0;
|
|
|
|
uint32_t SGPRBlocks = 0;
|
|
|
|
uint32_t Priority = 0;
|
|
|
|
uint32_t FloatMode = 0;
|
|
|
|
uint32_t Priv = 0;
|
|
|
|
uint32_t DX10Clamp = 0;
|
|
|
|
uint32_t DebugMode = 0;
|
|
|
|
uint32_t IEEEMode = 0;
|
|
|
|
uint32_t ScratchSize = 0;
|
|
|
|
|
|
|
|
uint64_t ComputePGMRSrc1 = 0;
|
2014-12-03 05:28:53 +08:00
|
|
|
|
|
|
|
// Fields set in PGM_RSRC2 pm4 packet.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint32_t LDSBlocks = 0;
|
|
|
|
uint32_t ScratchBlocks = 0;
|
2014-12-03 05:28:53 +08:00
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
uint64_t ComputePGMRSrc2 = 0;
|
2014-12-03 05:28:53 +08:00
|
|
|
|
2017-01-21 01:52:16 +08:00
|
|
|
uint32_t NumVGPR = 0;
|
|
|
|
uint32_t NumSGPR = 0;
|
2017-04-18 03:48:30 +08:00
|
|
|
uint32_t LDSSize = 0;
|
2017-01-21 01:52:16 +08:00
|
|
|
bool FlatUsed = false;
|
2014-09-15 23:41:53 +08:00
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
// Number of SGPRs that meets number of waves per execution unit request.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint32_t NumSGPRsForWavesPerEU = 0;
|
2016-09-07 04:22:28 +08:00
|
|
|
|
|
|
|
// Number of VGPRs that meets number of waves per execution unit request.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint32_t NumVGPRsForWavesPerEU = 0;
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2016-04-27 01:24:40 +08:00
|
|
|
// If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
|
|
|
|
// fixed VGPR number reserved.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint16_t ReservedVGPRFirst = 0;
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2016-04-27 01:24:40 +08:00
|
|
|
// The number of consecutive VGPRs reserved.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint16_t ReservedVGPRCount = 0;
|
2016-04-26 23:43:14 +08:00
|
|
|
|
2016-06-25 11:11:28 +08:00
|
|
|
// Fixed SGPR number used to hold wave scratch offset for entire kernel
|
2017-01-24 07:41:16 +08:00
|
|
|
// execution, or std::numeric_limits<uint16_t>::max() if the register is not
|
|
|
|
// used or not known.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR =
|
|
|
|
std::numeric_limits<uint16_t>::max();
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2016-06-25 11:11:28 +08:00
|
|
|
// Fixed SGPR number of the first 4 SGPRs used to hold scratch V# for entire
|
2017-01-24 07:41:16 +08:00
|
|
|
// kernel execution, or std::numeric_limits<uint16_t>::max() if the register
|
|
|
|
// is not used or not known.
|
2017-01-21 01:52:16 +08:00
|
|
|
uint16_t DebuggerPrivateSegmentBufferSGPR =
|
|
|
|
std::numeric_limits<uint16_t>::max();
|
2016-06-25 11:11:28 +08:00
|
|
|
|
2017-05-03 01:14:00 +08:00
|
|
|
// Whether there is recursion, dynamic allocas, indirect calls or some other
|
|
|
|
// reason there may be statically unknown stack usage.
|
|
|
|
bool DynamicCallStack = false;
|
|
|
|
|
2014-06-27 01:22:30 +08:00
|
|
|
// Bonus information for debugging.
|
2017-01-21 01:52:16 +08:00
|
|
|
bool VCCUsed = false;
|
|
|
|
|
|
|
|
SIProgramInfo() = default;
|
2013-12-05 13:15:35 +08:00
|
|
|
};
|
|
|
|
|
2017-05-03 01:14:00 +08:00
|
|
|
SIProgramInfo CurrentProgramInfo;
|
|
|
|
DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// \brief Emit register usage information so that the GPU driver
|
|
|
|
/// can correctly setup the GPU state.
|
2014-07-13 11:06:43 +08:00
|
|
|
void EmitProgramInfoR600(const MachineFunction &MF);
|
|
|
|
void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
|
2017-05-03 01:14:00 +08:00
|
|
|
void emitCommonFunctionComments(uint32_t NumVGPR,
|
|
|
|
uint32_t NumSGPR,
|
|
|
|
uint32_t ScratchSize,
|
|
|
|
uint64_t CodeSize);
|
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
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
const MCSubtargetInfo* getSTI() const;
|
|
|
|
|
|
|
|
AMDGPUTargetStreamer& getTargetStreamer() const;
|
|
|
|
|
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;
|
|
|
|
|
2016-10-07 01:19:11 +08:00
|
|
|
/// \brief Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
|
|
|
|
/// pseudo lowering.
|
|
|
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
|
|
|
|
|
2017-02-07 08:43:21 +08:00
|
|
|
/// \brief Lower the specified LLVM Constant to an MCExpr.
|
|
|
|
/// 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;
|
|
|
|
|
2016-10-07 01:19:11 +08:00
|
|
|
/// \brief tblgen'erated driver function for lowering simple MI->MC pseudo
|
|
|
|
/// 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;
|
|
|
|
|
2015-11-06 19:45:14 +08:00
|
|
|
void EmitFunctionEntryLabel() override;
|
|
|
|
|
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,
|
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2015-04-08 10:07:05 +08:00
|
|
|
raw_ostream &O) override;
|
2015-04-08 09:09:26 +08:00
|
|
|
|
2013-10-12 13:02:51 +08:00
|
|
|
protected:
|
|
|
|
std::vector<std::string> DisasmLines, HexLines;
|
|
|
|
size_t DisasmLineMaxLen;
|
2017-03-27 22:04:01 +08:00
|
|
|
AMDGPUAS AMDGPUASI;
|
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
|