Move the uglier parts of deciding not to emit a
authorDale Johannesen <dalej@apple.com>
Tue, 9 Sep 2008 22:29:13 +0000 (22:29 +0000)
committerDale Johannesen <dalej@apple.com>
Tue, 9 Sep 2008 22:29:13 +0000 (22:29 +0000)
UsedDirective for some symbols in llvm.used into
Darwin-specific code.  I've decided LessPrivateGlobal
is potentially a useful abstraction and left it in
the target-independent area, with improved comment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56024 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/DarwinTargetAsmInfo.h
include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/DarwinTargetAsmInfo.cpp

index 0ed9b387037c3407ad9d83af160964362843d285..4abf4b7cfd112335a95f8adc5b7e0f59f565856b 100644 (file)
@@ -22,6 +22,7 @@ namespace llvm {
   class GlobalValue;
   class GlobalVariable;
   class Type;
+  class Mangler;
 
   struct DarwinTargetAsmInfo: public virtual TargetAsmInfo {
     const Section* TextCoalSection;
@@ -33,6 +34,8 @@ namespace llvm {
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
     virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
                                                SectionKind::Kind kind) const;
+    virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
+                                      Mangler *Mang) const;
     const Section* MergeableConstSection(const GlobalVariable *GV) const;
     const Section* MergeableConstSection(const Type *Ty) const;
     const Section* MergeableStringSection(const GlobalVariable *GV) const;
index bbb58527eb620e46202554ca9270b9ae46cb430e..589c9a6efc9b052f04be92297cd9a6f1c5522dea 100644 (file)
@@ -100,6 +100,7 @@ namespace llvm {
   class CallInst;
   class GlobalValue;
   class Type;
+  class Mangler;
 
   class Section {
     friend class TargetAsmInfo;
@@ -220,9 +221,9 @@ namespace llvm {
     /// have names in the .o file.  This is often "." or "L".
     const char *PrivateGlobalPrefix;      // Defaults to "."
     
-    /// LessPrivateGlobalPrefix - This prefix is used for some Objective C
-    /// metadata symbols that should be passed through the assembler but be
-    /// removed by the linker.  This is "l" on Darwin.
+    /// LessPrivateGlobalPrefix - This prefix is used for symbols that should
+    /// be passed through the assembler but be removed by the linker.  This
+    /// is "l" on Darwin, currently used for some ObjC metadata.
     const char *LessPrivateGlobalPrefix;      // Defaults to ""
     
     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
@@ -543,6 +544,13 @@ namespace llvm {
       return false;
     }
 
+    /// emitUsedDirectiveFor - This hook allows targets to selectively decide
+    /// not to emit the UsedDirective for some symbols in llvm.used.
+    virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
+                                      Mangler *Mang) const {
+      return (GV!=0);
+    }
+
     /// PreferredEHDataFormat - This hook allows the target to select data
     /// format used for encoding pointers in exception handling data. Reason is
     /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
index f041f3be56fcf32684c4290f339dcfc907aa1c0b..98f4b7d13cd96ffe0fac17ad4ac10ee0427c016b 100644 (file)
@@ -451,10 +451,9 @@ const GlobalValue * AsmPrinter::findGlobalValue(const Constant *CV) {
 }
 
 /// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
-/// global in the specified llvm.used list as being used with this directive.
-/// Internally linked data beginning with the PrivateGlobalPrefix or the
-/// LessPrivateGlobalPrefix does not have the directive emitted (this 
-/// occurs in ObjC metadata).
+/// global in the specified llvm.used list for which emitUsedDirectiveFor
+/// is true, as being used with this directive.
+
 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
   const char *Directive = TAI->getUsedDirective();
 
@@ -464,17 +463,7 @@ void AsmPrinter::EmitLLVMUsedList(Constant *List) {
   
   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
     const GlobalValue *GV = findGlobalValue(InitList->getOperand(i));
-    if (GV) {
-      if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
-          ((strlen(TAI->getPrivateGlobalPrefix()) != 0 &&
-            Mang->getValueName(GV)
-              .substr(0,strlen(TAI->getPrivateGlobalPrefix())) ==
-              TAI->getPrivateGlobalPrefix()) ||
-           (strlen(TAI->getLessPrivateGlobalPrefix()) != 0 &&
-            Mang->getValueName(GV)
-              .substr(0,strlen(TAI->getLessPrivateGlobalPrefix())) ==
-              TAI->getLessPrivateGlobalPrefix())))
-        continue;
+    if (TAI->emitUsedDirectiveFor(GV, Mang)) {
       O << Directive;
       EmitConstantValueOnly(InitList->getOperand(i));
       O << '\n';
index 749cb7179437c8e9c0329f9c881a10fd8254834e..2fc1d28d2b6b82ec80ae9da9bd8fd3c11cf97c7c 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Mangler.h"
 #include "llvm/Target/DarwinTargetAsmInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetData.h"
@@ -50,6 +51,26 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) {
                                       SectionFlags::Writeable);
 }
 
+/// emitUsedDirectiveFor - On Darwin, internally linked data beginning with
+/// the PrivateGlobalPrefix or the LessPrivateGlobalPrefix does not have the
+/// directive emitted (this occurs in ObjC metadata).
+
+bool
+DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
+                                          Mangler *Mang) const {
+  if (GV==0)
+    return false;
+  if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
+      ((strlen(getPrivateGlobalPrefix()) != 0 &&
+        Mang->getValueName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
+          getPrivateGlobalPrefix()) ||
+       (strlen(getLessPrivateGlobalPrefix()) != 0 &&
+        Mang->getValueName(GV).substr(0,strlen(getLessPrivateGlobalPrefix())) ==
+          getLessPrivateGlobalPrefix())))
+    return false;
+  return true;
+}
+
 const Section*
 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);