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 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 =
56 MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>;
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 // Record a list of GlobalAlias associated with a GlobalObject.
94 // This is used for z/OS's extra-label-at-definition aliasing strategy.
95 // This is similar to what is done for AIX.
96 DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>>
97 GOAliasMap;
98
99 void calculatePPA1();
100 void emitPPA2(Module &M);
101 void emitADASection();
102 void emitIDRLSection(Module &M);
103
104public:
105 SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
106 : AsmPrinter(TM, std::move(Streamer), ID),
107 ADATable(TM.getPointerSize(0)) {}
108
109 // Override AsmPrinter.
110 StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
111 void emitInstruction(const MachineInstr *MI) override;
112 void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
113 void emitXXStructorList(const DataLayout &DL, const Constant *List,
114 bool IsCtor) override;
115 void emitEndOfAsmFile(Module &M) override;
116 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
117 const char *ExtraCode, raw_ostream &OS) override;
118 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
119 const char *ExtraCode, raw_ostream &OS) override;
120
123
124 // Emit the XRay table for this function.
126
127 return false;
128 }
129
130 bool doInitialization(Module &M) override;
131 void emitFunctionEntryLabel() override;
132 void emitFunctionBodyEnd() override;
133 void emitStartOfAsmFile(Module &M) override;
134 void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
135 const MCExpr *lowerConstant(const Constant *CV,
136 const Constant *BaseCV = nullptr,
137 uint64_t Offset = 0) override;
138
139private:
140 void emitCallInformation(CallType CT);
141 void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
142 void LowerSTACKMAP(const MachineInstr &MI);
143 void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
144 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
146 void LowerPATCHABLE_RET(const MachineInstr &MI, SystemZMCInstLower &Lower);
147 void lowerLOAD_TLS_BLOCK_ADDR(const MachineInstr &MI,
149 void lowerLOAD_GLOBAL_STACKGUARD_ADDR(const MachineInstr &MI,
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:453
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
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:573
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:860