LLVM 20.0.0git
MipsOptionRecord.cpp
Go to the documentation of this file.
1//===- MipsOptionRecord.cpp - Abstraction for storing information ---------===//
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#include "MipsOptionRecord.h"
10#include "MipsABIInfo.h"
11#include "MipsELFStreamer.h"
12#include "MipsTargetStreamer.h"
14#include "llvm/MC/MCAssembler.h"
15#include "llvm/MC/MCContext.h"
18#include <cassert>
19
20using namespace llvm;
21
24 static_cast<MipsTargetStreamer *>(Streamer->getTargetStreamer());
25
26 Streamer->pushSection();
27
28 // We need to distinguish between N64 and the rest because at the moment
29 // we don't emit .Mips.options for other ELFs other than N64.
30 // Since .reginfo has the same information as .Mips.options (ODK_REGINFO),
31 // we can use the same abstraction (MipsRegInfoRecord class) to handle both.
32 if (MTS->getABI().IsN64()) {
33 // The EntrySize value of 1 seems strange since the records are neither
34 // 1-byte long nor fixed length but it matches the value GAS emits.
35 MCSectionELF *Sec =
36 Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
38 Sec->setAlignment(Align(8));
39 Streamer->switchSection(Sec);
40
41 Streamer->emitInt8(ELF::ODK_REGINFO); // kind
42 Streamer->emitInt8(40); // size
43 Streamer->emitInt16(0); // section
44 Streamer->emitInt32(0); // info
45 Streamer->emitInt32(ri_gprmask);
46 Streamer->emitInt32(0); // pad
47 Streamer->emitInt32(ri_cprmask[0]);
48 Streamer->emitInt32(ri_cprmask[1]);
49 Streamer->emitInt32(ri_cprmask[2]);
50 Streamer->emitInt32(ri_cprmask[3]);
51 Streamer->emitIntValue(ri_gp_value, 8);
52 } else {
53 MCSectionELF *Sec = Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO,
54 ELF::SHF_ALLOC, 24);
55 Sec->setAlignment(MTS->getABI().IsN32() ? Align(8) : Align(4));
56 Streamer->switchSection(Sec);
57
58 Streamer->emitInt32(ri_gprmask);
59 Streamer->emitInt32(ri_cprmask[0]);
60 Streamer->emitInt32(ri_cprmask[1]);
61 Streamer->emitInt32(ri_cprmask[2]);
62 Streamer->emitInt32(ri_cprmask[3]);
63 assert((ri_gp_value & 0xffffffff) == ri_gp_value);
64 Streamer->emitInt32(ri_gp_value);
65 }
66
67 Streamer->popSection();
68}
69
71 const MCRegisterInfo *MCRegInfo) {
72 unsigned Value = 0;
73
74 for (const MCPhysReg &SubReg : MCRegInfo->subregs_inclusive(Reg)) {
75 unsigned EncVal = MCRegInfo->getEncodingValue(SubReg);
76 Value |= 1 << EncVal;
77
78 if (GPR32RegClass->contains(SubReg) || GPR64RegClass->contains(SubReg))
79 ri_gprmask |= Value;
80 else if (COP0RegClass->contains(SubReg))
81 ri_cprmask[0] |= Value;
82 // MIPS COP1 is the FPU.
83 else if (FGR32RegClass->contains(SubReg) ||
84 FGR64RegClass->contains(SubReg) ||
85 AFGR64RegClass->contains(SubReg) ||
86 MSA128BRegClass->contains(SubReg))
87 ri_cprmask[1] |= Value;
88 else if (COP2RegClass->contains(SubReg))
89 ri_cprmask[2] |= Value;
90 else if (COP3RegClass->contains(SubReg))
91 ri_cprmask[3] |= Value;
92 }
93}
unsigned SubReg
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:551
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
iterator_range< MCSubRegIterator > subregs_inclusive(MCRegister Reg) const
Return an iterator range over all sub-registers of Reg, including Reg.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
void setAlignment(Align Value)
Definition: MCSection.h:147
bool popSection()
Restore the current and previous section from the section stack.
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:309
void emitInt16(uint64_t Value)
Definition: MCStreamer.h:718
void pushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:416
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:719
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:717
bool IsN64() const
Definition: MipsABIInfo.h:42
bool IsN32() const
Definition: MipsABIInfo.h:41
void switchSection(MCSection *Section, uint32_t Subsection=0) override
Overriding this function allows us to dismiss all labels that are candidates for marking as microMIPS...
void emitIntValue(uint64_t Value, unsigned Size) override
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
void SetPhysRegUsed(unsigned Reg, const MCRegisterInfo *MCRegInfo)
void EmitMipsOptionRecord() override
const MipsABIInfo & getABI() const
LLVM Value Representation.
Definition: Value.h:74
@ SHT_MIPS_REGINFO
Definition: ELF.h:1162
@ SHT_MIPS_OPTIONS
Definition: ELF.h:1163
@ ODK_REGINFO
Definition: ELF.h:598
@ SHF_MIPS_NOSTRIP
Definition: ELF.h:1266
@ SHF_ALLOC
Definition: ELF.h:1186
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39