@@ -734,70 +734,73 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
734
734
}
735
735
736
736
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.
754
737
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
- }
770
738
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 ));
775
777
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 ();
781
783
782
- // TODO: handle O64 ABI
784
+ // TODO: handle O64 ABI
783
785
784
- TS.updateABIInfo (STI);
786
+ TS.updateABIInfo (STI);
785
787
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 ();
792
794
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 ();
798
800
799
- // Switch to the .text section.
800
- OutStreamer->switchSection (getObjFileLowering ().getTextSection ());
801
+ // Switch to the .text section.
802
+ OutStreamer->switchSection (getObjFileLowering ().getTextSection ());
803
+ }
801
804
}
802
805
803
806
void MipsAsmPrinter::emitInlineAsmStart () const {
0 commit comments