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"
20
21namespace llvm {
22class MCStreamer;
23class MachineInstr;
24class Module;
25class raw_ostream;
26
28public:
29 static char ID;
30
31private:
32 MCSymbol *PPA2Sym;
33
34 SystemZTargetStreamer *getTargetStreamer() {
35 MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
36 assert(TS && "do not have a target streamer");
37 return static_cast<SystemZTargetStreamer *>(TS);
38 }
39
40 /// Call type information for XPLINK.
41 enum class CallType {
42 BASR76 = 0, // b'x000' == BASR r7,r6
43 BRAS7 = 1, // b'x001' == BRAS r7,ep
44 RESVD_2 = 2, // b'x010'
45 BRASL7 = 3, // b'x011' == BRASL r7,ep
46 RESVD_4 = 4, // b'x100'
47 RESVD_5 = 5, // b'x101'
48 BALR1415 = 6, // b'x110' == BALR r14,r15
49 BASR33 = 7, // b'x111' == BASR r3,r3
50 };
51
52 // The Associated Data Area (ADA) contains descriptors which help locating
53 // external symbols. For each symbol and type, the displacement into the ADA
54 // is stored.
55 class AssociatedDataAreaTable {
56 public:
57 using DisplacementTable =
58 MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>;
59
60 private:
61 const uint64_t PointerSize;
62
63 /// The mapping of name/slot type pairs to displacements.
64 DisplacementTable Displacements;
65
66 /// The next available displacement value. Incremented when new entries into
67 /// the ADA are created.
68 uint32_t NextDisplacement = 0;
69
70 public:
71 AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}
72
73 /// @brief Add a function descriptor to the ADA.
74 /// @param MI Pointer to an ADA_ENTRY instruction.
75 /// @return The displacement of the descriptor into the ADA.
76 uint32_t insert(const MachineOperand MO);
77
78 /// @brief Get the displacement into associated data area (ADA) for a name.
79 /// If no displacement is already associated with the name, assign one and
80 /// return it.
81 /// @param Sym The symbol for which the displacement should be returned.
82 /// @param SlotKind The ADA type.
83 /// @return The displacement of the descriptor into the ADA.
84 uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);
85
86 /// Get the table of GOFF displacements. This is 'const' since it should
87 /// never be modified by anything except the APIs on this class.
88 const DisplacementTable &getTable() const { return Displacements; }
89
90 uint32_t getNextDisplacement() const { return NextDisplacement; }
91 };
92
93 AssociatedDataAreaTable ADATable;
94
95 // Record a list of GlobalAlias associated with a GlobalObject.
96 // This is used for z/OS's extra-label-at-definition aliasing strategy.
97 // This is similar to what is done for AIX.
98 DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>>
99 GOAliasMap;
100
101 struct PPA1Info {
102 StringRef Name;
103 MCSymbol *FnEnd = nullptr; // Symbol marking function end.
104 MCSymbol *PPA1 = nullptr; // Symbol marking PPA1 begin.
105 MCSymbol *EPMarker = nullptr; // Symbol marking entry point.
106 MCSymbol *PersonalityRoutine = nullptr;
107 MCSymbol *GCCEH = nullptr;
108 int64_t OffsetFPR = 0;
109 int64_t OffsetVR = 0;
110 uint64_t CallFrameSize = 0;
111 unsigned SizeOfFnParams = 0;
112 uint32_t FrameAndFPROffset;
113 uint32_t FrameAndVROffset;
114 uint16_t SavedGPRMask = 0;
115 uint16_t SavedFPRMask = 0;
116 uint8_t SavedVRMask = 0;
117 uint8_t FrameReg = 0;
118 uint8_t AllocaReg = 0;
119 bool IsVarArg = false;
120 bool HasStackProtector = false;
121 };
122 SmallVector<PPA1Info, 0> DeferredPPA1;
123
124 void calculatePPA1();
125 void emitPPA1(PPA1Info &Info);
126 void emitPPA2(Module &M);
127 void emitADASection();
128 void emitIDRLSection(Module &M);
129
130public:
131 SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
132 : AsmPrinter(TM, std::move(Streamer), ID), PPA2Sym(nullptr),
133 ADATable(TM.getPointerSize(0)) {}
134
135 // Override AsmPrinter.
136 StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
137 void emitInstruction(const MachineInstr *MI) override;
138 void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
139 void emitXXStructorList(const DataLayout &DL, const Constant *List,
140 bool IsCtor) override;
141 void emitEndOfAsmFile(Module &M) override;
142 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
143 const char *ExtraCode, raw_ostream &OS) override;
144 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
145 const char *ExtraCode, raw_ostream &OS) override;
146
149
150 // Emit the XRay table for this function.
152
153 return false;
154 }
155
156 bool doInitialization(Module &M) override;
157 void emitFunctionEntryLabel() override;
158 void emitFunctionBodyEnd() override;
159 void emitStartOfAsmFile(Module &M) override;
160 void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
161 const MCExpr *lowerConstant(const Constant *CV,
162 const Constant *BaseCV = nullptr,
163 uint64_t Offset = 0) override;
164
165private:
166 void emitCallInformation(CallType CT);
167 void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
168 void LowerSTACKMAP(const MachineInstr &MI);
169 void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
170 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
172 void LowerPATCHABLE_RET(const MachineInstr &MI, SystemZMCInstLower &Lower);
173 void emitAttributes(Module &M);
174};
175} // end namespace llvm
176
177#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:456
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:222
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:95
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.
@ 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