xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonAsmPrinter.h (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1 //===- HexagonAsmPrinter.h - Print machine code -----------------*- 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 // Hexagon Assembly printer class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONASMPRINTER_H
14 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONASMPRINTER_H
15 
16 #include "HexagonSubtarget.h"
17 #include "llvm/CodeGen/AsmPrinter.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include <utility>
21 
22 namespace llvm {
23 
24 class MachineInstr;
25 class MCInst;
26 class raw_ostream;
27 class TargetMachine;
28 
29   class HexagonAsmPrinter : public AsmPrinter {
30     const HexagonSubtarget *Subtarget = nullptr;
31 
32   public:
33     explicit HexagonAsmPrinter(TargetMachine &TM,
34                                std::unique_ptr<MCStreamer> Streamer)
35       : AsmPrinter(TM, std::move(Streamer)) {}
36 
37     bool runOnMachineFunction(MachineFunction &Fn) override {
38       Subtarget = &Fn.getSubtarget<HexagonSubtarget>();
39       const bool Modified = AsmPrinter::runOnMachineFunction(Fn);
40       // Emit the XRay table for this function.
41       emitXRayTable();
42 
43       return Modified;
44     }
45 
46     StringRef getPassName() const override {
47       return "Hexagon Assembly Printer";
48     }
49 
50     bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB)
51           const override;
52 
53     void emitInstruction(const MachineInstr *MI) override;
54 
55     //===------------------------------------------------------------------===//
56     // XRay implementation
57     //===------------------------------------------------------------------===//
58     // XRay-specific lowering for Hexagon.
59     void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
60     void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
61     void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
62     void EmitSled(const MachineInstr &MI, SledKind Kind);
63 
64     void HexagonProcessInstruction(MCInst &Inst, const MachineInstr &MBB);
65 
66     void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
67     bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
68                          const char *ExtraCode, raw_ostream &OS) override;
69     bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
70                                const char *ExtraCode, raw_ostream &OS) override;
71   };
72 
73 } // end namespace llvm
74 
75 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONASMPRINTER_H
76