From 0d236450aa050e259006826b14e39cf05eb2efa6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Oct 2006 00:35:50 +0000 Subject: [PATCH] implement DarwinTargetAsmInfo::getSectionForFunction, use it when outputting function bodies llvm-svn: 30733 --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 6 ++---- llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp | 14 +++++++++++++- llvm/lib/Target/PowerPC/PPCTargetAsmInfo.h | 7 ++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 4868b68435d7..252109a42127 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -422,19 +422,17 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { // Print out labels for the function. const Function *F = MF.getFunction(); + SwitchToTextSection(TAI->getSectionForFunction(*F), F); + switch (F->getLinkage()) { default: assert(0 && "Unknown linkage type!"); case Function::InternalLinkage: // Symbols default to internal. - SwitchToTextSection("\t.text", F); break; case Function::ExternalLinkage: - SwitchToTextSection("\t.text", F); O << "\t.globl\t" << CurrentFnName << "\n"; break; case Function::WeakLinkage: case Function::LinkOnceLinkage: - SwitchToTextSection( - ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F); O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.weak_definition\t" << CurrentFnName << "\n"; break; diff --git a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp index 03e9a01dd318..f767a4428d6a 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.cpp @@ -13,7 +13,7 @@ #include "PPCTargetAsmInfo.h" #include "PPCTargetMachine.h" - +#include "llvm/Function.h" using namespace llvm; DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM) { @@ -50,3 +50,15 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM) { DwarfRangesSection = ".section __DWARF,__debug_ranges"; DwarfMacInfoSection = ".section __DWARF,__debug_macinfo"; } + + +const char *DarwinTargetAsmInfo::getSectionForFunction(const Function &F) const{ + switch (F.getLinkage()) { + default: assert(0 && "Unknown linkage type!"); + case Function::ExternalLinkage: + case Function::InternalLinkage: return TextSection; + case Function::WeakLinkage: + case Function::LinkOnceLinkage: + return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions"; + } +} diff --git a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.h b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.h index d3c790c5fc97..6188862e9f70 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.h +++ b/llvm/lib/Target/PowerPC/PPCTargetAsmInfo.h @@ -23,9 +23,14 @@ namespace llvm { struct DarwinTargetAsmInfo : public TargetAsmInfo { DarwinTargetAsmInfo(const PPCTargetMachine &TM); + + /// getSectionForFunction - Return the section that we should emit the + /// specified function body into. This defaults to 'TextSection'. This + /// should most likely be overridden by the target to put linkonce/weak + /// functions into special sections. + virtual const char *getSectionForFunction(const Function &F) const; }; - } // namespace llvm #endif