xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 
12 #include "SystemZMCInstLower.h"
13 #include "SystemZTargetMachine.h"
14 #include "SystemZTargetStreamer.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/CodeGen/StackMaps.h"
17 #include "llvm/MC/MCInstBuilder.h"
18 #include "llvm/Support/Compiler.h"
19 
20 namespace llvm {
21 class MCStreamer;
22 class MachineInstr;
23 class Module;
24 class raw_ostream;
25 
26 class LLVM_LIBRARY_VISIBILITY SystemZAsmPrinter : public AsmPrinter {
27 private:
28   StackMaps SM;
29   MCSymbol *CurrentFnPPA1Sym;     // PPA1 Symbol.
30   MCSymbol *CurrentFnEPMarkerSym; // Entry Point Marker.
31 
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   void emitPPA1(MCSymbol *FnEndSym);
51 
52 public:
53   SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
54       : AsmPrinter(TM, std::move(Streamer)), SM(*this),
55         CurrentFnPPA1Sym(nullptr), CurrentFnEPMarkerSym(nullptr) {}
56 
57   // Override AsmPrinter.
58   StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
59   void emitInstruction(const MachineInstr *MI) override;
60   void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
61   void emitEndOfAsmFile(Module &M) override;
62   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
63                        const char *ExtraCode, raw_ostream &OS) override;
64   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
65                              const char *ExtraCode, raw_ostream &OS) override;
66 
67   bool doInitialization(Module &M) override {
68     SM.reset();
69     return AsmPrinter::doInitialization(M);
70   }
71   void emitFunctionEntryLabel() override;
72   void emitFunctionBodyEnd() override;
73 
74 private:
75   void emitCallInformation(CallType CT);
76   void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
77   void LowerSTACKMAP(const MachineInstr &MI);
78   void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
79 };
80 } // end namespace llvm
81 
82 #endif
83