Add gfx950 mfma instructions to ROCDL dialect (#123361)
[llvm-project.git] / llvm / lib / Target / SystemZ / SystemZAsmPrinter.h
blob2696702b44551d1dcca105b7df32ead5a9764620
1 //===-- SystemZAsmPrinter.h - SystemZ LLVM assembly printer ----*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H
10 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H
12 #include "SystemZMCInstLower.h"
13 #include "SystemZTargetMachine.h"
14 #include "SystemZTargetStreamer.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/CodeGen/StackMaps.h"
17 #include "llvm/MC/MCInstBuilder.h"
18 #include "llvm/Support/Compiler.h"
20 namespace llvm {
21 class MCStreamer;
22 class MachineInstr;
23 class Module;
24 class raw_ostream;
26 class LLVM_LIBRARY_VISIBILITY SystemZAsmPrinter : public AsmPrinter {
27 private:
28 MCSymbol *CurrentFnPPA1Sym; // PPA1 Symbol.
29 MCSymbol *CurrentFnEPMarkerSym; // Entry Point Marker.
30 MCSymbol *PPA2Sym;
32 SystemZTargetStreamer *getTargetStreamer() {
33 MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
34 assert(TS && "do not have a target streamer");
35 return static_cast<SystemZTargetStreamer *>(TS);
38 /// Call type information for XPLINK.
39 enum class CallType {
40 BASR76 = 0, // b'x000' == BASR r7,r6
41 BRAS7 = 1, // b'x001' == BRAS r7,ep
42 RESVD_2 = 2, // b'x010'
43 BRASL7 = 3, // b'x011' == BRASL r7,ep
44 RESVD_4 = 4, // b'x100'
45 RESVD_5 = 5, // b'x101'
46 BALR1415 = 6, // b'x110' == BALR r14,r15
47 BASR33 = 7, // b'x111' == BASR r3,r3
50 // The Associated Data Area (ADA) contains descriptors which help locating
51 // external symbols. For each symbol and type, the displacement into the ADA
52 // is stored.
53 class AssociatedDataAreaTable {
54 public:
55 using DisplacementTable =
56 MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>;
58 private:
59 const uint64_t PointerSize;
61 /// The mapping of name/slot type pairs to displacements.
62 DisplacementTable Displacements;
64 /// The next available displacement value. Incremented when new entries into
65 /// the ADA are created.
66 uint32_t NextDisplacement = 0;
68 public:
69 AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}
71 /// @brief Add a function descriptor to the ADA.
72 /// @param MI Pointer to an ADA_ENTRY instruction.
73 /// @return The displacement of the descriptor into the ADA.
74 uint32_t insert(const MachineOperand MO);
76 /// @brief Get the displacement into associated data area (ADA) for a name.
77 /// If no displacement is already associated with the name, assign one and
78 /// return it.
79 /// @param Sym The symbol for which the displacement should be returned.
80 /// @param SlotKind The ADA type.
81 /// @return The displacement of the descriptor into the ADA.
82 uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);
84 /// Get the table of GOFF displacements. This is 'const' since it should
85 /// never be modified by anything except the APIs on this class.
86 const DisplacementTable &getTable() const { return Displacements; }
88 uint32_t getNextDisplacement() const { return NextDisplacement; }
91 AssociatedDataAreaTable ADATable;
93 void emitPPA1(MCSymbol *FnEndSym);
94 void emitPPA2(Module &M);
95 void emitADASection();
96 void emitIDRLSection(Module &M);
98 public:
99 SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
100 : AsmPrinter(TM, std::move(Streamer)), CurrentFnPPA1Sym(nullptr),
101 CurrentFnEPMarkerSym(nullptr), PPA2Sym(nullptr),
102 ADATable(TM.getPointerSize(0)) {}
104 // Override AsmPrinter.
105 StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
106 void emitInstruction(const MachineInstr *MI) override;
107 void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
108 void emitEndOfAsmFile(Module &M) override;
109 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
110 const char *ExtraCode, raw_ostream &OS) override;
111 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
112 const char *ExtraCode, raw_ostream &OS) override;
114 bool runOnMachineFunction(MachineFunction &MF) override {
115 AsmPrinter::runOnMachineFunction(MF);
117 // Emit the XRay table for this function.
118 emitXRayTable();
120 return false;
123 bool doInitialization(Module &M) override {
124 SM.reset();
125 return AsmPrinter::doInitialization(M);
127 void emitFunctionEntryLabel() override;
128 void emitFunctionBodyEnd() override;
129 void emitStartOfAsmFile(Module &M) override;
131 private:
132 void emitCallInformation(CallType CT);
133 void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
134 void LowerSTACKMAP(const MachineInstr &MI);
135 void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
136 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
137 SystemZMCInstLower &Lower);
138 void LowerPATCHABLE_RET(const MachineInstr &MI, SystemZMCInstLower &Lower);
139 void emitAttributes(Module &M);
141 } // end namespace llvm
143 #endif