blob: 1266718ec00b691c6057b157387ab990fb4ea898 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===---------------------------------------------------------------------===//
2// Random Notes
3//===---------------------------------------------------------------------===//
4
5C90/C99/C++ Comparisons:
6http://david.tribble.com/text/cdiffs.htm
7
8//===---------------------------------------------------------------------===//
9Extensions:
10
11 * "#define_target X Y"
12 This preprocessor directive works exactly the same was as #define, but it
13 notes that 'X' is a target-specific preprocessor directive. When used, a
14 diagnostic is emitted indicating that the translation unit is non-portable.
15
16 If a target-define is #undef'd before use, no diagnostic is emitted. If 'X'
17 were previously a normal #define macro, the macro is tainted. If 'X' is
18 subsequently #defined as a non-target-specific define, the taint bit is
19 cleared.
20
21 * "#define_other_target X"
22 The preprocessor directive takes a single identifier argument. It notes
23 that this identifier is a target-specific #define for some target other than
24 the current one. Use of this identifier will result in a diagnostic.
25
26 If 'X' is later #undef'd or #define'd, the taint bit is cleared. If 'X' is
27 already defined, X is marked as a target-specific define.
28
29//===---------------------------------------------------------------------===//
30
31To time GCC preprocessing speed without output, use:
32 "time gcc -MM file"
33This is similar to -Eonly.
34
35
36//===---------------------------------------------------------------------===//
37
38 C++ Template Instantiation benchmark:
39 http://users.rcn.com/abrahams/instantiation_speed/index.html
40
41//===---------------------------------------------------------------------===//
42
43TODO: File Manager Speedup:
44
45 We currently do a lot of stat'ing for files that don't exist, particularly
46 when lots of -I paths exist (e.g. see the <iostream> example, check for
47 failures in stat in FileManager::getFile). It would be far better to make
48 the following changes:
49 1. FileEntry contains a sys::Path instead of a std::string for Name.
50 2. sys::Path contains timestamp and size, lazily computed. Eliminate from
51 FileEntry.
52 3. File UIDs are created on request, not when files are opened.
53 These changes make it possible to efficiently have FileEntry objects for
54 files that exist on the file system, but have not been used yet.
55
56 Once this is done:
57 1. DirectoryEntry gets a boolean value "has read entries". When false, not
58 all entries in the directory are in the file mgr, when true, they are.
59 2. Instead of stat'ing the file in FileManager::getFile, check to see if
60 the dir has been read. If so, fail immediately, if not, read the dir,
61 then retry.
62 3. Reading the dir uses the getdirentries syscall, creating an FileEntry
63 for all files found.
64
65//===---------------------------------------------------------------------===//
66
67TODO: Fast #Import:
68
69 * Get frameworks that don't use #import to do so, e.g.
70 DirectoryService, AudioToolbox, CoreFoundation, etc. Why not using #import?
71 Because they work in C mode? C has #import.
72 * Have the lexer return a token for #import instead of handling it itself.
73 - Create a new preprocessor object with no external state (no -D/U options
74 from the command line, etc). Alternatively, keep track of exactly which
75 external state is used by a #import: declare it somehow.
76 * When having reading a #import file, keep track of whether we have (and/or
77 which) seen any "configuration" macros. Various cases:
78 - Uses of target args (__POWERPC__, __i386): Header has to be parsed
79 multiple times, per-target. What about #ifndef checks? How do we know?
80 - "Configuration" preprocessor macros not defined: POWERPC, etc. What about
81 things like __STDC__ etc? What is and what isn't allowed.
82 * Special handling for "umbrella" headers, which just contain #import stmts:
83 - Cocoa.h/AppKit.h - Contain pointers to digests instead of entire digests
84 themselves? Foundation.h isn't pure umbrella!
85 * Frameworks digests:
86 - Can put "digest" of a framework-worth of headers into the framework
87 itself. To open AppKit, just mmap
88 /System/Library/Frameworks/AppKit.framework/"digest", which provides a
89 symbol table in a well defined format. Lazily unstream stuff that is
90 needed. Contains declarations, macros, and debug information.
91 - System frameworks ship with digests. How do we handle configuration
92 information? How do we handle stuff like:
93 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
94 which guards a bunch of decls? Should there be a couple of default
95 configs, then have the UI fall back to building/caching its own?
96 - GUI automatically builds digests when UI is idle, both of system
97 frameworks if they aren't not available in the right config, and of app
98 frameworks.
99 - GUI builds dependence graph of frameworks/digests based on #imports. If a
100 digest is out date, dependent digests are automatically invalidated.
101
102 * New constraints on #import for objc-v3:
103 - #imported file must not define non-inline function bodies.
104 - Alternatively, they can, and these bodies get compiled/linked *once*
105 per app into a dylib. What about building user dylibs?
106 - Restrictions on ObjC grammar: can't #import the body of a for stmt or fn.
107 - Compiler must detect and reject these cases.
108 - #defines defined within a #import have two behaviors:
109 - By default, they escape the header. These macros *cannot* be #undef'd
110 by other code: this is enforced by the front-end.
111 - Optionally, user can specify what macros escape (whitelist) or can use
112 #undef.
113
114//===---------------------------------------------------------------------===//
115
116TODO: New language feature: Configuration queries:
117 - Instead of #ifdef __POWERPC__, use "if (strcmp(`cpu`, __POWERPC__))", or
118 some other, better, syntax.
119 - Use it to increase the number of "architecture-clean" #import'd files,
120 allowing a single index to be used for all fat slices.
121
122//===---------------------------------------------------------------------===//
Ted Kremenekf4c45b02007-12-03 22:26:16 +0000123// Specifying targets: -triple and -arch
124===---------------------------------------------------------------------===//
125
126The clang supports "-triple" and "-arch" options. At most one -triple option may
127be specified, while multiple -arch options can be specified. Both are optional.
128
129The "selection of target" behavior is defined as follows:
130
131(1) If the user does not specify -triple:
132
133 (a) If no -arch options are specified, the target triple used is the host
134 triple (in llvm/Config/config.h).
135
136 (b) If one or more -arch's are specified (and no -triple), then there is
137 one triple for each -arch, where the specified arch is substituted
138 for the arch in the host triple. Example:
139
140 host triple = i686-apple-darwin9
141 command: clang -arch ppc -arch ppc64 ...
142 triples used: ppc-apple-darwin9 ppc64-apple-darwin9
143
144(2) The user does specify a -triple (only one allowed):
145
146 (a) If no -arch options are specified, the triple specified by -triple
147 is used. E.g clang -triple i686-apple-darwin9
148
149 (b) If one or more -arch options are specified, then the triple specified
150 by -triple is used as the primary target, and the arch's specified
151 by -arch are used to create secondary targets. For example:
152
153 clang -triple i686-apple-darwin9 -arch ppc -arch ppc64
154
155 has the following targets:
156
157 i686-apple-darwin9 (primary target)
158 ppc-apple-darwin9 (secondary target)
159 ppc64-apple-darwin9 (secondary target)
160
161The secondary targets are used in the 'portability' model (see below).
162
163//===---------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000164
165The 'portability' model in clang is sufficient to catch translation units (or
166their parts) that are not portable, but it doesn't help if the system headers
167are non-portable and not fixed. An alternative model that would be easy to use
168is a 'tainting' scheme. Consider:
169
170int32_t
171OSHostByteOrder(void) {
172#if defined(__LITTLE_ENDIAN__)
173 return OSLittleEndian;
174#elif defined(__BIG_ENDIAN__)
175 return OSBigEndian;
176#else
177 return OSUnknownByteOrder;
178#endif
179}
180
181It would be trivial to mark 'OSHostByteOrder' as being non-portable (tainted)
182instead of marking the entire translation unit. Then, if OSHostByteOrder is
183never called/used by the current translation unit, the t-u wouldn't be marked
184non-portable. However, there is no good way to handle stuff like:
185
186extern int X, Y;
187
188#ifndef __POWERPC__
189#define X Y
190#endif
191
192int bar() { return X; }
193
194When compiling for powerpc, the #define is skipped, so it doesn't know that bar
195uses a #define that is set on some other target. In practice, limited cases
196could be handled by scanning the skipped region of a #if, but the fully general
197case cannot be implemented efficiently. In this case, for example, the #define
198in the protected region could be turned into either a #define_target or
199#define_other_target as appropriate. The harder case is code like this (from
200OSByteOrder.h):
201
202 #if (defined(__ppc__) || defined(__ppc64__))
203 #include <libkern/ppc/OSByteOrder.h>
204 #elif (defined(__i386__) || defined(__x86_64__))
205 #include <libkern/i386/OSByteOrder.h>
206 #else
207 #include <libkern/machine/OSByteOrder.h>
208 #endif
209
210The realistic way to fix this is by having an initial #ifdef __llvm__ that
211defines its contents in terms of the llvm bswap intrinsics. Other things should
212be handled on a case-by-case basis.
213
214
215We probably have to do something smarter like this in the future. The C++ header
216<limits> contains a lot of code like this:
217
218 static const int digits10 = __LDBL_DIG__;
219 static const int min_exponent = __LDBL_MIN_EXP__;
220 static const int min_exponent10 = __LDBL_MIN_10_EXP__;
221 static const float_denorm_style has_denorm
222 = bool(__LDBL_DENORM_MIN__) ? denorm_present : denorm_absent;
223
224 ... since this isn't being used in an #ifdef, it should be easy enough to taint
225the decl for these ivars.
226
227
228/usr/include/sys/cdefs.h contains stuff like this:
229
230#if defined(__ppc__)
231# if defined(__LDBL_MANT_DIG__) && defined(__DBL_MANT_DIG__) && \
232 __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
233# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1040
234# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBLStub")
235# else
236# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBL128")
237# endif
238# define __DARWIN_LDBL_COMPAT2(x) __asm("_" __STRING(x) "$LDBL128")
239# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
240# else
241# define __DARWIN_LDBL_COMPAT(x) /* nothing */
242# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
243# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 1
244# endif
245#elif defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
246# define __DARWIN_LDBL_COMPAT(x) /* nothing */
247# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
248# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
249#else
250# error Unknown architecture
251#endif
252
253An ideal way to solve this issue is to mark __DARWIN_LDBL_COMPAT /
254__DARWIN_LDBL_COMPAT2 / __DARWIN_LONG_DOUBLE_IS_DOUBLE as being non-portable
255because they depend on non-portable macros. In practice though, this may end
256up being a serious problem: every use of printf will mark the translation unit
257non-portable if targetting ppc32 and something else.
258
259//===---------------------------------------------------------------------===//
Chris Lattner26862342007-07-11 17:31:59 +0000260