From d7dec666cc9e9e5b226a498ac84caea3c37f2937 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 5 Feb 2015 19:06:45 +0000 Subject: [PATCH] Migrate the X86 AsmPrinter away from using the subtarget when dealing with module level emission. Currently this is using the Triple to determine, but eventually the logic should probably migrate to TLOF. llvm-svn: 228332 --- llvm/lib/Target/X86/X86AsmPrinter.cpp | 30 +++++++++++++++++---------- llvm/lib/Target/X86/X86AsmPrinter.h | 4 +--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index 907dcb5e700c..aff526ccb85d 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -47,6 +47,8 @@ using namespace llvm; /// runOnMachineFunction - Emit the function body. /// bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { + Subtarget = &MF.getSubtarget(); + SMShadowTracker.startFunction(MF); SetupMachineFunction(MF); @@ -505,13 +507,15 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, } void X86AsmPrinter::EmitStartOfAsmFile(Module &M) { - if (Subtarget->isTargetMachO()) + Triple TT(TM.getTargetTriple()); + + if (TT.isOSBinFormatMachO()) OutStreamer.SwitchSection(getObjFileLowering().getTextSection()); - if (Subtarget->isTargetCOFF()) { + if (TT.isOSBinFormatCOFF()) { // Emit an absolute @feat.00 symbol. This appears to be some kind of // compiler features bitfield read by link.exe. - if (!Subtarget->is64Bit()) { + if (TT.getArch() == Triple::x86) { MCSymbol *S = MMI->getContext().GetOrCreateSymbol(StringRef("@feat.00")); OutStreamer.BeginCOFFSymbolDef(S); OutStreamer.EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC); @@ -578,20 +582,21 @@ void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) { SmallString<128> Directive; raw_svector_ostream OS(Directive); StringRef Name = Sym->getName(); + Triple TT(TM.getTargetTriple()); - if (Subtarget->isTargetKnownWindowsMSVC()) + if (TT.isKnownWindowsMSVCEnvironment()) OS << " /EXPORT:"; else OS << " -export:"; - if ((Subtarget->isTargetWindowsGNU() || Subtarget->isTargetWindowsCygwin()) && + if ((TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) && (Name[0] == getDataLayout().getGlobalPrefix())) Name = Name.drop_front(); OS << Name; if (IsData) { - if (Subtarget->isTargetKnownWindowsMSVC()) + if (TT.isKnownWindowsMSVCEnvironment()) OS << ",DATA"; else OS << ",data"; @@ -602,7 +607,9 @@ void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) { } void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { - if (Subtarget->isTargetMachO()) { + Triple TT(TM.getTargetTriple()); + + if (TT.isOSBinFormatMachO()) { // All darwin targets use mach-o. MachineModuleInfoMachO &MMIMacho = MMI->getObjFileInfo(); @@ -676,13 +683,14 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); } - if (Subtarget->isTargetKnownWindowsMSVC() && MMI->usesVAFloatArgument()) { - StringRef SymbolName = Subtarget->is64Bit() ? "_fltused" : "__fltused"; + if (TT.isKnownWindowsMSVCEnvironment() && MMI->usesVAFloatArgument()) { + StringRef SymbolName = + (TT.getArch() == Triple::x86_64) ? "_fltused" : "__fltused"; MCSymbol *S = MMI->getContext().GetOrCreateSymbol(SymbolName); OutStreamer.EmitSymbolAttribute(S, MCSA_Global); } - if (Subtarget->isTargetCOFF()) { + if (TT.isOSBinFormatCOFF()) { // Necessary for dllexport support std::vector DLLExportedFns, DLLExportedGlobals; @@ -718,7 +726,7 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { } } - if (Subtarget->isTargetELF()) { + if (TT.isOSBinFormatELF()) { const TargetLoweringObjectFileELF &TLOFELF = static_cast(getObjFileLowering()); diff --git a/llvm/lib/Target/X86/X86AsmPrinter.h b/llvm/lib/Target/X86/X86AsmPrinter.h index daa14c00660f..3a3cbadc365d 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.h +++ b/llvm/lib/Target/X86/X86AsmPrinter.h @@ -87,9 +87,7 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter { public: explicit X86AsmPrinter(TargetMachine &TM, std::unique_ptr Streamer) - : AsmPrinter(TM, std::move(Streamer)), SM(*this), SMShadowTracker(TM) { - Subtarget = &TM.getSubtarget(); - } + : AsmPrinter(TM, std::move(Streamer)), SM(*this), SMShadowTracker(TM) {} const char *getPassName() const override { return "X86 Assembly / Object Emitter";