| 1 | //===- PPCELFStreamer.h - ELF Object Output --------------------*- 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 is a custom MCELFStreamer for PowerPC. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H |
| 14 | #define LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H |
| 15 | |
| 16 | #include "llvm/MC/MCELFStreamer.h" |
| 17 | #include <memory> |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | class MCAsmBackend; |
| 22 | class MCCodeEmitter; |
| 23 | class MCContext; |
| 24 | class MCSubtargetInfo; |
| 25 | |
| 26 | class PPCELFStreamer : public MCELFStreamer { |
| 27 | // We need to keep track of the last label we emitted (only one) because |
| 28 | // depending on whether the label is on the same line as an aligned |
| 29 | // instruction or not, the label may refer to the instruction or the nop. |
| 30 | MCSymbol *LastLabel; |
| 31 | SMLoc LastLabelLoc; |
| 32 | |
| 33 | public: |
| 34 | PPCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB, |
| 35 | std::unique_ptr<MCObjectWriter> OW, |
| 36 | std::unique_ptr<MCCodeEmitter> Emitter); |
| 37 | |
| 38 | void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override; |
| 39 | |
| 40 | // EmitLabel updates LastLabel and LastLabelLoc when a new label is emitted. |
| 41 | void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; |
| 42 | private: |
| 43 | void emitPrefixedInstruction(const MCInst &Inst, const MCSubtargetInfo &STI); |
| 44 | void emitGOTToPCRelReloc(const MCInst &Inst); |
| 45 | void emitGOTToPCRelLabel(const MCInst &Inst); |
| 46 | }; |
| 47 | |
| 48 | // Check if the instruction Inst is part of a pair of instructions that make up |
| 49 | // a link time GOT PC Rel optimization. |
| 50 | std::optional<bool> isPartOfGOTToPCRelPair(const MCInst &Inst, |
| 51 | const MCSubtargetInfo &STI); |
| 52 | |
| 53 | MCStreamer *createPPCELFStreamer(const Triple &, MCContext &, |
| 54 | std::unique_ptr<MCAsmBackend> &&MAB, |
| 55 | std::unique_ptr<MCObjectWriter> &&OW, |
| 56 | std::unique_ptr<MCCodeEmitter> &&Emitter); |
| 57 | } // end namespace llvm |
| 58 | |
| 59 | #endif // LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H |
| 60 | |