Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
35269 views
//===-- SystemZAsmPrinter.h - SystemZ LLVM assembly printer ----*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H9#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZASMPRINTER_H1011#include "SystemZMCInstLower.h"12#include "SystemZTargetMachine.h"13#include "SystemZTargetStreamer.h"14#include "llvm/CodeGen/AsmPrinter.h"15#include "llvm/CodeGen/StackMaps.h"16#include "llvm/MC/MCInstBuilder.h"17#include "llvm/Support/Compiler.h"1819namespace llvm {20class MCStreamer;21class MachineInstr;22class Module;23class raw_ostream;2425class LLVM_LIBRARY_VISIBILITY SystemZAsmPrinter : public AsmPrinter {26private:27MCSymbol *CurrentFnPPA1Sym; // PPA1 Symbol.28MCSymbol *CurrentFnEPMarkerSym; // Entry Point Marker.29MCSymbol *PPA2Sym;3031SystemZTargetStreamer *getTargetStreamer() {32MCTargetStreamer *TS = OutStreamer->getTargetStreamer();33assert(TS && "do not have a target streamer");34return static_cast<SystemZTargetStreamer *>(TS);35}3637/// Call type information for XPLINK.38enum class CallType {39BASR76 = 0, // b'x000' == BASR r7,r640BRAS7 = 1, // b'x001' == BRAS r7,ep41RESVD_2 = 2, // b'x010'42BRASL7 = 3, // b'x011' == BRASL r7,ep43RESVD_4 = 4, // b'x100'44RESVD_5 = 5, // b'x101'45BALR1415 = 6, // b'x110' == BALR r14,r1546BASR33 = 7, // b'x111' == BASR r3,r347};4849// The Associated Data Area (ADA) contains descriptors which help locating50// external symbols. For each symbol and type, the displacement into the ADA51// is stored.52class AssociatedDataAreaTable {53public:54using DisplacementTable =55MapVector<std::pair<const MCSymbol *, unsigned>, uint32_t>;5657private:58const uint64_t PointerSize;5960/// The mapping of name/slot type pairs to displacements.61DisplacementTable Displacements;6263/// The next available displacement value. Incremented when new entries into64/// the ADA are created.65uint32_t NextDisplacement = 0;6667public:68AssociatedDataAreaTable(uint64_t PointerSize) : PointerSize(PointerSize) {}6970/// @brief Add a function descriptor to the ADA.71/// @param MI Pointer to an ADA_ENTRY instruction.72/// @return The displacement of the descriptor into the ADA.73uint32_t insert(const MachineOperand MO);7475/// @brief Get the displacement into associated data area (ADA) for a name.76/// If no displacement is already associated with the name, assign one and77/// return it.78/// @param Sym The symbol for which the displacement should be returned.79/// @param SlotKind The ADA type.80/// @return The displacement of the descriptor into the ADA.81uint32_t insert(const MCSymbol *Sym, unsigned SlotKind);8283/// Get the table of GOFF displacements. This is 'const' since it should84/// never be modified by anything except the APIs on this class.85const DisplacementTable &getTable() const { return Displacements; }8687uint32_t getNextDisplacement() const { return NextDisplacement; }88};8990AssociatedDataAreaTable ADATable;9192void emitPPA1(MCSymbol *FnEndSym);93void emitPPA2(Module &M);94void emitADASection();95void emitIDRLSection(Module &M);9697public:98SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)99: AsmPrinter(TM, std::move(Streamer)), CurrentFnPPA1Sym(nullptr),100CurrentFnEPMarkerSym(nullptr), PPA2Sym(nullptr),101ADATable(TM.getPointerSize(0)) {}102103// Override AsmPrinter.104StringRef getPassName() const override { return "SystemZ Assembly Printer"; }105void emitInstruction(const MachineInstr *MI) override;106void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;107void emitEndOfAsmFile(Module &M) override;108bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,109const char *ExtraCode, raw_ostream &OS) override;110bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,111const char *ExtraCode, raw_ostream &OS) override;112113bool doInitialization(Module &M) override {114SM.reset();115return AsmPrinter::doInitialization(M);116}117void emitFunctionEntryLabel() override;118void emitFunctionBodyEnd() override;119void emitStartOfAsmFile(Module &M) override;120121private:122void emitCallInformation(CallType CT);123void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);124void LowerSTACKMAP(const MachineInstr &MI);125void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);126void emitAttributes(Module &M);127};128} // end namespace llvm129130#endif131132133