1 //===-- AArch64TargetStreamer.h - AArch64 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_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H 10 #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64TARGETSTREAMER_H 11 12 #include "llvm/MC/MCStreamer.h" 13 14 namespace { 15 class AArch64ELFStreamer; 16 } 17 18 namespace llvm { 19 20 class AArch64TargetStreamer : public MCTargetStreamer { 21 public: 22 AArch64TargetStreamer(MCStreamer &S); 23 ~AArch64TargetStreamer() override; 24 25 void finish() override; 26 27 /// Callback used to implement the ldr= pseudo. 28 /// Add a new entry to the constant pool for the current section and return an 29 /// MCExpr that can be used to refer to the constant pool location. 30 const MCExpr *addConstantPoolEntry(const MCExpr *, unsigned Size, SMLoc Loc); 31 32 /// Callback used to implemnt the .ltorg directive. 33 /// Emit contents of constant pool for the current section. 34 void emitCurrentConstantPool(); 35 36 /// Callback used to implement the .note.gnu.property section. 37 void emitNoteSection(unsigned Flags); 38 39 /// Callback used to implement the .inst directive. 40 virtual void emitInst(uint32_t Inst); 41 42 /// Callback used to implement the .variant_pcs directive. 43 virtual void emitDirectiveVariantPCS(MCSymbol *Symbol) {}; 44 45 virtual void emitARM64WinCFIAllocStack(unsigned Size) {} 46 virtual void emitARM64WinCFISaveR19R20X(int Offset) {} 47 virtual void emitARM64WinCFISaveFPLR(int Offset) {} 48 virtual void emitARM64WinCFISaveFPLRX(int Offset) {} 49 virtual void emitARM64WinCFISaveReg(unsigned Reg, int Offset) {} 50 virtual void emitARM64WinCFISaveRegX(unsigned Reg, int Offset) {} 51 virtual void emitARM64WinCFISaveRegP(unsigned Reg, int Offset) {} 52 virtual void emitARM64WinCFISaveRegPX(unsigned Reg, int Offset) {} 53 virtual void emitARM64WinCFISaveLRPair(unsigned Reg, int Offset) {} 54 virtual void emitARM64WinCFISaveFReg(unsigned Reg, int Offset) {} 55 virtual void emitARM64WinCFISaveFRegX(unsigned Reg, int Offset) {} 56 virtual void emitARM64WinCFISaveFRegP(unsigned Reg, int Offset) {} 57 virtual void emitARM64WinCFISaveFRegPX(unsigned Reg, int Offset) {} 58 virtual void emitARM64WinCFISetFP() {} 59 virtual void emitARM64WinCFIAddFP(unsigned Size) {} 60 virtual void emitARM64WinCFINop() {} 61 virtual void emitARM64WinCFISaveNext() {} 62 virtual void emitARM64WinCFIPrologEnd() {} 63 virtual void emitARM64WinCFIEpilogStart() {} 64 virtual void emitARM64WinCFIEpilogEnd() {} 65 virtual void emitARM64WinCFITrapFrame() {} 66 virtual void emitARM64WinCFIMachineFrame() {} 67 virtual void emitARM64WinCFIContext() {} 68 virtual void emitARM64WinCFIClearUnwoundToCall() {} 69 70 private: 71 std::unique_ptr<AssemblerConstantPools> ConstantPools; 72 }; 73 74 class AArch64TargetELFStreamer : public AArch64TargetStreamer { 75 private: 76 AArch64ELFStreamer &getStreamer(); 77 78 void emitInst(uint32_t Inst) override; 79 void emitDirectiveVariantPCS(MCSymbol *Symbol) override; 80 81 public: 82 AArch64TargetELFStreamer(MCStreamer &S) : AArch64TargetStreamer(S) {} 83 }; 84 85 class AArch64TargetWinCOFFStreamer : public llvm::AArch64TargetStreamer { 86 private: 87 // True if we are processing SEH directives in an epilogue. 88 bool InEpilogCFI = false; 89 90 // Symbol of the current epilog for which we are processing SEH directives. 91 MCSymbol *CurrentEpilog = nullptr; 92 public: 93 AArch64TargetWinCOFFStreamer(llvm::MCStreamer &S) 94 : AArch64TargetStreamer(S) {} 95 96 // The unwind codes on ARM64 Windows are documented at 97 // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling 98 void emitARM64WinCFIAllocStack(unsigned Size) override; 99 void emitARM64WinCFISaveR19R20X(int Offset) override; 100 void emitARM64WinCFISaveFPLR(int Offset) override; 101 void emitARM64WinCFISaveFPLRX(int Offset) override; 102 void emitARM64WinCFISaveReg(unsigned Reg, int Offset) override; 103 void emitARM64WinCFISaveRegX(unsigned Reg, int Offset) override; 104 void emitARM64WinCFISaveRegP(unsigned Reg, int Offset) override; 105 void emitARM64WinCFISaveRegPX(unsigned Reg, int Offset) override; 106 void emitARM64WinCFISaveLRPair(unsigned Reg, int Offset) override; 107 void emitARM64WinCFISaveFReg(unsigned Reg, int Offset) override; 108 void emitARM64WinCFISaveFRegX(unsigned Reg, int Offset) override; 109 void emitARM64WinCFISaveFRegP(unsigned Reg, int Offset) override; 110 void emitARM64WinCFISaveFRegPX(unsigned Reg, int Offset) override; 111 void emitARM64WinCFISetFP() override; 112 void emitARM64WinCFIAddFP(unsigned Size) override; 113 void emitARM64WinCFINop() override; 114 void emitARM64WinCFISaveNext() override; 115 void emitARM64WinCFIPrologEnd() override; 116 void emitARM64WinCFIEpilogStart() override; 117 void emitARM64WinCFIEpilogEnd() override; 118 void emitARM64WinCFITrapFrame() override; 119 void emitARM64WinCFIMachineFrame() override; 120 void emitARM64WinCFIContext() override; 121 void emitARM64WinCFIClearUnwoundToCall() override; 122 123 private: 124 void emitARM64WinUnwindCode(unsigned UnwindCode, int Reg, int Offset); 125 }; 126 127 MCTargetStreamer * 128 createAArch64ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 129 130 } // end namespace llvm 131 132 #endif 133