LLVM 20.0.0git
LoongArchELFStreamer.cpp
Go to the documentation of this file.
1//===-- LoongArchELFStreamer.cpp - LoongArch ELF Target Streamer Methods --===//
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 file provides LoongArch specific target streamer methods.
10//
11//===----------------------------------------------------------------------===//
12
14#include "LoongArchAsmBackend.h"
15#include "LoongArchBaseInfo.h"
17#include "llvm/MC/MCAssembler.h"
20
21using namespace llvm;
22
23// This part is for ELF object output.
25 MCStreamer &S, const MCSubtargetInfo &STI)
27 auto &MAB = static_cast<LoongArchAsmBackend &>(
31 MAB.getTargetOptions().getABIName()));
32}
33
35 return static_cast<MCELFStreamer &>(Streamer);
36}
37
42
47
48 // Figure out the e_flags.
49 //
50 // Bitness is already represented with the EI_CLASS byte in the current spec,
51 // so here we only record the base ABI modifier. Also set the object file ABI
52 // version to v1, as upstream LLVM cannot handle the previous stack-machine-
53 // based relocs from day one.
54 //
55 // Refer to LoongArch ELF psABI v2.01 for details.
56 unsigned EFlags = W.getELFHeaderEFlags();
58 switch (ABI) {
62 break;
66 break;
70 break;
72 llvm_unreachable("Improperly initialized target ABI");
73 }
74 W.setELFHeaderEFlags(EFlags);
75}
76
77namespace {
78class LoongArchELFStreamer : public MCELFStreamer {
79public:
80 LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
81 std::unique_ptr<MCObjectWriter> MOW,
82 std::unique_ptr<MCCodeEmitter> MCE)
83 : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
84};
85} // end namespace
86
87namespace llvm {
89 std::unique_ptr<MCAsmBackend> MAB,
90 std::unique_ptr<MCObjectWriter> MOW,
91 std::unique_ptr<MCCodeEmitter> MCE) {
92 LoongArchELFStreamer *S = new LoongArchELFStreamer(
93 C, std::move(MAB), std::move(MOW), std::move(MCE));
94 return S;
95}
96} // end namespace llvm
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LoongArchABI::ABI getTargetABI() const
void setTargetABI(LoongArchABI::ABI ABI)
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:188
Context object for machine code objects.
Definition: MCContext.h:83
ELFObjectWriter & getWriter()
MCAssembler & getAssembler()
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
virtual void finish()
Definition: MCStreamer.cpp:55
MCStreamer & Streamer
Definition: MCStreamer.h:96
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ EF_LOONGARCH_OBJABI_V1
Definition: ELF.h:1021
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition: ELF.h:1015
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition: ELF.h:1016
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition: ELF.h:1014
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE)
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858