PPCELFStreamer.h 2.3 KB

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