blob: 58230414172a198aaf7a316e8ce360bfb6a008e5 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <title>LLVM: Frequently Asked Questions</title>
6 <style type="text/css">
7 @import url("llvm.css");
8 .question { font-weight: bold }
9 .answer { margin-left: 2em }
10 </style>
11</head>
12<body>
13
14<div class="doc_title">
15 LLVM: Frequently Asked Questions
16</div>
17
18<ol>
19 <li><a href="#license">License</a>
20 <ol>
21 <li>Why are the LLVM source code and the front-end distributed under different
22 licenses?</li>
23 <li>Does the University of Illinois Open Source License really qualify as an
24 "open source" license?</li>
25 <li>Can I modify LLVM source code and redistribute the modified source?</li>
26 <li>Can I modify LLVM source code and redistribute binaries or other tools
27 based on it, without redistributing the source?</li>
28 </ol></li>
29
30 <li><a href="#source">Source code</a>
31 <ol>
32 <li>In what language is LLVM written?</li>
33 <li>How portable is the LLVM source code?</li>
34 </ol></li>
35
36 <li><a href="#build">Build Problems</a>
37 <ol>
38 <li>When I run configure, it finds the wrong C compiler.</li>
39 <li>The <tt>configure</tt> script finds the right C compiler, but it uses the
40 LLVM linker from a previous build. What do I do?</li>
41 <li>When creating a dynamic library, I get a strange GLIBC error.</li>
42 <li>I've updated my source tree from Subversion, and now my build is trying
43 to use a file/directory that doesn't exist.</li>
44 <li>I've modified a Makefile in my source tree, but my build tree keeps using
45 the old version. What do I do?</li>
46 <li>I've upgraded to a new version of LLVM, and I get strange build
47 errors.</li>
48 <li>I've built LLVM and am testing it, but the tests freeze.</li>
49 <li>Why do test results differ when I perform different types of builds?</li>
50 <li>Compiling LLVM with GCC 3.3.2 fails, what should I do?</li>
51 <li>When I use the test suite, all of the C Backend tests fail. What is
52 wrong?</li>
53 <li>After Subversion update, rebuilding gives the error "No rule to make
54 target".</li>
55 <li><a href="#llvmc">The <tt>llvmc</tt> program gives me errors/doesn't
Bill Wendling4e05864c2007-09-22 09:54:47 +000056 work.</a></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 </ol></li>
58
59 <li><a href="#felangs">Source Languages</a>
60 <ol>
61 <li><a href="#langs">What source languages are supported?</a></li>
62 <li><a href="#langhlsupp">What support is there for higher level source
63 language constructs for building a compiler?</a></li>
64 <li><a href="GetElementPtr.html">I don't understand the GetElementPtr
65 instruction. Help!</a></li>
66 </ol>
67
68 <li><a href="#cfe">Using the GCC Front End</a>
69 <ol>
70 <li>
71 When I compile software that uses a configure script, the configure script
72 thinks my system has all of the header files and libraries it is testing
73 for. How do I get configure to work correctly?
74 </li>
75
76 <li>
77 When I compile code using the LLVM GCC front end, it complains that it
78 cannot find libcrtend.a.
79 </li>
80
81 <li>
82 How can I disable all optimizations when compiling code using the LLVM GCC front end?
83 </li>
84
85 <li><a href="#translatec++">Can I use LLVM to convert C++ code to C code?</a></li>
86
87 </ol>
88 </li>
89
90 <li><a href="#cfe_code">Questions about code generated by the GCC front-end</a>
91 <ol>
92 <li><a href="#__main">What is this <tt>__main()</tt> call that gets inserted into
93 <tt>main()</tt>?</a></li>
94 <li><a href="#iosinit">What is this <tt>llvm.global_ctors</tt> and
95 <tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I
96 #include &lt;iostream&gt;?</a></li>
97 <li><a href="#codedce">Where did all of my code go??</a></li>
98 <li><a href="#undef">What is this "<tt>undef</tt>" thing that shows up in my code?</a></li>
99 </ol>
100 </li>
101</ol>
102
103<div class="doc_author">
104 <p>Written by <a href="http://llvm.org">The LLVM Team</a></p>
105</div>
106
107
108<!-- *********************************************************************** -->
109<div class="doc_section">
110 <a name="license">License</a>
111</div>
112<!-- *********************************************************************** -->
113
114<div class="question">
115<p>Why are the LLVM source code and the front-end distributed under different
116licenses?</p>
117</div>
118
119<div class="answer">
120<p>The C/C++ front-ends are based on GCC and must be distributed under the GPL.
121Our aim is to distribute LLVM source code under a <em>much less restrictive</em>
122license, in particular one that does not compel users who distribute tools based
123on modifying the source to redistribute the modified source code as well.</p>
124</div>
125
126<div class="question">
127<p>Does the University of Illinois Open Source License really qualify as an
128"open source" license?</p>
129</div>
130
131<div class="answer">
132<p>Yes, the license is <a
133href="http://www.opensource.org/licenses/UoI-NCSA.php">certified</a> by the Open
134Source Initiative (OSI).</p>
135</div>
136
137<div class="question">
138<p>Can I modify LLVM source code and redistribute the modified source?</p>
139</div>
140
141<div class="answer">
142<p>Yes. The modified source distribution must retain the copyright notice and
143follow the three bulletted conditions listed in the <a
144href="http://llvm.org/releases/1.3/LICENSE.TXT">LLVM license</a>.</p>
145</div>
146
147<div class="question">
148<p>Can I modify LLVM source code and redistribute binaries or other tools based
149on it, without redistributing the source?</p>
150</div>
151
152<div class="answer">
153<p>Yes, this is why we distribute LLVM under a less restrictive license than
154GPL, as explained in the first question above.</p>
155</div>
156
157<!-- *********************************************************************** -->
158<div class="doc_section">
159 <a name="source">Source Code</a>
160</div>
161<!-- *********************************************************************** -->
162
163<div class="question">
164<p>In what language is LLVM written?</p>
165</div>
166
167<div class="answer">
168<p>All of the LLVM tools and libraries are written in C++ with extensive use of
169the STL.</p>
170</div>
171
172<div class="question">
173<p>How portable is the LLVM source code?</p>
174</div>
175
176<div class="answer">
177<p>The LLVM source code should be portable to most modern UNIX-like operating
178systems. Most of the code is written in standard C++ with operating system
179services abstracted to a support library. The tools required to build and test
180LLVM have been ported to a plethora of platforms.</p>
181
182<p>Some porting problems may exist in the following areas:</p>
183
184<ul>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185 <li>The GCC front end code is not as portable as the LLVM suite, so it may not
Bill Wendling4e05864c2007-09-22 09:54:47 +0000186 compile as well on unsupported platforms.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187
188 <li>The LLVM build system relies heavily on UNIX shell tools, like the Bourne
Bill Wendling4e05864c2007-09-22 09:54:47 +0000189 Shell and sed. Porting to systems without these tools (MacOS 9, Plan 9)
190 will require more effort.</li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191</ul>
192
193</div>
194
195<!-- *********************************************************************** -->
196<div class="doc_section">
197 <a name="build">Build Problems</a>
198</div>
199<!-- *********************************************************************** -->
200
201<div class="question">
202<p>When I run configure, it finds the wrong C compiler.</p>
203</div>
204
205<div class="answer">
206
207<p>The <tt>configure</tt> script attempts to locate first <tt>gcc</tt> and then
208<tt>cc</tt>, unless it finds compiler paths set in <tt>CC</tt> and <tt>CXX</tt>
209for the C and C++ compiler, respectively.</p>
210
211<p>If <tt>configure</tt> finds the wrong compiler, either adjust your
212<tt>PATH</tt> environment variable or set <tt>CC</tt> and <tt>CXX</tt>
213explicitly.</p>
214
215</div>
216
217<div class="question">
218<p>The <tt>configure</tt> script finds the right C compiler, but it uses the
219LLVM linker from a previous build. What do I do?</p>
220</div>
221
222<div class="answer">
223<p>The <tt>configure</tt> script uses the <tt>PATH</tt> to find executables, so
224if it's grabbing the wrong linker/assembler/etc, there are two ways to fix
225it:</p>
226
227<ol>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228 <li><p>Adjust your <tt>PATH</tt> environment variable so that the correct
Bill Wendling4e05864c2007-09-22 09:54:47 +0000229 program appears first in the <tt>PATH</tt>. This may work, but may not be
230 convenient when you want them <i>first</i> in your path for other
231 work.</p></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232
233 <li><p>Run <tt>configure</tt> with an alternative <tt>PATH</tt> that is
Bill Wendling4e05864c2007-09-22 09:54:47 +0000234 correct. In a Borne compatible shell, the syntax would be:</p>
235
236<div class="doc_code">
237<pre>
238% PATH=[the path without the bad program] ./configure ...
239</pre>
240</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241
242 <p>This is still somewhat inconvenient, but it allows <tt>configure</tt>
Bill Wendling4e05864c2007-09-22 09:54:47 +0000243 to do its work without having to adjust your <tt>PATH</tt>
244 permanently.</p></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245</ol>
246
247</div>
248
249<div class="question">
250<p>When creating a dynamic library, I get a strange GLIBC error.</p>
251</div>
252
253<div class="answer">
254<p>Under some operating systems (i.e. Linux), libtool does not work correctly if
255GCC was compiled with the --disable-shared option. To work around this, install
256your own version of GCC that has shared libraries enabled by default.</p>
257</div>
258
259<div class="question">
Bill Wendling4e05864c2007-09-22 09:54:47 +0000260<p>I've updated my source tree from Subversion, and now my build is trying to
261use a file/directory that doesn't exist.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262</div>
263
264<div class="answer">
265<p>You need to re-run configure in your object directory. When new Makefiles
266are added to the source tree, they have to be copied over to the object tree in
267order to be used by the build.</p>
268</div>
269
270<div class="question">
271<p>I've modified a Makefile in my source tree, but my build tree keeps using the
272old version. What do I do?</p>
273</div>
274
275<div class="answer">
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276<p>If the Makefile already exists in your object tree, you
277can just run the following command in the top level directory of your object
278tree:</p>
279
Bill Wendling4e05864c2007-09-22 09:54:47 +0000280<div class="doc_code">
281<pre>% ./config.status &lt;relative path to Makefile&gt;</pre>
282</div>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000283
284<p>If the Makefile is new, you will have to modify the configure script to copy
285it over.</p>
286
287</div>
288
289<div class="question">
290<p>I've upgraded to a new version of LLVM, and I get strange build errors.</p>
291</div>
292
293<div class="answer">
294
295<p>Sometimes, changes to the LLVM source code alters how the build system works.
296Changes in libtool, autoconf, or header file dependencies are especially prone
297to this sort of problem.</p>
298
299<p>The best thing to try is to remove the old files and re-build. In most
300cases, this takes care of the problem. To do this, just type <tt>make
301clean</tt> and then <tt>make</tt> in the directory that fails to build.</p>
302
303</div>
304
305<div class="question">
306<p>I've built LLVM and am testing it, but the tests freeze.</p>
307</div>
308
309<div class="answer">
310
311<p>This is most likely occurring because you built a profile or release
312(optimized) build of LLVM and have not specified the same information on the
313<tt>gmake</tt> command line.</p>
314
315<p>For example, if you built LLVM with the command:</p>
316
317<div class="doc_code">
Bill Wendling4e05864c2007-09-22 09:54:47 +0000318<pre>% gmake ENABLE_PROFILING=1</pre>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319</div>
320
321<p>...then you must run the tests with the following commands:</p>
322
323<div class="doc_code">
324<pre>
325% cd llvm/test
326% gmake ENABLE_PROFILING=1
327</pre>
328</div>
329
330</div>
331
332<div class="question">
333<p>Why do test results differ when I perform different types of builds?</p>
334</div>
335
336<div class="answer">
337
338<p>The LLVM test suite is dependent upon several features of the LLVM tools and
339libraries.</p>
340
341<p>First, the debugging assertions in code are not enabled in optimized or
342profiling builds. Hence, tests that used to fail may pass.</p>
343
344<p>Second, some tests may rely upon debugging options or behavior that is only
345available in the debug build. These tests will fail in an optimized or profile
346build.</p>
347
348</div>
349
350<div class="question">
351<p>Compiling LLVM with GCC 3.3.2 fails, what should I do?</p>
352</div>
353
354<div class="answer">
355<p>This is <a href="http://gcc.gnu.org/PR?13392">a bug in GCC</a>, and
Bill Wendling4e05864c2007-09-22 09:54:47 +0000356affects projects other than LLVM. Try upgrading or downgrading your GCC.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357</div>
358
359<div class="question">
Bill Wendling4e05864c2007-09-22 09:54:47 +0000360<p>After Subversion update, rebuilding gives the error "No rule to make
361target".</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362</div>
363
364<div class="answer">
365<p>If the error is of the form:</p>
366
367<div class="doc_code">
368<pre>
369gmake[2]: *** No rule to make target `/path/to/somefile', needed by
370`/path/to/another/file.d'.<br>
371Stop.
372</pre>
373</div>
374
375<p>This may occur anytime files are moved within the Subversion repository or
376removed entirely. In this case, the best solution is to erase all
377<tt>.d</tt> files, which list dependencies for source files, and rebuild:</p>
378
379<div class="doc_code">
380<pre>
381% cd $LLVM_OBJ_DIR
382% rm -f `find . -name \*\.d`
383% gmake
384</pre>
385</div>
386
387<p>In other cases, it may be necessary to run <tt>make clean</tt> before
388rebuilding.</p>
389</div>
390
Bill Wendling4e05864c2007-09-22 09:54:47 +0000391<div class="question"><p><a name="llvmc">
392The <tt>llvmc</tt> program gives me errors/doesn't work.</a></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393</div>
394
395<div class="answer">
Bill Wendling4e05864c2007-09-22 09:54:47 +0000396<p><tt>llvmc</tt> is experimental and isn't really supported. We suggest
397using <tt>llvm-gcc</tt> instead.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398</div>
399
400<!-- *********************************************************************** -->
401<div class="doc_section"><a name="felangs">Source Languages</a></div>
402
403<div class="question"><p>
404 <a name="langs">What source languages are supported?</a></p>
405</div>
406<div class="answer">
407 <p>LLVM currently has full support for C and C++ source languages. These are
408 available through a special version of GCC that LLVM calls the
409 <a href="#cfe">C Front End</a></p>
410 <p>There is an incomplete version of a Java front end available in the
411 <tt>java</tt> module. There is no documentation on this yet so
412 you'll need to download the code, compile it, and try it.</p>
413 <p>In the <tt>stacker</tt> module is a compiler and runtime
414 library for the Stacker language, a "toy" language loosely based on Forth.</p>
415 <p>The PyPy developers are working on integrating LLVM into the PyPy backend
416 so that PyPy language can translate to LLVM.</p>
417</div>
Bill Wendling4e05864c2007-09-22 09:54:47 +0000418<div class="question"><p><a name="langhlsupp">
419 What support is there for a higher level source language constructs for
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420 building a compiler?</a></p>
421</div>
422<div class="answer">
423 <p>Currently, there isn't much. LLVM supports an intermediate representation
424 which is useful for code representation but will not support the high level
425 (abstract syntax tree) representation needed by most compilers. There are no
426 facilities for lexical nor semantic analysis. There is, however, a <i>mostly
427 implemented</i> configuration-driven
428 <a href="CompilerDriver.html">compiler driver</a> which simplifies the task
429 of running optimizations, linking, and executable generation.</p>
430</div>
431
Bill Wendling4e05864c2007-09-22 09:54:47 +0000432<div class="question"><p><a name="langhlsupp">
433 I don't understand the GetElementPtr instruction. Help!</a></p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434</div>
435<div class="answer">
436 <p>See <a href="GetElementPtr.html">The Often Misunderstood GEP
Bill Wendling4e05864c2007-09-22 09:54:47 +0000437 Instruction</a>.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000438</div>
439
440<!-- *********************************************************************** -->
441<div class="doc_section">
442 <a name="cfe">Using the GCC Front End</a>
443</div>
444
445<div class="question">
446<p>
447When I compile software that uses a configure script, the configure script
448thinks my system has all of the header files and libraries it is testing for.
449How do I get configure to work correctly?
450</p>
451</div>
452
453<div class="answer">
454<p>
455The configure script is getting things wrong because the LLVM linker allows
456symbols to be undefined at link time (so that they can be resolved during JIT
457or translation to the C back end). That is why configure thinks your system
458"has everything."
459</p>
460<p>
461To work around this, perform the following steps:
462</p>
463<ol>
464 <li>Make sure the CC and CXX environment variables contains the full path to
465 the LLVM GCC front end.</li>
466
467 <li>Make sure that the regular C compiler is first in your PATH. </li>
468
469 <li>Add the string "-Wl,-native" to your CFLAGS environment variable.</li>
470</ol>
471
472<p>
473This will allow the <tt>llvm-ld</tt> linker to create a native code executable
474instead of shell script that runs the JIT. Creating native code requires
475standard linkage, which in turn will allow the configure script to find out if
476code is not linking on your system because the feature isn't available on your
477system.</p>
478</div>
479
480<div class="question">
481<p>
482When I compile code using the LLVM GCC front end, it complains that it cannot
483find libcrtend.a.
484</p>
485</div>
486
487<div class="answer">
488<p>
489The only way this can happen is if you haven't installed the runtime library. To
490correct this, do:</p>
491
492<div class="doc_code">
493<pre>
494% cd llvm/runtime
495% make clean ; make install-bytecode
496</pre>
497</div>
498</div>
499
500<div class="question">
501<p>
502How can I disable all optimizations when compiling code using the LLVM GCC front end?
503</p>
504</div>
505
506<div class="answer">
507<p>
508Passing "-Wa,-disable-opt -Wl,-disable-opt" will disable *all* cleanup and
509optimizations done at the llvm level, leaving you with the truly horrible
510code that you desire.
511</p>
512</div>
513
514
515<div class="question">
516<p>
517<a name="translatec++">Can I use LLVM to convert C++ code to C code?</a>
518</p>
519</div>
520
521<div class="answer">
522<p>Yes, you can use LLVM to convert code from any language LLVM supports to C.
523Note that the generated C code will be very low level (all loops are lowered
524to gotos, etc) and not very pretty (comments are stripped, original source
525formatting is totally lost, variables are renamed, expressions are regrouped),
526so this may not be what you're looking for. However, this is a good way to add
527C++ support for a processor that does not otherwise have a C++ compiler.
528</p>
529
530<p>Use commands like this:</p>
531
532<ol>
Bill Wendling4e05864c2007-09-22 09:54:47 +0000533 <li><p>Compile your program as normal with llvm-g++:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534
535<div class="doc_code">
536<pre>
537% llvm-g++ x.cpp -o program
538</pre>
539</div>
540
Bill Wendling4e05864c2007-09-22 09:54:47 +0000541 <p>or:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542
543<div class="doc_code">
544<pre>
545% llvm-g++ a.cpp -c
546% llvm-g++ b.cpp -c
547% llvm-g++ a.o b.o -o program
548</pre>
549</div>
550
Bill Wendling4e05864c2007-09-22 09:54:47 +0000551 <p>With llvm-gcc3, this will generate program and program.bc. The .bc
552 file is the LLVM version of the program all linked together.</p></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553
Bill Wendling4e05864c2007-09-22 09:54:47 +0000554 <li><p>Convert the LLVM code to C code, using the LLC tool with the C
555 backend:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
557<div class="doc_code">
558<pre>
559% llc -march=c program.bc -o program.c
560</pre>
Bill Wendling4e05864c2007-09-22 09:54:47 +0000561</div></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562
Bill Wendling4e05864c2007-09-22 09:54:47 +0000563<li><p>Finally, compile the C file:</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564
565<div class="doc_code">
566<pre>
567% cc x.c
568</pre>
Bill Wendling4e05864c2007-09-22 09:54:47 +0000569</div></li>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
571</ol>
572
Bill Wendling4e05864c2007-09-22 09:54:47 +0000573<p>Note that, by default, the C backend does not support exception handling. If
574you want/need it for a certain program, you can enable it by passing
575"-enable-correct-eh-support" to the llc program. The resultant code will use
576setjmp/longjmp to implement exception support that is correct but relatively
577slow.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578
Bill Wendling4e05864c2007-09-22 09:54:47 +0000579<p>Also note: this specific sequence of commands won't work if you use a
580function defined in the C++ runtime library (or any other C++ library). To
581access an external C++ library, you must manually compile libstdc++ to LLVM
582bitcode, statically link it into your program, then use the commands above to
583convert the whole result into C code. Alternatively, you can compile the
584libraries and your application into two different chunks of C code and link
585them.</p>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586
587</div>
588
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589<!-- *********************************************************************** -->
590<div class="doc_section">
591 <a name="cfe_code">Questions about code generated by the GCC front-end</a>
592</div>
593
594<div class="question"><p>
595<a name="__main"></a>
596What is this <tt>__main()</tt> call that gets inserted into <tt>main()</tt>?
597</p></div>
598
599<div class="answer">
600<p>
601The <tt>__main</tt> call is inserted by the C/C++ compiler in order to guarantee
602that static constructors and destructors are called when the program starts up
603and shuts down. In C, you can create static constructors and destructors by
604using GCC extensions, and in C++ you can do so by creating a global variable
605whose class has a ctor or dtor.
606</p>
607
608<p>
609The actual implementation of <tt>__main</tt> lives in the
610<tt>llvm/runtime/GCCLibraries/crtend/</tt> directory in the source-base, and is
611linked in automatically when you link the program.
612</p>
613</div>
614
615<!--=========================================================================-->
616
617<div class="question">
618<a name="iosinit"></a>
619<p> What is this <tt>llvm.global_ctors</tt> and
620<tt>_GLOBAL__I__tmp_webcompile...</tt> stuff that happens when I #include
621&lt;iostream&gt;?</p>
622</div>
623
624<div class="answer">
625
626<p>If you #include the &lt;iostream&gt; header into a C++ translation unit, the
627file will probably use the <tt>std::cin</tt>/<tt>std::cout</tt>/... global
628objects. However, C++ does not guarantee an order of initialization between
629static objects in different translation units, so if a static ctor/dtor in your
630.cpp file used <tt>std::cout</tt>, for example, the object would not necessarily
631be automatically initialized before your use.</p>
632
633<p>To make <tt>std::cout</tt> and friends work correctly in these scenarios, the
634STL that we use declares a static object that gets created in every translation
635unit that includes <tt>&lt;iostream&gt;</tt>. This object has a static
636constructor and destructor that initializes and destroys the global iostream
637objects before they could possibly be used in the file. The code that you see
638in the .ll file corresponds to the constructor and destructor registration code.
639</p>
640
641<p>If you would like to make it easier to <b>understand</b> the LLVM code
642generated by the compiler in the demo page, consider using <tt>printf()</tt>
643instead of <tt>iostream</tt>s to print values.</p>
644
645</div>
646
647<!--=========================================================================-->
648
649<div class="question"><p>
650<a name="codedce"></a>
651Where did all of my code go??
652</p></div>
653
654<div class="answer">
655<p>
656If you are using the LLVM demo page, you may often wonder what happened to all
657of the code that you typed in. Remember that the demo script is running the
658code through the LLVM optimizers, so if your code doesn't actually do anything
659useful, it might all be deleted.
660</p>
661
662<p>
663To prevent this, make sure that the code is actually needed. For example, if
664you are computing some expression, return the value from the function instead of
665leaving it in a local variable. If you really want to constrain the optimizer,
666you can read from and assign to <tt>volatile</tt> global variables.
667</p>
668</div>
669
670<!--=========================================================================-->
671
672<div class="question"><p>
673<a name="undef"></a>
674<p>What is this "<tt>undef</tt>" thing that shows up in my code?
675</p></div>
676
677<div class="answer">
678<p>
679<a href="LangRef.html#undef"><tt>undef</tt></a> is the LLVM way of representing
680a value that is not defined. You can get these if you do not initialize a
681variable before you use it. For example, the C function:</p>
682
683<div class="doc_code">
684<pre>
685int X() { int i; return i; }
686</pre>
687</div>
688
689<p>Is compiled to "<tt>ret i32 undef</tt>" because "<tt>i</tt>" never has
690a value specified for it.</p>
691</div>
692
693<!-- *********************************************************************** -->
694
695<hr>
696<address>
697 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
698 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
699 <a href="http://validator.w3.org/check/referer"><img
700 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
701
702 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
703 Last modified: $Date$
704</address>
705
706</body>
707</html>