1//===-- llvm/Target/AMDGPU/AMDGPUMIRFormatter.h -----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6// See https://llvm.org/LICENSE.txt for license information.
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8//
9//===----------------------------------------------------------------------===//
10//
11/// \file
12/// AMDGPU specific overrides of MIRFormatter.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_AMDGPUMIRFORMATTER_H
17#define LLVM_LIB_TARGET_AMDGPUMIRFORMATTER_H
18
19#include "Utils/AMDGPUBaseInfo.h"
20#include "llvm/CodeGen/MIRFormatter.h"
21
22namespace llvm {
23
24class MachineFunction;
25struct PerFunctionMIParsingState;
26
27class AMDGPUMIRFormatter final : public MIRFormatter {
28public:
29 explicit AMDGPUMIRFormatter(const MCSubtargetInfo &STI) : STI(STI) {}
30 ~AMDGPUMIRFormatter() override = default;
31
32 /// Implement target specific printing for machine operand immediate value, so
33 /// that we can have more meaningful mnemonic than a 64-bit integer. Passing
34 /// None to OpIdx means the index is unknown.
35 void printImm(raw_ostream &OS, const MachineInstr &MI,
36 std::optional<unsigned> OpIdx, int64_t Imm) const override;
37
38 /// Implement target specific parsing of immediate mnemonics. The mnemonic is
39 /// a string with a leading dot.
40 bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
41 StringRef Src, int64_t &Imm,
42 ErrorCallbackType ErrorCallback) const override;
43
44 /// Implement target specific parsing of target custom pseudo source value.
45 bool
46 parseCustomPseudoSourceValue(StringRef Src, MachineFunction &MF,
47 PerFunctionMIParsingState &PFS,
48 const PseudoSourceValue *&PSV,
49 ErrorCallbackType ErrorCallback) const override;
50
51private:
52 const MCSubtargetInfo &STI;
53 /// Prints the string to represent s_wait_alu immediate value.
54 void printSWaitAluImm(uint64_t Imm, raw_ostream &OS) const;
55 /// Prints the string to represent s_waitcnt immediate value.
56 void printSWaitcntImm(uint64_t Imm, raw_ostream &OS) const;
57 /// Prints the string to represent s_wait_loadcnt_dscnt immediate value.
58 void printSWaitLoadcntDscntImm(uint64_t Imm, raw_ostream &OS) const;
59 /// Print the string to represent s_delay_alu immediate value
60 void printSDelayAluImm(int64_t Imm, llvm::raw_ostream &OS) const;
61
62 /// Parse the immediate pseudo literal for s_wait_alu
63 bool parseSWaitAluImmMnemonic(
64 const unsigned int OpIdx, int64_t &Imm, StringRef &Src,
65 MIRFormatter::ErrorCallbackType &ErrorCallback) const;
66
67 /// Parse the immediate pseudo literal for s_waitcnt
68 bool parseSWaitcntImmMnemonic(
69 const unsigned int OpIdx, int64_t &Imm, StringRef &Src,
70 MIRFormatter::ErrorCallbackType &ErrorCallback) const;
71
72 /// Parse the immediate pseudo literal for s_wait_loadcnt_dscnt
73 bool parseSWaitLoadcntDscntImmMnemonic(
74 const unsigned int OpIdx, int64_t &Imm, StringRef &Src,
75 MIRFormatter::ErrorCallbackType &ErrorCallback) const;
76
77 /// Parse the immediate pseudo literal for s_delay_alu
78 bool parseSDelayAluImmMnemonic(
79 const unsigned int OpIdx, int64_t &Imm, llvm::StringRef &Src,
80 llvm::MIRFormatter::ErrorCallbackType &ErrorCallback) const;
81
82};
83
84} // end namespace llvm
85
86#endif
87