Implement getSectionForFunction, use it when printing function body.
authorChris Lattner <sabre@nondot.org>
Thu, 5 Oct 2006 02:43:52 +0000 (02:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 5 Oct 2006 02:43:52 +0000 (02:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30737 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.h
lib/Target/X86/X86IntelAsmPrinter.cpp
lib/Target/X86/X86IntelAsmPrinter.h
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h

index 6f34ca5c1341584d309587ef52e7de88468fa6af..85ba0f40e6135d395e5435aa09da18872ec4b45f 100755 (executable)
 #include <iostream>
 using namespace llvm;
 
+/// getSectionForFunction - Return the section that we should emit the
+/// specified function body into.
+std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
+  switch (F.getLinkage()) {
+  default: assert(0 && "Unknown linkage type!");
+  case Function::InternalLinkage: 
+  case Function::DLLExportLinkage:
+  case Function::ExternalLinkage:
+    return TAI->getTextSection();
+  case Function::WeakLinkage:
+  case Function::LinkOnceLinkage:
+    if (Subtarget->isTargetDarwin()) {
+      return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
+    } else if (Subtarget->isTargetCygwin()) {
+      return "\t.section\t.llvm.linkonce.t." + CurrentFnName + ",\"ax\"\n";
+    } else {
+      return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
+             ",\"ax\",@progbits\n";
+    }
+  }
+}
+
 /// runOnMachineFunction - This uses the printMachineInstruction()
 /// method to print assembly for each instruction.
 ///
@@ -53,38 +75,30 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   X86SharedAsmPrinter::decorateName(CurrentFnName, F);
 
+  SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
+  
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
   case Function::InternalLinkage:  // Symbols default to internal.
-    SwitchToTextSection(TAI->getTextSection(), F);
     EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
     break;
   case Function::DLLExportLinkage:
     DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
     //FALLS THROUGH
   case Function::ExternalLinkage:
-    SwitchToTextSection(TAI->getTextSection(), F);
     EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
     O << "\t.globl\t" << CurrentFnName << "\n";    
     break;
   case Function::WeakLinkage:
   case Function::LinkOnceLinkage:
     if (Subtarget->isTargetDarwin()) {
-      SwitchToTextSection(
-                ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
       O << "\t.globl\t" << CurrentFnName << "\n";
       O << "\t.weak_definition\t" << CurrentFnName << "\n";
     } else if (Subtarget->isTargetCygwin()) {
       EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
-      O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
-        << ",\"ax\"\n";
-      SwitchToTextSection("", F);
       O << "\t.weak " << CurrentFnName << "\n";
     } else {
       EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
-      O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
-        << ",\"ax\",@progbits\n";
-      SwitchToTextSection("", F);
       O << "\t.weak " << CurrentFnName << "\n";
     }
     break;
index 167e812f4d441721f4182ce4430b7da05eb55534..8955fc35961d7f3d1aff64c57d39db47134ccbdf 100755 (executable)
@@ -76,6 +76,10 @@ struct X86ATTAsmPrinter : public X86SharedAsmPrinter {
                          const char *Modifier=NULL);
   void printPICLabel(const MachineInstr *MI, unsigned Op);
   bool runOnMachineFunction(MachineFunction &F);
+  
+  /// getSectionForFunction - Return the section that we should emit the
+  /// specified function body into.
+  virtual std::string getSectionForFunction(const Function &F) const;
 };
 
 } // end namespace llvm
index 705488a6c2f356e47704d692500a41897a948186..4e833bdd3dac5ff70a8804de4a879382e84709e0 100755 (executable)
 #include "llvm/Target/TargetOptions.h"
 using namespace llvm;
 
+std::string X86IntelAsmPrinter::getSectionForFunction(const Function &F) const {
+  // Intel asm always emits functions to _text.
+  return "_text";
+}
+
 /// runOnMachineFunction - This uses the printMachineInstruction()
 /// method to print assembly for each instruction.
 ///
@@ -46,10 +51,11 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   X86SharedAsmPrinter::decorateName(CurrentFnName, F);
 
+  SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
+
   switch (F->getLinkage()) {
   default: assert(0 && "Unsupported linkage type!");
   case Function::InternalLinkage:
-    SwitchToTextSection("_text", F);
     EmitAlignment(4);
     break;    
   case Function::DLLExportLinkage:
@@ -57,7 +63,6 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     //FALLS THROUGH
   case Function::ExternalLinkage:
     O << "\tpublic " << CurrentFnName << "\n";
-    SwitchToTextSection("_text", F);
     EmitAlignment(4);
     break;    
   }
index 110420bb74909b167c9aabe40634dab3d4851f79..9ad11ffc22ae8c1c7109cd7d87ce4af8eb9a7a3b 100755 (executable)
@@ -99,6 +99,10 @@ struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
   bool runOnMachineFunction(MachineFunction &F);
   bool doInitialization(Module &M);
   bool doFinalization(Module &M);
+  
+  /// getSectionForFunction - Return the section that we should emit the
+  /// specified function body into.
+  virtual std::string getSectionForFunction(const Function &F) const;
 
   virtual void EmitString(const ConstantArray *CVA) const;
 };
index 581feb7542aaf4d5b445300b4566611c79b86746..cf0854851902302c1deaaddfb26c357dae90c4ae 100644 (file)
@@ -20,7 +20,7 @@ using namespace llvm;
 X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
   
-  //FIXME - Should to be simplified.
+  // FIXME - Should be simplified.
    
   switch (Subtarget->TargetType) {
   case X86Subtarget::isDarwin:
@@ -31,7 +31,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
     PrivateGlobalPrefix = "L";     // Marker for constant pool idxs
     ConstantPoolSection = "\t.const\n";
-    JumpTableDataSection = "\t.const\n"; // FIXME: depends on PIC mode
+    JumpTableDataSection = "\t.const\n";
     FourByteConstantSection = "\t.literal4\n";
     EightByteConstantSection = "\t.literal8\n";
     if (Subtarget->is64Bit())
@@ -97,3 +97,4 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     SectionEndDirectiveSuffix = "\tends\n";
   }
 }
+
index a5401da602bf34601b39884166aff59e407fd203..ac0505f71604362a245b9f4aede2596fd896780d 100644 (file)
@@ -24,8 +24,6 @@ namespace llvm {
   struct X86TargetAsmInfo : public TargetAsmInfo {
     X86TargetAsmInfo(const X86TargetMachine &TM);
   };
-
-
 } // namespace llvm
 
 #endif