LLVM 20.0.0git
SystemZAsmPrinter.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H
10#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H
11
12#include "SystemZMCInstLower.h"
19
20namespace llvm {
21class MCStreamer;
22class MachineInstr;
23class Module;
24class raw_ostream;
25
27private:
28 MCSymbol *CurrentFnPPA1Sym; // PPA1 Symbol.
29 MCSymbol *CurrentFnEPMarkerSym; // Entry Point Marker.
30 MCSymbol *PPA2Sym;
31
32 SystemZTargetStreamer *getTargetStreamer() {
33 MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
34 assert(TS && "do not have a target streamer");
35 return static_cast<SystemZTargetStreamer *>(TS);
36 }
37
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
48 };
49
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 =
57
58 private:
59 const uint64_t PointerSize;
60
61 /// The mapping of name/slot type pairs to displacements.
62 DisplacementTable Displacements;
63
64 /// The next available displacement value. Incremented when new entries into
65 /// the ADA are created.
66 uint32_t NextDisplacement = 0;
67
68 public:
69 AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}
70
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);
75
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);
83
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; }
87
88 uint32_t getNextDisplacement() const { return NextDisplacement; }
89 };
90
91 AssociatedDataAreaTable ADATable;
92
93 void emitPPA1(MCSymbol *FnEndSym);
94 void emitPPA2(Module &M);
95 void emitADASection();
96 void emitIDRLSection(Module &M);
97
98public:
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)) {}
103
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;
113
114 bool doInitialization(Module &M) override {
115 SM.reset();
116 return AsmPrinter::doInitialization(M);
117 }
118 void emitFunctionEntryLabel() override;
119 void emitFunctionBodyEnd() override;
120 void emitStartOfAsmFile(Module &M) override;
121
122private:
123 void emitCallInformation(CallType CT);
124 void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
125 void LowerSTACKMAP(const MachineInstr &MI);
126 void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
127 void emitAttributes(Module &M);
128};
129} // end namespace llvm
130
131#endif
#define LLVM_LIBRARY_VISIBILITY
Definition: Compiler.h:131
static std::optional< TypeSize > getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
Symbol * Sym
Definition: ELF_riscv.cpp:479
IRTranslator LLVM IR MI
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Target specific streamer interface.
Definition: MCStreamer.h:94
Abstract base class for all machine specific constantpool value subclasses.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858