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 
30   SystemZTargetStreamer *getTargetStreamer() {
31     MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
32     assert(TS && "do not have a target streamer");
33     return static_cast<SystemZTargetStreamer *>(TS);
34   }
35 
36   /// Call type information for XPLINK.
37   enum class CallType {
38     BASR76 = 0,   // b'x000' == BASR  r7,r6
39     BRAS7 = 1,    // b'x001' == BRAS  r7,ep
40     RESVD_2 = 2,  // b'x010'
41     BRASL7 = 3,   // b'x011' == BRASL r7,ep
42     RESVD_4 = 4,  // b'x100'
43     RESVD_5 = 5,  // b'x101'
44     BALR1415 = 6, // b'x110' == BALR  r14,r15
45     BASR33 = 7,   // b'x111' == BASR  r3,r3
46   };
47 
48 public:
49   SystemZAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
50       : AsmPrinter(TM, std::move(Streamer)), SM(*this) {}
51 
52   // Override AsmPrinter.
53   StringRef getPassName() const override { return "SystemZ Assembly Printer"; }
54   void emitInstruction(const MachineInstr *MI) override;
55   void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
56   void emitEndOfAsmFile(Module &M) override;
57   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
58                        const char *ExtraCode, raw_ostream &OS) override;
59   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
60                              const char *ExtraCode, raw_ostream &OS) override;
61 
62   bool doInitialization(Module &M) override {
63     SM.reset();
64     return AsmPrinter::doInitialization(M);
65   }
66   void emitFunctionEntryLabel() override;
67 
68 private:
69   void emitCallInformation(CallType CT);
70   void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL);
71   void LowerSTACKMAP(const MachineInstr &MI);
72   void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower);
73 };
74 } // end namespace llvm
75 
76 #endif
77