Skip to content

[MC][Mips] Rename MipsMCAsmInfo to MipsELFMCAsmInfo #112592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

using namespace llvm;

void MipsMCAsmInfo::anchor() { }
void MipsELFMCAsmInfo::anchor() {}

MipsMCAsmInfo::MipsMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options) {
MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options) {
IsLittleEndian = TheTriple.isLittleEndian();

MipsABIInfo ABI = MipsABIInfo::computeTargetABI(TheTriple, "", Options);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
namespace llvm {
class Triple;

class MipsMCAsmInfo : public MCAsmInfoELF {
class MipsELFMCAsmInfo : public MCAsmInfoELF {
void anchor() override;

public:
explicit MipsMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options);
explicit MipsELFMCAsmInfo(const Triple &TheTriple,
const MCTargetOptions &Options);
};

} // namespace llvm
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static MCSubtargetInfo *createMipsMCSubtargetInfo(const Triple &TT,
static MCAsmInfo *createMipsMCAsmInfo(const MCRegisterInfo &MRI,
const Triple &TT,
const MCTargetOptions &Options) {
MCAsmInfo *MAI = new MipsMCAsmInfo(TT, Options);
MCAsmInfo *MAI = new MipsELFMCAsmInfo(TT, Options);

unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
MCCFIInstruction Inst = MCCFIInstruction::createDefCfaRegister(nullptr, SP);
Expand Down
115 changes: 59 additions & 56 deletions llvm/lib/Target/Mips/MipsAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,70 +730,73 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
}

void MipsAsmPrinter::emitStartOfAsmFile(Module &M) {
MipsTargetStreamer &TS = getTargetStreamer();

// MipsTargetStreamer has an initialization order problem when emitting an
// object file directly (see MipsTargetELFStreamer for full details). Work
// around it by re-initializing the PIC state here.
TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());

// Try to get target-features from the first function.
StringRef FS = TM.getTargetFeatureString();
Module::iterator F = M.begin();
if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
FS = F->getFnAttribute("target-features").getValueAsString();

// Compute MIPS architecture attributes based on the default subtarget
// that we'd have constructed.
// FIXME: For ifunc related functions we could iterate over and look
// for a feature string that doesn't match the default one.
const Triple &TT = TM.getTargetTriple();
StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);

bool IsABICalls = STI.isABICalls();
const MipsABIInfo &ABI = MTM.getABI();
if (IsABICalls) {
TS.emitDirectiveAbiCalls();
// FIXME: This condition should be a lot more complicated that it is here.
// Ideally it should test for properties of the ABI and not the ABI
// itself.
// For the moment, I'm only correcting enough to make MIPS-IV work.
if (!isPositionIndependent() && STI.hasSym32())
TS.emitDirectiveOptionPic0();
}

// Tell the assembler which ABI we are using
std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
OutStreamer->switchSection(
OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
if (TT.isOSBinFormatELF()) {
MipsTargetStreamer &TS = getTargetStreamer();

// MipsTargetStreamer has an initialization order problem when emitting an
// object file directly (see MipsTargetELFStreamer for full details). Work
// around it by re-initializing the PIC state here.
TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());

// Try to get target-features from the first function.
StringRef FS = TM.getTargetFeatureString();
Module::iterator F = M.begin();
if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
FS = F->getFnAttribute("target-features").getValueAsString();

// Compute MIPS architecture attributes based on the default subtarget
// that we'd have constructed.
// FIXME: For ifunc related functions we could iterate over and look
// for a feature string that doesn't match the default one.
StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM,
std::nullopt);

bool IsABICalls = STI.isABICalls();
const MipsABIInfo &ABI = MTM.getABI();
if (IsABICalls) {
TS.emitDirectiveAbiCalls();
// FIXME: This condition should be a lot more complicated that it is here.
// Ideally it should test for properties of the ABI and not the ABI
// itself.
// For the moment, I'm only correcting enough to make MIPS-IV work.
if (!isPositionIndependent() && STI.hasSym32())
TS.emitDirectiveOptionPic0();
}

// Tell the assembler which ABI we are using
std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
OutStreamer->switchSection(
OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));

