@@ -730,70 +730,73 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
730
730
}
731
731
732
732
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.
750
733
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
- }
766
734
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 ));
771
774
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 ();
777
779
778
- // TODO: handle O64 ABI
780
+ // TODO: handle O64 ABI
779
781
780
- TS.updateABIInfo (STI);
782
+ TS.updateABIInfo (STI);
781
783
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 ();
788
790
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 ();
794
796
795
- // Switch to the .text section.
796
- OutStreamer->switchSection (getObjFileLowering ().getTextSection ());
797
+ // Switch to the .text section.
798
+ OutStreamer->switchSection (getObjFileLowering ().getTextSection ());
799
+ }
797
800
}
798
801
799
802
void MipsAsmPrinter::emitInlineAsmStart () const {
0 commit comments