[llvm-commits] [llvm] r56024 - in /llvm/trunk: include/llvm/Target/DarwinTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Target/DarwinTargetAsmInfo.cpp

Dale Johannesen dalej at apple.com
Tue Sep 9 15:29:14 PDT 2008


Author: johannes
Date: Tue Sep  9 17:29:13 2008
New Revision: 56024

URL: http://llvm.org/viewvc/llvm-project?rev=56024&view=rev
Log:
Move the uglier parts of deciding not to emit a
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.


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

Modified: llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h?rev=56024&r1=56023&r2=56024&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h Tue Sep  9 17:29:13 2008
@@ -22,6 +22,7 @@
   class GlobalValue;
   class GlobalVariable;
   class Type;
+  class Mangler;
 
   struct DarwinTargetAsmInfo: public virtual TargetAsmInfo {
     const Section* TextCoalSection;
@@ -33,6 +34,8 @@
     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;

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=56024&r1=56023&r2=56024&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Tue Sep  9 17:29:13 2008
@@ -100,6 +100,7 @@
   class CallInst;
   class GlobalValue;
   class Type;
+  class Mangler;
 
   class Section {
     friend class TargetAsmInfo;
@@ -220,9 +221,9 @@
     /// 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 @@
       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

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=56024&r1=56023&r2=56024&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Sep  9 17:29:13 2008
@@ -451,10 +451,9 @@
 }
 
 /// 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 @@
   
   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';

Modified: llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp?rev=56024&r1=56023&r2=56024&view=diff

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Tue Sep  9 17:29:13 2008
@@ -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 @@
                                       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);





More information about the llvm-commits mailing list