AMDGPUAsmPrinter.h revision dce4a407a24b04eebc6a376f8e62b41aaa7b071f
1//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief AMDGPU Assembly printer class.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef AMDGPU_ASMPRINTER_H
16#define AMDGPU_ASMPRINTER_H
17
18#include "llvm/CodeGen/AsmPrinter.h"
19#include <string>
20#include <vector>
21
22namespace llvm {
23
24class AMDGPUAsmPrinter : public AsmPrinter {
25private:
26  struct SIProgramInfo {
27    SIProgramInfo() :
28      CodeLen(0),
29      NumSGPR(0),
30      NumVGPR(0) {}
31
32    uint64_t CodeLen;
33    unsigned NumSGPR;
34    unsigned NumVGPR;
35  };
36
37  void getSIProgramInfo(SIProgramInfo &Out, MachineFunction &MF) const;
38  void findNumUsedRegistersSI(MachineFunction &MF,
39                              unsigned &NumSGPR,
40                              unsigned &NumVGPR) const;
41
42  /// \brief Emit register usage information so that the GPU driver
43  /// can correctly setup the GPU state.
44  void EmitProgramInfoR600(MachineFunction &MF);
45  void EmitProgramInfoSI(MachineFunction &MF, const SIProgramInfo &KernelInfo);
46
47public:
48  explicit AMDGPUAsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
49
50  bool runOnMachineFunction(MachineFunction &MF) override;
51
52  const char *getPassName() const override {
53    return "AMDGPU Assembly Printer";
54  }
55
56  /// Implemented in AMDGPUMCInstLower.cpp
57  void EmitInstruction(const MachineInstr *MI) override;
58
59protected:
60  bool DisasmEnabled;
61  std::vector<std::string> DisasmLines, HexLines;
62  size_t DisasmLineMaxLen;
63};
64
65} // End anonymous llvm
66
67#endif //AMDGPU_ASMPRINTER_H
68