move ExtWeakSymbols to AsmPrinter
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 18 Dec 2006 03:37:18 +0000 (03:37 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 18 Dec 2006 03:37:18 +0000 (03:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32648 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter.cpp
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h

index 59d5b153ea79f89e0f15fd788aba56eec56588b0..2f54d6de74257f2d5c3778927b3e223e969b59de 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Support/DataTypes.h"
+#include <set>
 
 namespace llvm {
   class Constant;
@@ -39,6 +40,10 @@ namespace llvm {
     ///
     unsigned FunctionNumber;
 
+  protected:
+    // Necessary for external weak linkage support
+    std::set<const GlobalValue*> ExtWeakSymbols;
+
   public:
     /// Output stream on which we're printing assembly code.
     ///
index 8757d303ec80a8de23c215cc8df071cc9b5cd8f1..833ed28f085c4d48dd5d01ef5dd5564f4fd9f239 100644 (file)
@@ -106,6 +106,18 @@ bool AsmPrinter::doInitialization(Module &M) {
 }
 
 bool AsmPrinter::doFinalization(Module &M) {
+  if (TAI->getWeakRefDirective()) {
+    if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+      SwitchToDataSection("");
+
+    for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
+         e = ExtWeakSymbols.end(); i != e; ++i) {
+      const GlobalValue *GV = *i;
+      std::string Name = Mang->getValueName(GV);
+      O << TAI->getWeakRefDirective() << Name << "\n";
+    }
+  }
+
   delete Mang; Mang = 0;
   return false;
 }
index c30c593084b6bdcc903586ba80d20bfb959ab469..291073e04cda137981dae49139fe2b39ab51c74b 100644 (file)
@@ -62,8 +62,6 @@ namespace {
       : AsmPrinter(O, TM, T) {
     }
 
-    std::set<std::string> ExtWeakSymbols;
-
     /// We name each basic block in a Function with a unique number, so
     /// that we can consistently refer to them later. This is cleared
     /// at the beginning of each call to runOnMachineFunction().
@@ -246,7 +244,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     std::string Name = Mang->getValueName(GV);
     O << Name;
     if (GV->hasExternalWeakLinkage()) {
-      ExtWeakSymbols.insert(Name);
+      ExtWeakSymbols.insert(GV);
     }
   }
     break;
@@ -337,13 +335,6 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
     }
   }
 
-  if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
-    SwitchToDataSection("");
-  for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
-         e = ExtWeakSymbols.end(); i != e; ++i) {
-    O << TAI->getWeakRefDirective() << *i << "\n";
-  }
-
   AsmPrinter::doFinalization(M);
   return false; // success
 }
index 0659f03365319823f2b5b91213385bfd0ffd029d..1ffd65265f17af334f52bfe71b5f8201d450bf7b 100644 (file)
@@ -50,9 +50,6 @@ namespace {
   struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
     std::set<std::string> FnStubs, GVStubs;
     const PPCSubtarget &Subtarget;
-    
-    // Necessary for external weak linkage support
-    std::set<std::string> ExtWeakSymbols;
 
     PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
       : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) {
@@ -162,7 +159,7 @@ namespace {
             FnStubs.insert(Name);
             O << "L" << Name << "$stub";
             if (GV->hasExternalWeakLinkage())
-              ExtWeakSymbols.insert(Name);
+              ExtWeakSymbols.insert(GV);
             return;
           }
         }
@@ -337,7 +334,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
     O << Name;
     
     if (GV->hasExternalWeakLinkage())
-      ExtWeakSymbols.insert(Name);
+      ExtWeakSymbols.insert(GV);
     return;
   }
 
@@ -658,22 +655,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
       // reference!
       if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
         if (GV->hasExternalWeakLinkage())
-          ExtWeakSymbols.insert(Mang->getValueName(GV));
+          ExtWeakSymbols.insert(GV);
 
       EmitGlobalConstant(C);
       O << '\n';
     }
   }
 
-  if (TAI->getWeakRefDirective()) {
-    if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
-      SwitchToDataSection("");
-    for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
-         e = ExtWeakSymbols.end(); i != e; ++i) {
-      O << TAI->getWeakRefDirective() << *i << "\n";
-    }
-  }
-
   bool isPPC64 = TD->getPointerSizeInBits() == 64;
 
   // Output stubs for dynamically-linked functions
index 62f24db4e82db5452d3535600510ea258ab84343..f9645b80d280f1c36bfcce48784a866afe9003a8 100755 (executable)
@@ -257,7 +257,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
     }
 
     if (GV->hasExternalWeakLinkage())
-      ExtWeakSymbols.insert(Name);
+      ExtWeakSymbols.insert(GV);
     
     int Offset = MO.getOffset();
     if (Offset > 0)
index 021e55c5c5c0f5f53722a063955b1fe04e515a63..578e1aa9785ca8756835191a689df50306003c89 100644 (file)
@@ -250,7 +250,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       // reference!
       if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
         if (GV->hasExternalWeakLinkage())
-          ExtWeakSymbols.insert(Mang->getValueName(GV));
+          ExtWeakSymbols.insert(GV);
 
       EmitGlobalConstant(C);
       O << '\n';
@@ -278,15 +278,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     O << "\t.ascii \" -export:" << *i << "\"\n";
   }    
 
-  if (TAI->getWeakRefDirective()) {
-    if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
-      SwitchToDataSection("");
-    for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
-         e = ExtWeakSymbols.end(); i != e; ++i) {
-      O << TAI->getWeakRefDirective() << *i << "\n";
-    }
-  }
-  
   if (Subtarget->isTargetDarwin()) {
     SwitchToDataSection("");
 
index b9b643b701ead5a2c40af6b994f51bfd6e56a372..af182fab259f3e94605bea5f7596ea9cd401ad71 100755 (executable)
@@ -86,9 +86,6 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
   // Necessary for dllexport support
   std::set<std::string> DLLExportedFns, DLLExportedGVs;
 
-  // Necessary for external weak linkage support
-  std::set<std::string> ExtWeakSymbols;
-  
   inline static bool isScale(const MachineOperand &MO) {
     return MO.isImmediate() &&
           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||