LLVM 19.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 &>(
30 STI.getTargetTriple(), MAB.getTargetOptions().getABIName()));
31}
32
34 return static_cast<MCELFStreamer &>(Streamer);
35}
36
41
42 // Figure out the e_flags.
43 //
44 // Bitness is already represented with the EI_CLASS byte in the current spec,
45 // so here we only record the base ABI modifier. Also set the object file ABI
46 // version to v1, as upstream LLVM cannot handle the previous stack-machine-
47 // based relocs from day one.
48 //
49 // Refer to LoongArch ELF psABI v2.01 for details.
50 unsigned EFlags = MCA.getELFHeaderEFlags();
52 switch (ABI) {
56 break;
60 break;
64 break;
66 llvm_unreachable("Improperly initialized target ABI");
67 }
68 MCA.setELFHeaderEFlags(EFlags);
69}
70
71namespace {
72class LoongArchELFStreamer : public MCELFStreamer {
73public:
74 LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
75 std::unique_ptr<MCObjectWriter> MOW,
76 std::unique_ptr<MCCodeEmitter> MCE)
77 : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
78};
79} // end namespace
80
81namespace llvm {
83 std::unique_ptr<MCAsmBackend> MAB,
84 std::unique_ptr<MCObjectWriter> MOW,
85 std::unique_ptr<MCCodeEmitter> MCE,
86 bool RelaxAll) {
87 LoongArchELFStreamer *S = new LoongArchELFStreamer(
88 C, std::move(MAB), std::move(MOW), std::move(MCE));
89 S->getAssembler().setRelaxAll(RelaxAll);
90 return S;
91}
92} // end namespace llvm
LoongArchTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LoongArchABI::ABI getTargetABI() const
void setTargetABI(LoongArchABI::ABI ABI)
unsigned getELFHeaderEFlags() const
ELF e_header flags.
Definition: MCAssembler.h:281
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:334
void setELFHeaderEFlags(unsigned Flags)
Definition: MCAssembler.h:282
Context object for machine code objects.
Definition: MCContext.h:76
MCAssembler & getAssembler()
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
virtual void finish()
Definition: MCStreamer.cpp:55
MCStreamer & Streamer
Definition: MCStreamer.h:95
#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:992
@ EF_LOONGARCH_ABI_SINGLE_FLOAT
Definition: ELF.h:986
@ EF_LOONGARCH_ABI_DOUBLE_FLOAT
Definition: ELF.h:987
@ EF_LOONGARCH_ABI_SOFT_FLOAT
Definition: ELF.h:985
ABI computeTargetABI(const Triple &TT, 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:1858
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE, bool RelaxAll)
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858