aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-03-21 23:38:23 +0000
committerDan Gohman <gohman@apple.com>2008-03-21 23:38:23 +0000
commitfbee880cfbf4e63d6d2ad5c71c85ff8ead2074c4 (patch)
tree9c8a36e34af92cf6fa2eadf89a437f11c436c142
parent4145bd509d0be0ea2ebea693a7ad15948480d982 (diff)
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%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48665 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/System/IncludeFile.h21
-rw-r--r--lib/System/IncludeFile.cpp2
2 files changed, 18 insertions, 5 deletions
diff --git a/include/llvm/System/IncludeFile.h b/include/llvm/System/IncludeFile.h
index 7617373ad1..6103e44e4c 100644
--- a/include/llvm/System/IncludeFile.h
+++ b/include/llvm/System/IncludeFile.h
@@ -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 @@ namespace llvm {
/// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
/// @brief Class to ensure linking of corresponding object file.
struct IncludeFile {
- IncludeFile(void *);
+ explicit IncludeFile(const void *);
};
}
diff --git a/lib/System/IncludeFile.cpp b/lib/System/IncludeFile.cpp
index d927e15959..8258d40326 100644
--- a/lib/System/IncludeFile.cpp
+++ b/lib/System/IncludeFile.cpp
@@ -17,4 +17,4 @@ using namespace llvm;
// 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*) {}