llvm.org GIT mirror llvm / fbee880
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 Dan Gohman 12 years ago
2 changed file(s) with 18 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2525 ///
2626 /// And, foo.cp would use:
2727 /// DEFINING_FILE_FOR(foo)
28 #ifdef __GNUC__
29 // If the `used' attribute is available, use it to create a variable
30 // with an initializer that will force the linking of the defining file.
2831 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
2932 namespace llvm { \
30 extern char name ## LinkVar; \
31 static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
33 extern const char name ## LinkVar; \
34 __attribute__((used)) static const char *const name ## LinkObj = \
35 &name ## LinkVar; \
3236 }
37 #else
38 // Otherwise use a constructor call.
39 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
40 namespace llvm { \
41 extern const char name ## LinkVar; \
42 static const IncludeFile name ## LinkObj ( &name ## LinkVar ); \
43 }
44 #endif
3345
3446 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
3547 /// be used in a .cpp file to define the name referenced in a header file that
3648 /// will cause linkage of the .cpp file. It should only be used at extern level.
37 #define DEFINING_FILE_FOR(name) namespace llvm { char name ## LinkVar; }
49 #define DEFINING_FILE_FOR(name) \
50 namespace llvm { const char name ## LinkVar = 0; }
3851
3952 namespace llvm {
4053
5669 /// static IncludeFile LinkMyModule(&LinkMyCodeStub);
5770 /// @brief Class to ensure linking of corresponding object file.
5871 struct IncludeFile {
59 IncludeFile(void *);
72 explicit IncludeFile(const void *);
6073 };
6174
6275 }
1616
1717 // This constructor is used to ensure linking of other modules. See the
1818 // llvm/System/IncludeFile.h header for details.
19 IncludeFile::IncludeFile(void*) {}
19 IncludeFile::IncludeFile(const void*) {}