xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.h (revision 0d8fe2373503aeac48492f28073049a8bfa4feb5)
1 //===- PPCELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is a custom MCELFStreamer for PowerPC.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H
15 #define LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/MC/MCELFStreamer.h"
19 #include <memory>
20 
21 namespace llvm {
22 
23 class MCAsmBackend;
24 class MCCodeEmitter;
25 class MCContext;
26 class MCSubtargetInfo;
27 
28 class PPCELFStreamer : public MCELFStreamer {
29   // We need to keep track of the last label we emitted (only one) because
30   // depending on whether the label is on the same line as an aligned
31   // instruction or not, the label may refer to the instruction or the nop.
32   MCSymbol *LastLabel;
33   SMLoc LastLabelLoc;
34 
35 public:
36   PPCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
37                  std::unique_ptr<MCObjectWriter> OW,
38                  std::unique_ptr<MCCodeEmitter> Emitter);
39 
40   void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
41 
42   // EmitLabel updates LastLabel and LastLabelLoc when a new label is emitted.
43   void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
44 private:
45   void emitPrefixedInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
46   void emitGOTToPCRelReloc(const MCInst &Inst);
47   void emitGOTToPCRelLabel(const MCInst &Inst);
48 };
49 
50 // Check if the instruction Inst is part of a pair of instructions that make up
51 // a link time GOT PC Rel optimization.
52 Optional<bool> isPartOfGOTToPCRelPair(const MCInst &Inst,
53                                       const MCSubtargetInfo &STI);
54 
55 MCELFStreamer *createPPCELFStreamer(MCContext &Context,
56                                     std::unique_ptr<MCAsmBackend> MAB,
57                                     std::unique_ptr<MCObjectWriter> OW,
58                                     std::unique_ptr<MCCodeEmitter> Emitter);
59 } // end namespace llvm
60 
61 #endif // LLVM_LIB_TARGET_PPC_MCELFSTREAMER_PPCELFSTREAMER_H
62