// NaN: At the moment we only support:
// 1. .nan legacy (default)
// 2. .nan 2008
STI.isNaN2008() ? TS.emitDirectiveNaN2008()
: TS.emitDirectiveNaNLegacy();
// NaN: At the moment we only support:
// 1. .nan legacy (default)
// 2. .nan 2008
STI.isNaN2008() ? TS.emitDirectiveNaN2008() : TS.emitDirectiveNaNLegacy();

// TODO: handle O64 ABI
// TODO: handle O64 ABI

TS.updateABIInfo(STI);
TS.updateABIInfo(STI);

// We should always emit a '.module fp=...' but binutils 2.24 does not accept
// it. We therefore emit it when it contradicts the ABI defaults (-mfpxx or
// -mfp64) and omit it otherwise.
if ((ABI.IsO32() && (STI.isABI_FPXX() || STI.isFP64bit())) ||
STI.useSoftFloat())
TS.emitDirectiveModuleFP();
// We should always emit a '.module fp=...' but binutils 2.24 does not
// accept it. We therefore emit it when it contradicts the ABI defaults
// (-mfpxx or -mfp64) and omit it otherwise.
if ((ABI.IsO32() && (STI.isABI_FPXX() || STI.isFP64bit())) ||
STI.useSoftFloat())
TS.emitDirectiveModuleFP();

// We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
// accept it. We therefore emit it when it contradicts the default or an
// option has changed the default (i.e. FPXX) and omit it otherwise.
if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
TS.emitDirectiveModuleOddSPReg();
// We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
// accept it. We therefore emit it when it contradicts the default or an
// option has changed the default (i.e. FPXX) and omit it otherwise.
if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
TS.emitDirectiveModuleOddSPReg();

// Switch to the .text section.
OutStreamer->switchSection(getObjFileLowering().getTextSection());
// Switch to the .text section.
OutStreamer->switchSection(getObjFileLowering().getTextSection());
}
}

void MipsAsmPrinter::emitInlineAsmStart() const {
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/Mips/MipsTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsTarget() {
initializeMipsDAGToDAGISelLegacyPass(*PR);
}

static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
return std::make_unique<MipsTargetObjectFile>();
}

static std::string computeDataLayout(const Triple &TT, StringRef CPU,
const TargetOptions &Options,
bool isLittle) {
Expand Down Expand Up @@ -128,7 +132,7 @@ MipsTargetMachine::MipsTargetMachine(const Target &T, const Triple &TT,
: LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT,
CPU, FS, Options, getEffectiveRelocModel(JIT, RM),
getEffectiveCodeModel(CM, CodeModel::Small), OL),
isLittle(isLittle), TLOF(std::make_unique<MipsTargetObjectFile>()),
isLittle(isLittle), TLOF(createTLOF(getTargetTriple())),
ABI(MipsABIInfo::computeTargetABI(TT, CPU, Options.MCOptions)),
Subtarget(nullptr),
DefaultSubtarget(TT, CPU, FS, isLittle, *this, std::nullopt),
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/CodeGen/Mips/no-odd-spreg.ll
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
; RUN: llc -march=mipsel -mcpu=mips32 < %s \
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32 < %s \
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-NO-EMIT
; RUN: llc -march=mipsel -mcpu=mips32 -mattr=+nooddspreg < %s \
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32 -mattr=+nooddspreg < %s \
; RUN: | FileCheck %s -check-prefixes=ALL,NOODDSPREG
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64 < %s \
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fp64 < %s \
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-NO-EMIT
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64,+nooddspreg < %s \
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fp64,+nooddspreg < %s \
; RUN: | FileCheck %s -check-prefixes=ALL,NOODDSPREG
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fpxx,-nooddspreg < %s \
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fpxx,-nooddspreg < %s \
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-EMIT

; We don't emit a directive unless we need to. This is to support versions of
Expand Down
Loading