Skip to content

Commit 6fa1647

Browse files
authored
[MC][Mips] Rename MipsMCAsmInfo to MipsELFMCAsmInfo (#112592)
Also change MipsAsmPrinter::emitStartOfAsmFile to emit ELF-related sections only when using ELF output file format.
1 parent beb7fb9 commit 6fa1647

File tree

6 files changed

+76
-69
lines changed

6 files changed

+76
-69
lines changed

llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
using namespace llvm;
1818

19-
void MipsMCAsmInfo::anchor() { }
19+
void MipsELFMCAsmInfo::anchor() {}
2020

21-
MipsMCAsmInfo::MipsMCAsmInfo(const Triple &TheTriple,
22-
const MCTargetOptions &Options) {
21+
MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
22+
const MCTargetOptions &Options) {
2323
IsLittleEndian = TheTriple.isLittleEndian();
2424

2525
MipsABIInfo ABI = MipsABIInfo::computeTargetABI(TheTriple, "", Options);

llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
namespace llvm {
1919
class Triple;
2020

21-
class MipsMCAsmInfo : public MCAsmInfoELF {
21+
class MipsELFMCAsmInfo : public MCAsmInfoELF {
2222
void anchor() override;
2323

2424
public:
25-
explicit MipsMCAsmInfo(const Triple &TheTriple,
26-
const MCTargetOptions &Options);
25+
explicit MipsELFMCAsmInfo(const Triple &TheTriple,
26+
const MCTargetOptions &Options);
2727
};
2828

2929
} // namespace llvm

llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static MCSubtargetInfo *createMipsMCSubtargetInfo(const Triple &TT,
8484
static MCAsmInfo *createMipsMCAsmInfo(const MCRegisterInfo &MRI,
8585
const Triple &TT,
8686
const MCTargetOptions &Options) {
87-
MCAsmInfo *MAI = new MipsMCAsmInfo(TT, Options);
87+
MCAsmInfo *MAI = new MipsELFMCAsmInfo(TT, Options);
8888

8989
unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
9090
MCCFIInstruction Inst = MCCFIInstruction::createDefCfaRegister(nullptr, SP);

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -730,70 +730,73 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
730730
}
731731

732732
void MipsAsmPrinter::emitStartOfAsmFile(Module &M) {
733-
MipsTargetStreamer &TS = getTargetStreamer();
734-
735-
// MipsTargetStreamer has an initialization order problem when emitting an
736-
// object file directly (see MipsTargetELFStreamer for full details). Work
737-
// around it by re-initializing the PIC state here.
738-
TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
739-
740-
// Try to get target-features from the first function.
741-
StringRef FS = TM.getTargetFeatureString();
742-
Module::iterator F = M.begin();
743-
if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
744-
FS = F->getFnAttribute("target-features").getValueAsString();
745-
746-
// Compute MIPS architecture attributes based on the default subtarget
747-
// that we'd have constructed.
748-
// FIXME: For ifunc related functions we could iterate over and look
749-
// for a feature string that doesn't match the default one.
750733
const Triple &TT = TM.getTargetTriple();
751-
StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
752-
const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
753-
const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, std::nullopt);
754-
755-
bool IsABICalls = STI.isABICalls();
756-
const MipsABIInfo &ABI = MTM.getABI();
757-
if (IsABICalls) {
758-
TS.emitDirectiveAbiCalls();
759-
// FIXME: This condition should be a lot more complicated that it is here.
760-
// Ideally it should test for properties of the ABI and not the ABI
761-
// itself.
762-
// For the moment, I'm only correcting enough to make MIPS-IV work.
763-
if (!isPositionIndependent() && STI.hasSym32())
764-
TS.emitDirectiveOptionPic0();
765-
}
766734

767-
// Tell the assembler which ABI we are using
768-
std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
769-
OutStreamer->switchSection(
770-
OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
735+
if (TT.isOSBinFormatELF()) {
736+
MipsTargetStreamer &TS = getTargetStreamer();
737+
738+
// MipsTargetStreamer has an initialization order problem when emitting an
739+
// object file directly (see MipsTargetELFStreamer for full details). Work
740+
// around it by re-initializing the PIC state here.
741+
TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
742+
743+
// Try to get target-features from the first function.
744+
StringRef FS = TM.getTargetFeatureString();
745+
Module::iterator F = M.begin();
746+
if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
747+
FS = F->getFnAttribute("target-features").getValueAsString();
748+
749+
// Compute MIPS architecture attributes based on the default subtarget
750+
// that we'd have constructed.
751+
// FIXME: For ifunc related functions we could iterate over and look
752+
// for a feature string that doesn't match the default one.
753+
StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
754+
const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
755+
const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM,
756+
std::nullopt);
757+
758+
bool IsABICalls = STI.isABICalls();
759+
const MipsABIInfo &ABI = MTM.getABI();
760+
if (IsABICalls) {
761+
TS.emitDirectiveAbiCalls();
762+
// FIXME: This condition should be a lot more complicated that it is here.
763+
// Ideally it should test for properties of the ABI and not the ABI
764+
// itself.
765+
// For the moment, I'm only correcting enough to make MIPS-IV work.
766+
if (!isPositionIndependent() && STI.hasSym32())
767+
TS.emitDirectiveOptionPic0();
768+
}
769+
770+
// Tell the assembler which ABI we are using
771+
std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
772+
OutStreamer->switchSection(
773+
OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
771774

772-
// NaN: At the moment we only support:
773-
// 1. .nan legacy (default)
774-
// 2. .nan 2008
775-
STI.isNaN2008() ? TS.emitDirectiveNaN2008()
776-
: TS.emitDirectiveNaNLegacy();
775+
// NaN: At the moment we only support:
776+
// 1. .nan legacy (default)
777+
// 2. .nan 2008
778+
STI.isNaN2008() ? TS.emitDirectiveNaN2008() : TS.emitDirectiveNaNLegacy();
777779

778-
// TODO: handle O64 ABI
780+
// TODO: handle O64 ABI
779781

780-
TS.updateABIInfo(STI);
782+
TS.updateABIInfo(STI);
781783

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

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

795-
// Switch to the .text section.
796-
OutStreamer->switchSection(getObjFileLowering().getTextSection());
797+
// Switch to the .text section.
798+
OutStreamer->switchSection(getObjFileLowering().getTextSection());
799+
}
797800
}
798801

799802
void MipsAsmPrinter::emitInlineAsmStart() const {

llvm/lib/Target/Mips/MipsTargetMachine.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsTarget() {
7070
initializeMipsDAGToDAGISelLegacyPass(*PR);
7171
}
7272

73+
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
74+
return std::make_unique<MipsTargetObjectFile>();
75+
}
76+
7377
static std::string computeDataLayout(const Triple &TT, StringRef CPU,
7478
const TargetOptions &Options,
7579
bool isLittle) {
@@ -128,7 +132,7 @@ MipsTargetMachine::MipsTargetMachine(const Target &T, const Triple &TT,
128132
: LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT,
129133
CPU, FS, Options, getEffectiveRelocModel(JIT, RM),
130134
getEffectiveCodeModel(CM, CodeModel::Small), OL),
131-
isLittle(isLittle), TLOF(std::make_unique<MipsTargetObjectFile>()),
135+
isLittle(isLittle), TLOF(createTLOF(getTargetTriple())),
132136
ABI(MipsABIInfo::computeTargetABI(TT, CPU, Options.MCOptions)),
133137
Subtarget(nullptr),
134138
DefaultSubtarget(TT, CPU, FS, isLittle, *this, std::nullopt),

llvm/test/CodeGen/Mips/no-odd-spreg.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
; RUN: llc -march=mipsel -mcpu=mips32 < %s \
1+
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32 < %s \
22
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-NO-EMIT
3-
; RUN: llc -march=mipsel -mcpu=mips32 -mattr=+nooddspreg < %s \
3+
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32 -mattr=+nooddspreg < %s \
44
; RUN: | FileCheck %s -check-prefixes=ALL,NOODDSPREG
5-
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64 < %s \
5+
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fp64 < %s \
66
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-NO-EMIT
7-
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fp64,+nooddspreg < %s \
7+
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fp64,+nooddspreg < %s \
88
; RUN: | FileCheck %s -check-prefixes=ALL,NOODDSPREG
9-
; RUN: llc -march=mipsel -mcpu=mips32r6 -mattr=fpxx,-nooddspreg < %s \
9+
; RUN: llc -mtriple=mipsel-elf -mcpu=mips32r6 -mattr=fpxx,-nooddspreg < %s \
1010
; RUN: | FileCheck %s -check-prefixes=ALL,ODDSPREG,ODDSPREG-EMIT
1111

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

0 commit comments

Comments
 (0)