LLVM 23.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
13#include "SystemZMCInstLower.h"
19
20namespace llvm {
21class MCStreamer;
22class MachineInstr;
23class Module;
24class raw_ostream;
25
27public:
28 static char ID;
29
30private:
31 MCSymbol *CurrentFnPPA1Sym; // PPA1 Symbol.
32 MCSymbol *CurrentFnEPMarkerSym; // Entry Point Marker.
33 MCSymbol *PPA2Sym;
34
35 SystemZTargetStreamer *getTargetStreamer() {
36 MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
37 assert(TS && "do not have a target streamer");
38 return static_cast<SystemZTargetStreamer *>(TS);
39 }
40
41 /// Call type information for XPLINK.
42 enum class CallType {
43 BASR76 = 0, // b'x000' == BASR r7,r6
44 BRAS7 = 1, // b'x001' == BRAS r7,ep
45 RESVD_2 = 2, // b'x010'
46 BRASL7 = 3, // b'x011' == BRASL r7,ep
47 RESVD_4 = 4, // b'x100'
48 RESVD_5 = 5, // b'x101'
49 BALR1415 = 6, // b'x110' == BALR r14,r15
50 BASR33 = 7, // b'x111' == BASR r3,r3
51 };
52
53 // The Associated Data Area (ADA) contains descriptors which help locating
54 // external symbols. For each symbol and type, the displacement into the ADA
55 // is stored.
56 class AssociatedDataAreaTable {
57 public:
58 using DisplacementTable =
59 MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>;
60
61 private:
62 const uint64_t PointerSize;
63
64 /// The mapping of name/slot type pairs to displacements.
65 DisplacementTable Displacements;
66
67 /// The next available displacement value. Incremented when new entries into
68 /// the ADA are created.
69 uint32_t NextDisplacement = 0;
70
71 public:
72 AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}
73
74 /// @brief Add a function descriptor to the ADA.
75 /// @param MI Pointer to an ADA_ENTRY instruction.
76 /// @return The displacement of the descriptor into the ADA.
77 uint32_t insert(const MachineOperand MO);
78
79 /// @brief Get the displacement into associated data area (ADA) for a name.
80 /// If no displacement is already associated with the name, assign one and
81 /// return it.
82 /// @param Sym The symbol for which the displacement should be returned.
83 /// @param SlotKind The ADA type.
84 /// @return The displacement of the descriptor into the ADA.
85 uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);
86
87 /// Get the table of GOFF displacements. This is 'const' since it should
88 /// never be modified by anything except the APIs on this class.
89 const DisplacementTable &getTable() const { return Displacements; }
90
91 uint32_t getNextDisplacement() const { return NextDisplacement; }
92 };
93
94 AssociatedDataAreaTable ADATable;
95
96 // Record a list of GlobalAlias associated with a GlobalObject.
97 // This is used for z/OS's extra-label-at-definition aliasing strategy.
98 // This is similar to what is done for AIX.
99 DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>>
100 GOAliasMap;
101
102 void emitPPA1(MCSymbol *FnEndSym);
103 void emitPPA2(Module &M);
104 void emitADASection();
105 void emitIDRLSection(Module &M);
106
107public:
108 SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
109 : AsmPrinter(TM, std::move(Streamer), ID), CurrentFnPPA1Sym(nullptr),
110 CurrentFnEPMarkerSym(nullptr), PPA2Sym(nullptr),
111 ADATable(TM.getPointerSize(0)) {}
112
113 // Override AsmPrinter.
114 StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
115 void emitInstruction(const MachineInstr *MI) override;
116 void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
117 void emitXXStructorList(const DataLayout &DL, const Constant *List,
118 bool IsCtor) override;
119 void emitEndOfAsmFile(Module &M) override;
120 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
121 const char *ExtraCode, raw_ostream &OS) override;
122 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
123 const char *ExtraCode, raw_ostream &OS) override;
124
127
128 // Emit the XRay table for this function.
130
131 return false;
132 }
133
134 bool doInitialization(Module &M) override;
135 void emitFunctionEntryLabel() override;
136 void emitFunctionBodyEnd() override;
137 void emitStartOfAsmFile(Module &M) override;
138 void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
139 const MCExpr *lowerConstant(const Constant *CV,
140 const Constant *BaseCV = nullptr,
141 uint64_t Offset = 0) override;
142
143private:
144 void emitCallInformation(CallType CT);
145 void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
146 void LowerSTACKMAP(const MachineInstr &MI);
147 void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
148 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
150 void LowerPATCHABLE_RET(const MachineInstr &MI, SystemZMCInstLower &Lower);
151 void emitAttributes(Module &M);
152};
153} // end namespace llvm
154
155#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
IRTranslator LLVM IR MI
Machine Check Debug Module
static SDValue lowerConstant(SDValue Op, SelectionDAG &DAG, const RISCVSubtarget &Subtarget)
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:94
void emitXRayTable()
Emit a table with all XRay instrumentation points.
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:458
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:106
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Streaming machine code generation interface.
Definition MCStreamer.h:221
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Target specific streamer interface.
Definition MCStreamer.h:94
Abstract base class for all machine specific constantpool value subclasses.
Representation of each machine instruction.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Primary interface to the complete machine description for the target machine.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
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:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870