reimplement getPICLabelString as PrintPICBaseSymbol to eliminate std::string heap thrashing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74105 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-06-24 19:19:16 +00:00
parent 0de1fc4f41
commit b5299dd06a
2 changed files with 31 additions and 20 deletions

View File

@ -43,20 +43,17 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
static cl::opt<bool> 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 << ':';
}

View File

@ -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);