| 1 | //=- SystemZTargetStreamer.h - SystemZ 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_SYSTEMZ_SYSTEMZTARGETSTREAMER_H |
| 10 | #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H |
| 11 | |
| 12 | #include "llvm/ADT/StringRef.h" |
| 13 | #include "llvm/MC/MCContext.h" |
| 14 | #include "llvm/MC/MCExpr.h" |
| 15 | #include "llvm/MC/MCInst.h" |
| 16 | #include "llvm/MC/MCStreamer.h" |
| 17 | #include "llvm/MC/MCSymbol.h" |
| 18 | #include "llvm/Support/FormattedStream.h" |
| 19 | #include <map> |
| 20 | #include <utility> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class SystemZHLASMAsmStreamer; |
| 24 | |
| 25 | class SystemZTargetStreamer : public MCTargetStreamer { |
| 26 | public: |
| 27 | SystemZTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} |
| 28 | |
| 29 | typedef std::pair<MCInst, const MCSubtargetInfo *> MCInstSTIPair; |
| 30 | struct CmpMCInst { |
| 31 | bool operator()(const MCInstSTIPair &MCI_STI_A, |
| 32 | const MCInstSTIPair &MCI_STI_B) const { |
| 33 | if (MCI_STI_A.second != MCI_STI_B.second) |
| 34 | return uintptr_t(MCI_STI_A.second) < uintptr_t(MCI_STI_B.second); |
| 35 | const MCInst &A = MCI_STI_A.first; |
| 36 | const MCInst &B = MCI_STI_B.first; |
| 37 | assert(A.getNumOperands() == B.getNumOperands() && |
| 38 | A.getNumOperands() == 5 && A.getOperand(2).getImm() == 1 && |
| 39 | B.getOperand(2).getImm() == 1 && "Unexpected EXRL target MCInst" ); |
| 40 | if (A.getOpcode() != B.getOpcode()) |
| 41 | return A.getOpcode() < B.getOpcode(); |
| 42 | if (A.getOperand(i: 0).getReg() != B.getOperand(i: 0).getReg()) |
| 43 | return A.getOperand(i: 0).getReg() < B.getOperand(i: 0).getReg(); |
| 44 | if (A.getOperand(i: 1).getImm() != B.getOperand(i: 1).getImm()) |
| 45 | return A.getOperand(i: 1).getImm() < B.getOperand(i: 1).getImm(); |
| 46 | if (A.getOperand(i: 3).getReg() != B.getOperand(i: 3).getReg()) |
| 47 | return A.getOperand(i: 3).getReg() < B.getOperand(i: 3).getReg(); |
| 48 | if (A.getOperand(i: 4).getImm() != B.getOperand(i: 4).getImm()) |
| 49 | return A.getOperand(i: 4).getImm() < B.getOperand(i: 4).getImm(); |
| 50 | return false; |
| 51 | } |
| 52 | }; |
| 53 | typedef std::map<MCInstSTIPair, MCSymbol *, CmpMCInst> EXRLT2SymMap; |
| 54 | EXRLT2SymMap EXRLTargets2Sym; |
| 55 | |
| 56 | void emitConstantPools() override; |
| 57 | |
| 58 | virtual void emitMachine(StringRef CPUOrCommand) {}; |
| 59 | |
| 60 | virtual void emitExtern(StringRef Str) {}; |
| 61 | virtual void emitEnd() {}; |
| 62 | |
| 63 | virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi, |
| 64 | const MCSymbol *Lo) { |
| 65 | return nullptr; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | class SystemZTargetGOFFStreamer : public SystemZTargetStreamer { |
| 70 | public: |
| 71 | SystemZTargetGOFFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {} |
| 72 | const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi, |
| 73 | const MCSymbol *Lo) override; |
| 74 | }; |
| 75 | |
| 76 | class SystemZTargetHLASMStreamer : public SystemZTargetStreamer { |
| 77 | formatted_raw_ostream &OS; |
| 78 | |
| 79 | public: |
| 80 | SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS) |
| 81 | : SystemZTargetStreamer(S), OS(OS) {} |
| 82 | SystemZHLASMAsmStreamer &getHLASMStreamer(); |
| 83 | void emitExtern(StringRef Sym) override; |
| 84 | void emitEnd() override; |
| 85 | const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi, |
| 86 | const MCSymbol *Lo) override; |
| 87 | }; |
| 88 | |
| 89 | class SystemZTargetELFStreamer : public SystemZTargetStreamer { |
| 90 | public: |
| 91 | SystemZTargetELFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {} |
| 92 | void emitMachine(StringRef CPUOrCommand) override {} |
| 93 | }; |
| 94 | |
| 95 | class SystemZTargetGNUStreamer : public SystemZTargetStreamer { |
| 96 | formatted_raw_ostream &OS; |
| 97 | |
| 98 | public: |
| 99 | SystemZTargetGNUStreamer(MCStreamer &S, formatted_raw_ostream &OS) |
| 100 | : SystemZTargetStreamer(S), OS(OS) {} |
| 101 | void emitMachine(StringRef CPUOrCommand) override { |
| 102 | OS << "\t.machine " << CPUOrCommand << "\n" ; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | } // end namespace llvm |
| 107 | |
| 108 | #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H |
| 109 | |