Skip to content

Commit 38bcda6

Browse files
committed
[MC][Mips] Rename MipsMCAsmInfo to MipsELFMCAsmInfo
Also change MipsAsmPrinter::emitStartOfAsmFile to emit ELF-related sections only when using ELF output file format.
1 parent db61c91 commit 38bcda6

File tree

5 files changed

+71
-64
lines changed

5 files changed

+71
-64
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
@@ -734,70 +734,73 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
734734
}
735735

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

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

776-
// NaN: At the moment we only support:
777-
// 1. .nan legacy (default)
778-
// 2. .nan 2008
779-
STI.isNaN2008() ? TS.emitDirectiveNaN2008()
780-
: TS.emitDirectiveNaNLegacy();
778+
// NaN: At the moment we only support:
779+
// 1. .nan legacy (default)
780+
// 2. .nan 2008
781+
STI.isNaN2008() ? TS.emitDirectiveNaN2008()
782+
: TS.emitDirectiveNaNLegacy();
781783

782-
// TODO: handle O64 ABI
784+
// TODO: handle O64 ABI
783785

784-
TS.updateABIInfo(STI);
786+
TS.updateABIInfo(STI);
785787

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

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

799-
// Switch to the .text section.
800-
OutStreamer->switchSection(getObjFileLowering().getTextSection());
801+
// Switch to the .text section.
802+
OutStreamer->switchSection(getObjFileLowering().getTextSection());
803+
}
801804
}
802805

803806
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),

0 commit comments

Comments
 (0)