[llvm-commits] [llvm] r48665 - in /llvm/trunk: include/llvm/System/IncludeFile.h lib/System/IncludeFile.cpp

Dan Gohman gohman at apple.com
Fri Mar 21 16:38:23 PDT 2008


Author: djg
Date: Fri Mar 21 18:38:23 2008
New Revision: 48665

URL: http://llvm.org/viewvc/llvm-project?rev=48665&view=rev
Log:
Specialize FORCE_DEFINING_FILE_TO_BE_LINKED using a GCC trick
to avoid using constructor calls for static objects. This reduces
the number of objects requiring static constructors in a typical
LLVM build by around 20%.

Modified:
    llvm/trunk/include/llvm/System/IncludeFile.h
    llvm/trunk/lib/System/IncludeFile.cpp

Modified: llvm/trunk/include/llvm/System/IncludeFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/IncludeFile.h?rev=48665&r1=48664&r2=48665&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/IncludeFile.h (original)
+++ llvm/trunk/include/llvm/System/IncludeFile.h Fri Mar 21 18:38:23 2008
@@ -26,16 +26,29 @@
 /// 
 /// And, foo.cp would use:<br/>
 /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
+#ifdef __GNUC__
+// If the `used' attribute is available, use it to create a variable
+// with an initializer that will force the linking of the defining file.
 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
   namespace llvm { \
-    extern char name ## LinkVar; \
-    static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
+    extern const char name ## LinkVar; \
+    __attribute__((used)) static const char *const name ## LinkObj = \
+      &name ## LinkVar; \
   } 
+#else
+// Otherwise use a constructor call.
+#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
+  namespace llvm { \
+    extern const char name ## LinkVar; \
+    static const IncludeFile name ## LinkObj ( &name ## LinkVar ); \
+  } 
+#endif
 
 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
 /// be used in a .cpp file to define the name referenced in a header file that
 /// will cause linkage of the .cpp file. It should only be used at extern level.
-#define DEFINING_FILE_FOR(name) namespace llvm { char name ## LinkVar; }
+#define DEFINING_FILE_FOR(name) \
+  namespace llvm { const char name ## LinkVar = 0; }
 
 namespace llvm {
 
@@ -57,7 +70,7 @@
 /// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
 /// @brief Class to ensure linking of corresponding object file.
 struct IncludeFile {
-  IncludeFile(void *);
+  explicit IncludeFile(const void *);
 };
 
 }

Modified: llvm/trunk/lib/System/IncludeFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/IncludeFile.cpp?rev=48665&r1=48664&r2=48665&view=diff

==============================================================================
--- llvm/trunk/lib/System/IncludeFile.cpp (original)
+++ llvm/trunk/lib/System/IncludeFile.cpp Fri Mar 21 18:38:23 2008
@@ -17,4 +17,4 @@
 
 // This constructor is used to ensure linking of other modules. See the
 // llvm/System/IncludeFile.h header for details. 
-IncludeFile::IncludeFile(void*) {}
+IncludeFile::IncludeFile(const void*) {}





More information about the llvm-commits mailing list