From 9b4aaef9d4b680e007e3aac1034558ab57c4abfd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 24 Jun 2009 19:19:16 +0000 Subject: [PATCH] reimplement getPICLabelString as PrintPICBaseSymbol to eliminate std::string heap thrashing. llvm-svn: 74105 --- .../X86/AsmPrinter/X86ATTAsmPrinter.cpp | 49 +++++++++++-------- .../Target/X86/AsmPrinter/X86ATTAsmPrinter.h | 2 + 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index a7e8464e68d7..a3618751fb95 100644 --- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -43,20 +43,17 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed"); static cl::opt NewAsmPrinter("experimental-asm-printer", cl::Hidden); -static std::string getPICLabelString(unsigned FnNum, - const TargetAsmInfo *TAI, - const X86Subtarget* Subtarget) { - std::string label; + +void X86ATTAsmPrinter::PrintPICBaseSymbol() const { if (Subtarget->isTargetDarwin()) - label = "\"L" + utostr_32(FnNum) + "$pb\""; + O << "\"L" << getFunctionNumber() << "$pb\""; else if (Subtarget->isTargetELF()) - label = ".Lllvm$" + utostr_32(FnNum) + "." "$piclabel"; + O << ".Lllvm$" << getFunctionNumber() << "." "$piclabel"; else assert(0 && "Don't know how to print PIC label!\n"); - - return label; } + static X86MachineFunctionInfo calculateFunctionInfo(const Function *F, const TargetData *TD) { X86MachineFunctionInfo Info; @@ -403,7 +400,7 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) { if (shouldPrintPLT(TM, Subtarget)) { std::string GOTName(TAI->getGlobalPrefix()); GOTName+="_GLOBAL_OFFSET_TABLE_"; - if (Name == GOTName) + if (Name == GOTName) { // HACK! Emit extra offset to PC during printing GOT offset to // compensate for the size of popl instruction. The resulting code // should look like: @@ -411,8 +408,10 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) { // piclabel: // popl %some_register // addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register - O << " + [.-" - << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << ']'; + O << " + [.-"; + PrintPICBaseSymbol(); + O << ']'; + } O << "@PLT"; } @@ -538,8 +537,10 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, O << Name; } - if (TM.getRelocationModel() == Reloc::PIC_) - O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget); + if (TM.getRelocationModel() == Reloc::PIC_) { + O << '-'; + PrintPICBaseSymbol(); + } } else { if (GV->hasDLLImportLinkage()) O << "__imp_"; @@ -626,7 +627,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, if (shouldPrintPLT(TM, Subtarget)) { std::string GOTName(TAI->getGlobalPrefix()); GOTName+="_GLOBAL_OFFSET_TABLE_"; - if (Name == GOTName) + if (Name == GOTName) { // HACK! Emit extra offset to PC during printing GOT offset to // compensate for the size of popl instruction. The resulting code // should look like: @@ -634,8 +635,10 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, // piclabel: // popl %some_register // addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register - O << " + [.-" - << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << ']'; + O << " + [.-"; + PrintPICBaseSymbol(); + O << ']'; + } } if (needCloseParen) @@ -737,13 +740,19 @@ void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid, if (Subtarget->isPICStyleRIPRel()) O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_' << uid << '\n'; - else - O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << '\n'; + else { + O << '-'; + PrintPICBaseSymbol(); + O << '\n'; + } } + void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { - std::string label = getPICLabelString(getFunctionNumber(), TAI, Subtarget); - O << label << '\n' << label << ':'; + PrintPICBaseSymbol(); + O << '\n'; + PrintPICBaseSymbol(); + O << ':'; } diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h index 24cd601b1feb..8bcf43cd6a2e 100644 --- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h +++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h @@ -187,6 +187,8 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { void printPICLabel(const MachineInstr *MI, unsigned Op); void printModuleLevelGV(const GlobalVariable* GVar); + void PrintPICBaseSymbol() const; + bool runOnMachineFunction(MachineFunction &F); void emitFunctionHeader(const MachineFunction &MF);