| 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 | |
| 18 | #include "MCTargetDesc/SystemZTargetStreamer.h" |
| 19 | #include "SystemZAsmPrinter.h" |
| 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/ADT/MapVector.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | class MCStreamer; |
| 25 | class MCSymbolGOFF; |
| 26 | class MachineInstr; |
| 27 | class Module; |
| 28 | class raw_ostream; |
| 29 | |
| 30 | class LLVM_LIBRARY_VISIBILITY SystemZXPLINKAsmPrinter |
| 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 = |
| 51 | MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>; |
| 52 | |
| 53 | private: |
| 54 | const uint64_t PointerSize; |
| 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 MI Pointer to an ADA_ENTRY instruction. |
| 68 | /// @return The displacement of the descriptor into the ADA. |
| 69 | uint32_t insert(const MachineOperand MO); |
| 70 | |
| 71 | /// @brief Get the displacement into associated data area (ADA) for a name. |
| 72 | /// If no displacement is already associated with the name, assign one and |
| 73 | /// return it. |
| 74 | /// @param Sym The symbol for which the displacement should be returned. |
| 75 | /// @param SlotKind The ADA type. |
| 76 | /// @return The displacement of the descriptor into the ADA. |
| 77 | uint32_t insert(const MCSymbol *Sym, unsigned SlotKind); |
| 78 | |
| 79 | /// Get the table of GOFF displacements. This is 'const' since it should |
| 80 | /// never be modified by anything except the APIs on this class. |
| 81 | const DisplacementTable &getTable() const { return Displacements; } |
| 82 | |
| 83 | uint32_t getNextDisplacement() const { return NextDisplacement; } |
| 84 | }; |
| 85 | |
| 86 | AssociatedDataAreaTable ADATable; |
| 87 | |
| 88 | // Record a list of GlobalAlias associated with a GlobalObject. |
| 89 | // This is used for z/OS's extra-label-at-definition aliasing strategy. |
| 90 | // This is similar to what is done for AIX. |
| 91 | DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>> |
| 92 | GOAliasMap; |
| 93 | |
| 94 | void calculatePPA1(); |
| 95 | void emitPPA2(Module &M); |
| 96 | void emitADASection(); |
| 97 | void emitIDRLSection(Module &M); |
| 98 | void emitCallInformation(CallType CT); |
| 99 | |
| 100 | SystemZTargetzOSStreamer *getTargetStreamer() { |
| 101 | MCTargetStreamer *TS = OutStreamer->getTargetStreamer(); |
| 102 | assert(TS && "do not have a target streamer" ); |
| 103 | return static_cast<SystemZTargetzOSStreamer *>(TS); |
| 104 | } |
| 105 | |
| 106 | public: |
| 107 | SystemZXPLINKAsmPrinter(TargetMachine &TM, |
| 108 | std::unique_ptr<MCStreamer> Streamer); |
| 109 | |
| 110 | // Override AsmPrinter. |
| 111 | void emitInstruction(const MachineInstr *MI) override; |
| 112 | void emitXXStructorList(const DataLayout &DL, const Constant *List, |
| 113 | bool IsCtor) override; |
| 114 | void emitEndOfAsmFile(Module &M) override; |
| 115 | bool doInitialization(Module &M) override; |
| 116 | void emitFunctionEntryLabel() override; |
| 117 | void emitFunctionBodyEnd() override; |
| 118 | void emitStartOfAsmFile(Module &M) override; |
| 119 | void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override; |
| 120 | const MCExpr *lowerConstant(const Constant *CV, |
| 121 | const Constant *BaseCV = nullptr, |
| 122 | uint64_t Offset = 0) override; |
| 123 | }; |
| 124 | |
| 125 | } // end namespace llvm |
| 126 | |
| 127 | #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZXPLINKASMPRINTER_H |
| 128 | |