From 0c08d092049c025c9ccf7143e39f39dc4e30d6b4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 3 Apr 2010 22:28:33 +0000 Subject: [PATCH] asmstreamerize the .size directive for function bodies, force clients of printOffset to pass in a stream to print to. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100296 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/AsmPrinter.h | 7 +----- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 23 +++++++++++-------- lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp | 2 +- .../AsmPrinter/BlackfinAsmPrinter.cpp | 2 +- .../PowerPC/AsmPrinter/PPCAsmPrinter.cpp | 2 +- .../SystemZ/AsmPrinter/SystemZAsmPrinter.cpp | 6 ++--- lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp | 4 ++-- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 93dc97b94e5..79c2eb1c928 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -269,11 +269,6 @@ namespace llvm { /// void EmitInt32(int Value) const; - /// EmitInt64 - Emit a long long directive and value. - /// - void EmitInt64(uint64_t Value) const; - - /// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size /// in bytes of the directive is specified by Size and Hi/Lo specify the /// labels. This implicitly uses .set if it is available. @@ -349,7 +344,7 @@ namespace llvm { virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); /// printOffset - This is just convenient handler for printing offsets. - void printOffset(int64_t Offset) const; + void printOffset(int64_t Offset, raw_ostream &OS) const; /// isBlockOnlyReachableByFallthough - Return true if the basic block has /// exactly one predecessor and the control transfer mechanism between diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 4f45f6514d0..84128168fe2 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -461,7 +461,16 @@ void AsmPrinter::EmitFunctionBody() { // If the target wants a .size directive for the size of the function, emit // it. if (MAI->hasDotTypeDotSizeDirective()) { - O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; + // Create a symbol for the end of function, so we can get the size as + // difference between the function label and the temp label. + MCSymbol *FnEndLabel = OutContext.CreateTempSymbol(); + OutStreamer.EmitLabel(FnEndLabel); + + const MCExpr *SizeExp = + MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(FnEndLabel, OutContext), + MCSymbolRefExpr::Create(CurrentFnSym, OutContext), + OutContext); + OutStreamer.EmitELFSize(CurrentFnSym, SizeExp); } // Emit post-function debug information. @@ -922,12 +931,6 @@ void AsmPrinter::EmitInt32(int Value) const { OutStreamer.EmitIntValue(Value, 4, 0/*addrspace*/); } -/// EmitInt64 - Emit a long long directive and value. -/// -void AsmPrinter::EmitInt64(uint64_t Value) const { - OutStreamer.EmitIntValue(Value, 8, 0/*addrspace*/); -} - /// EmitLabelDifference - Emit something like ".long Hi-Lo" where the size /// in bytes of the directive is specified by Size and Hi/Lo specify the /// labels. This implicitly uses .set if it is available. @@ -1822,11 +1825,11 @@ void AsmPrinter::EmitVisibility(MCSymbol *Sym, unsigned Visibility) const { OutStreamer.EmitSymbolAttribute(Sym, Attr); } -void AsmPrinter::printOffset(int64_t Offset) const { +void AsmPrinter::printOffset(int64_t Offset, raw_ostream &OS) const { if (Offset > 0) - O << '+' << Offset; + OS << '+' << Offset; else if (Offset < 0) - O << Offset; + OS << Offset; } /// isBlockOnlyReachableByFallthough - Return true if the basic block has diff --git a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp index ba736e3c077..b4aa4a46e1c 100644 --- a/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp @@ -319,7 +319,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, O << ":upper16:"; O << *Mang->getSymbol(GV); - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); if (isCallOp && Subtarget->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_) diff --git a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp index 1c6d841cf3e..a6b48423a52 100644 --- a/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp +++ b/lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp @@ -86,7 +86,7 @@ void BlackfinAsmPrinter::printOperand(const MachineInstr *MI, int opNum) { return; case MachineOperand::MO_GlobalAddress: O << *Mang->getSymbol(MO.getGlobal()); - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); break; case MachineOperand::MO_ExternalSymbol: O << *GetExternalSymbolSymbol(MO.getSymbolName()); diff --git a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp index 5adefd39c51..7523b6a6171 100644 --- a/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp @@ -446,7 +446,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) { O << *SymToPrint; - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); return; } diff --git a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp index b29dfcdc984..349ac3e4b18 100644 --- a/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp +++ b/lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp @@ -101,7 +101,7 @@ void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum){ !GV->hasLocalLinkage()) O << "@PLT"; - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); return; } case MachineOperand::MO_ExternalSymbol: { @@ -155,7 +155,7 @@ void SystemZAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_' << MO.getIndex(); - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); break; case MachineOperand::MO_GlobalAddress: O << *Mang->getSymbol(MO.getGlobal()); @@ -177,7 +177,7 @@ void SystemZAsmPrinter::printOperand(const MachineInstr *MI, int OpNum, case SystemZII::MO_PLT: O << "@PLT"; break; } - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); } void SystemZAsmPrinter::printRIAddrOperand(const MachineInstr *MI, int OpNum, diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp index 66bb914edde..5f758db9456 100644 --- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp @@ -87,7 +87,7 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) { break; case MachineOperand::MO_ConstantPoolIndex: O << *GetCPISymbol(MO.getIndex()); - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); break; case MachineOperand::MO_GlobalAddress: { const GlobalValue *GV = MO.getGlobal(); @@ -136,7 +136,7 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) { O << *GVSym; else O << '(' << *GVSym << ')'; - printOffset(MO.getOffset()); + printOffset(MO.getOffset(), O); break; } case MachineOperand::MO_ExternalSymbol: {