LLVM 24.0.0git
SystemZXPLINKAsmPrinter.h
Go to the documentation of this file.
1//===-- SystemZXPLINKAsmPrinter.h - SystemZ XPLINK asm 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// This file declares the SystemZXPLINKAsmPrinter class, which owns all
10// z/OS XPLINK-specific asm printer behaviour: ADA table management, PPA1/PPA2,
11// IDRL, entry-point markers, and XPLINK call/return instruction lowering.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZXPLINKASMPRINTER_H
16#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZXPLINKASMPRINTER_H
17
19#include "SystemZAsmPrinter.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/MapVector.h"
22
23namespace llvm {
24class MCStreamer;
25class MachineFunction;
26class MachineInstr;
27class MachineOperand;
28class Module;
29
31 : public SystemZAsmPrinter {
32
33 /// Call type information for XPLINK.
34 enum class CallType {
35 BASR76 = 0, // b'x000' == BASR r7,r6
36 BRAS7 = 1, // b'x001' == BRAS r7,ep
37 RESVD_2 = 2, // b'x010'
38 BRASL7 = 3, // b'x011' == BRASL r7,ep
39 RESVD_4 = 4, // b'x100'
40 RESVD_5 = 5, // b'x101'
41 BALR1415 = 6, // b'x110' == BALR r14,r15
42 BASR33 = 7, // b'x111' == BASR r3,r3
43 };
44
45 // The Associated Data Area (ADA) contains descriptors which help locating
46 // external symbols. For each symbol and type, the displacement into the ADA
47 // is stored.
48 class AssociatedDataAreaTable {
49 public:
50 using DisplacementTable =
52
53 private:
55
56 /// The mapping of name/slot type pairs to displacements.
57 DisplacementTable Displacements;
58
59 /// The next available displacement value. Incremented when new entries into
60 /// the ADA are created.
61 uint32_t NextDisplacement = 0;
62
63 public:
64 AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}
65
66 /// @brief Add a function descriptor to the ADA.
67 /// @param MF The function containing the ADA_ENTRY instruction.
68 /// @param MO The operand describing the descriptor symbol.
69 /// @return The displacement of the descriptor into the ADA.
70 uint32_t insert(const MachineFunction &MF, const MachineOperand &MO);
71
72 /// @brief Get the displacement into associated data area (ADA) for a name.
73 /// If no displacement is already associated with the name, assign one and
74 /// return it.
75 /// @param Sym The symbol for which the displacement should be returned.
76 /// @param SlotKind The ADA type.
77 /// @return The displacement of the descriptor into the ADA.
78 uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);
79
80 /// Get the table of GOFF displacements. This is 'const' since it should
81 /// never be modified by anything except the APIs on this class.
82 const DisplacementTable &getTable() const { return Displacements; }
83
84 uint32_t getNextDisplacement() const { return NextDisplacement; }
85 };
86
87 AssociatedDataAreaTable ADATable;
88
89 // Record a list of GlobalAlias associated with a GlobalObject.
90 // This is used for z/OS's extra-label-at-definition aliasing strategy.
91 // This is similar to what is done for AIX.
93 GOAliasMap;
94
95 /// Entry of the stack restore stub. Created by the first stack restore of
96 /// the module; the stub is then emitted after the last function.
97 MCSymbol *StackRestoreStub = nullptr;
98
99 void calculatePPA1();
100 void emitPPA2(Module &M);
101 void emitADASection();
102 void emitIDRLSection(Module &M);
103 void emitCELQMAIN(const Function &MainFn);
104 void emitStackRestoreStub();
105 void emitCallInformation(CallType CT);
106
107 SystemZTargetzOSStreamer *getTargetStreamer() {
108 MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
109 assert(TS && "do not have a target streamer");
110 return static_cast<SystemZTargetzOSStreamer *>(TS);
111 }
112
113public:
115 std::unique_ptr<MCStreamer> Streamer);
116
117 // Override AsmPrinter.
118 void emitInstruction(const MachineInstr *MI) override;
119 void emitXXStructorList(const DataLayout &DL, const Constant *List,
120 bool IsCtor) override;
121 void emitEndOfAsmFile(Module &M) override;
122 bool doInitialization(Module &M) override;
123 bool doFinalization(Module &M) override;
124 void emitFunctionEntryLabel() override;
125 void emitFunctionBodyEnd() override;
126 void emitStartOfAsmFile(Module &M) override;
127 void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
128 const MCExpr *lowerConstant(const Constant *CV,
129 const Constant *BaseCV = nullptr,
130 uint64_t Offset = 0) override;
131};
132
133} // end namespace llvm
134
135#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZXPLINKASMPRINTER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
This file defines the DenseMap class.
IRTranslator LLVM IR MI
This file implements a map that provides insertion order iteration.
static SDValue lowerConstant(SDValue Op, SelectionDAG &DAG, const RISCVSubtarget &Subtarget)
std::unique_ptr< MCStreamer > && Streamer
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:96
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:111
unsigned PointerSize
The pointer size in bytes for the default address space.
Definition AsmPrinter.h:117
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:108
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
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
Representation of each machine instruction.
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:39
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
SystemZXPLINKAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool doFinalization(Module &M) override
Shut down the asmprinter.
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
void emitXXStructorList(const DataLayout &DL, const Constant *List, bool IsCtor) override
This method emits llvm.global_ctors or llvm.global_dtors list.
Primary interface to the complete machine description for the target machine.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577