xref: /llvm-project/llvm/include/llvm/CodeGen/AsmPrinterHandler.h (revision f6b0555a433cea1d32a6904c120516cd94b8f3db)
1 //===-- llvm/CodeGen/AsmPrinterHandler.h -----------------------*- 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 contains a generic interface for AsmPrinter handlers,
10 // like debug and EH info emitters.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_ASMPRINTERHANDLER_H
15 #define LLVM_CODEGEN_ASMPRINTERHANDLER_H
16 
17 #include "llvm/Support/DataTypes.h"
18 
19 namespace llvm {
20 
21 class AsmPrinter;
22 class MachineBasicBlock;
23 class MachineFunction;
24 class MachineInstr;
25 class MCSymbol;
26 class Module;
27 
28 typedef MCSymbol *ExceptionSymbolProvider(AsmPrinter *Asm,
29                                           const MachineBasicBlock *MBB);
30 
31 /// Collects and handles AsmPrinter objects required to build debug
32 /// or EH information.
33 class AsmPrinterHandler {
34 public:
35   virtual ~AsmPrinterHandler();
36 
37   virtual void beginModule(Module *M) {}
38 
39   /// Emit all sections that should come after the content.
40   virtual void endModule() = 0;
41 
42   /// Gather pre-function debug information.
43   /// Every beginFunction(MF) call should be followed by an endFunction(MF)
44   /// call.
45   virtual void beginFunction(const MachineFunction *MF) = 0;
46 
47   // Emit any of function marker (like .cfi_endproc). This is called
48   // before endFunction and cannot switch sections.
49   virtual void markFunctionEnd();
50 
51   /// Gather post-function debug information.
52   virtual void endFunction(const MachineFunction *MF) = 0;
53 
54   /// Process the beginning of a new basic-block-section within a
55   /// function. Always called immediately after beginFunction for the first
56   /// basic-block. When basic-block-sections are enabled, called before the
57   /// first block of each such section.
58   virtual void beginBasicBlockSection(const MachineBasicBlock &MBB) {}
59 
60   /// Process the end of a basic-block-section within a function. When
61   /// basic-block-sections are enabled, called after the last block in each such
62   /// section (including the last section in the function). When
63   /// basic-block-sections are disabled, called at the end of a function,
64   /// immediately prior to markFunctionEnd.
65   virtual void endBasicBlockSection(const MachineBasicBlock &MBB) {}
66 
67   /// For symbols that have a size designated (e.g. common symbols),
68   /// this tracks that size.
69   virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
70 
71   /// Process beginning of an instruction.
72   virtual void beginInstruction(const MachineInstr *MI) {}
73 
74   /// Process end of an instruction.
75   virtual void endInstruction() {}
76 
77   virtual void beginCodeAlignment(const MachineBasicBlock &MBB) {}
78 
79   /// Emit target-specific EH funclet machinery.
80   virtual void beginFunclet(const MachineBasicBlock &MBB,
81                             MCSymbol *Sym = nullptr) {}
82   virtual void endFunclet() {}
83 };
84 
85 } // End of namespace llvm
86 
87 #endif
88