From cf1ed75f7ffae47c50f9030d56397ab6ee324253 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 11 Sep 2009 04:28:13 +0000 Subject: [PATCH] rearrange some code, export a SmallString version of DecorateCygMingName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81502 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../X86/AsmPrinter/X86ATTAsmPrinter.cpp | 58 +++++++++---------- lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h | 1 + lib/Target/X86/AsmPrinter/X86MCInstLower.cpp | 46 ++++++++------- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index c8e9efd468b..445cc13ec24 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -23,8 +23,6 @@ #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/Type.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/Assembly/Writer.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSectionMachO.h" @@ -36,6 +34,8 @@ #include "llvm/MC/MCAsmInfo.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Statistic.h" using namespace llvm; STATISTIC(EmittedInsts, "Number of machine instrs printed"); @@ -94,23 +94,23 @@ static X86MachineFunctionInfo calculateFunctionInfo(const Function *F, /// DecorateCygMingName - Query FunctionInfoMap and use this information for /// various name decorations for Cygwin and MingW. -void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name, +void X86ATTAsmPrinter::DecorateCygMingName(SmallVectorImpl &Name, const GlobalValue *GV) { assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw"); const Function *F = dyn_cast(GV); if (!F) return; - + // Save function name for later type emission. if (F->isDeclaration()) - CygMingStubs.insert(Name); + CygMingStubs.insert(StringRef(Name.data(), Name.size())); // We don't want to decorate non-stdcall or non-fastcall functions right now CallingConv::ID CC = F->getCallingConv(); if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall) return; - - + + const X86MachineFunctionInfo *Info; FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F); @@ -121,32 +121,30 @@ void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name, } else { Info = &info_item->second; } - + + if (Info->getDecorationStyle() == None) return; const FunctionType *FT = F->getFunctionType(); - switch (Info->getDecorationStyle()) { - case None: - break; - case StdCall: - // "Pure" variadic functions do not receive @0 suffix. - if (!FT->isVarArg() || (FT->getNumParams() == 0) || - (FT->getNumParams() == 1 && F->hasStructRetAttr())) - Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); - break; - case FastCall: - // "Pure" variadic functions do not receive @0 suffix. - if (!FT->isVarArg() || (FT->getNumParams() == 0) || - (FT->getNumParams() == 1 && F->hasStructRetAttr())) - Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); - if (Name[0] == '_') { + // "Pure" variadic functions do not receive @0 suffix. + if (!FT->isVarArg() || FT->getNumParams() == 0 || + (FT->getNumParams() == 1 && F->hasStructRetAttr())) + raw_svector_ostream(Name) << '@' << Info->getBytesToPopOnReturn(); + + if (Info->getDecorationStyle() == FastCall) { + if (Name[0] == '_') Name[0] = '@'; - } else { - Name = '@' + Name; - } - break; - default: - llvm_unreachable("Unsupported DecorationStyle"); - } + else + Name.insert(Name.begin(), '@'); + } +} + +/// DecorateCygMingName - Query FunctionInfoMap and use this information for +/// various name decorations for Cygwin and MingW. +void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name, + const GlobalValue *GV) { + SmallString<128> NameStr(Name.begin(), Name.end()); + DecorateCygMingName(NameStr, GV); + Name.assign(NameStr.begin(), NameStr.end()); } void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) { diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h index 32411db6b85..0dd35a7aa36 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h @@ -236,6 +236,7 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { FMFInfoMap FunctionInfoMap; void DecorateCygMingName(std::string &Name, const GlobalValue *GV); + void DecorateCygMingName(SmallVectorImpl &Name, const GlobalValue *GV); }; } // end namespace llvm diff --git a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp index e27c83b5ddb..72ac0724758 100644 --- a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp +++ b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp @@ -39,26 +39,6 @@ MCSymbol *X86ATTAsmPrinter::GetPICBaseSymbol() { } -static void lower_subreg32(MCInst *MI, unsigned OpNo) { - // Convert registers in the addr mode according to subreg32. - unsigned Reg = MI->getOperand(OpNo).getReg(); - if (Reg != 0) - MI->getOperand(OpNo).setReg(getX86SubSuperRegister(Reg, MVT::i32)); -} - - -static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) { - // Convert registers in the addr mode according to subreg64. - for (unsigned i = 0; i != 4; ++i) { - if (!MI->getOperand(OpNo+i).isReg()) continue; - - unsigned Reg = MI->getOperand(OpNo+i).getReg(); - if (Reg == 0) continue; - - MI->getOperand(OpNo+i).setReg(getX86SubSuperRegister(Reg, MVT::i64)); - } -} - /// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an /// MCOperand. MCSymbol *X86ATTAsmPrinter::GetGlobalAddressSymbol(const MachineOperand &MO) { @@ -264,6 +244,28 @@ MCOperand X86ATTAsmPrinter::LowerSymbolOperand(const MachineOperand &MO, return MCOperand::CreateExpr(Expr); } + + +static void lower_subreg32(MCInst *MI, unsigned OpNo) { + // Convert registers in the addr mode according to subreg32. + unsigned Reg = MI->getOperand(OpNo).getReg(); + if (Reg != 0) + MI->getOperand(OpNo).setReg(getX86SubSuperRegister(Reg, MVT::i32)); +} + +static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) { + // Convert registers in the addr mode according to subreg64. + for (unsigned i = 0; i != 4; ++i) { + if (!MI->getOperand(OpNo+i).isReg()) continue; + + unsigned Reg = MI->getOperand(OpNo+i).getReg(); + if (Reg == 0) continue; + + MI->getOperand(OpNo+i).setReg(getX86SubSuperRegister(Reg, MVT::i64)); + } +} + + void X86ATTAsmPrinter:: printInstructionThroughMCStreamer(const MachineInstr *MI) { MCInst TmpInst; @@ -345,9 +347,9 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) { TmpInst.addOperand(MCOp); } + // Handle a few special cases to eliminate operand modifiers. switch (TmpInst.getOpcode()) { - case X86::LEA64_32r: - // Handle the 'subreg rewriting' for the lea64_32mem operand. + case X86::LEA64_32r: // Handle 'subreg rewriting' for the lea64_32mem operand. lower_lea64_32mem(&TmpInst, 1); break; case X86::MOV16r0: