| 1 | //=====-- NVPTXTargetStreamer.h - NVPTX Target Streamer ------*- 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_NVPTX_MCTARGETDESC_NVPTXTARGETSTREAMER_H |
| 10 | #define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXTARGETSTREAMER_H |
| 11 | |
| 12 | #include "llvm/MC/MCStreamer.h" |
| 13 | |
| 14 | namespace llvm { |
| 15 | class MCSection; |
| 16 | class formatted_raw_ostream; |
| 17 | |
| 18 | /// Implments NVPTX-specific streamer. |
| 19 | class NVPTXTargetStreamer : public MCTargetStreamer { |
| 20 | private: |
| 21 | SmallVector<std::string, 4> DwarfFiles; |
| 22 | bool HasSections = false; |
| 23 | |
| 24 | public: |
| 25 | NVPTXTargetStreamer(MCStreamer &S); |
| 26 | ~NVPTXTargetStreamer() override; |
| 27 | |
| 28 | /// Emit the banner which specifies details of PTX generator. |
| 29 | virtual void emitBanner() {} |
| 30 | |
| 31 | /// Emit the PTX ISA version number. |
| 32 | virtual void emitVersionDirective(unsigned PTXVersion) {} |
| 33 | |
| 34 | /// Emit architecture and platform target. |
| 35 | virtual void emitTargetDirective(StringRef Target, bool TexModeIndependent, |
| 36 | bool HasDebug) {} |
| 37 | |
| 38 | /// Emit address size used for this PTX module. |
| 39 | virtual void emitAddressSizeDirective(unsigned AddrSize) {} |
| 40 | |
| 41 | /// Outputs the list of the DWARF '.file' directives to the streamer. |
| 42 | void outputDwarfFileDirectives(); |
| 43 | /// Close last section. |
| 44 | void closeLastSection(); |
| 45 | |
| 46 | /// Record DWARF file directives for later output. |
| 47 | /// According to PTX ISA, CUDA Toolkit documentation, 11.5.3. Debugging |
| 48 | /// Directives: .file |
| 49 | /// (http://docs.nvidia.com/cuda/parallel-thread-execution/index.html#debugging-directives-file), |
| 50 | /// The .file directive is allowed only in the outermost scope, i.e., at the |
| 51 | /// same level as kernel and device function declarations. Also, the order of |
| 52 | /// the .loc and .file directive does not matter, .file directives may follow |
| 53 | /// the .loc directives where the file is referenced. |
| 54 | /// LLVM emits .file directives immediately the location debug info is |
| 55 | /// emitted, i.e. they may be emitted inside functions. We gather all these |
| 56 | /// directives and emit them outside of the sections and, thus, outside of the |
| 57 | /// functions. |
| 58 | void emitDwarfFileDirective(StringRef Directive) override; |
| 59 | void changeSection(const MCSection *CurSection, MCSection *Section, |
| 60 | uint32_t SubSection, raw_ostream &OS) override; |
| 61 | /// Emit the bytes in \p Data into the output. |
| 62 | /// |
| 63 | /// This is used to emit bytes in \p Data as sequence of .byte directives. |
| 64 | void emitRawBytes(StringRef Data) override; |
| 65 | /// Makes sure that labels are mangled the same way as the actual symbols. |
| 66 | void emitValue(const MCExpr *Value) override; |
| 67 | }; |
| 68 | |
| 69 | class NVPTXAsmTargetStreamer : public NVPTXTargetStreamer { |
| 70 | formatted_raw_ostream &OS; |
| 71 | |
| 72 | public: |
| 73 | NVPTXAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS); |
| 74 | ~NVPTXAsmTargetStreamer() override; |
| 75 | |
| 76 | void emitBanner() override; |
| 77 | |
| 78 | void emitVersionDirective(unsigned PTXVersion) override; |
| 79 | |
| 80 | void emitTargetDirective(StringRef Target, bool TexModeIndependent, |
| 81 | bool HasDebug) override; |
| 82 | |
| 83 | void emitAddressSizeDirective(unsigned AddrSize) override; |
| 84 | }; |
| 85 | |
| 86 | } // end namespace llvm |
| 87 | |
| 88 | #endif |
| 89 | |