mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Fix up the formating and change llvm-gcc to clang.
Note that this example doesn't work anymore! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139999 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ea55c83e7f
commit
88816ec963
@ -79,7 +79,7 @@ conservative escape analysis.
|
|||||||
<p>The following example illustrates the advantages of LTO's integrated
|
<p>The following example illustrates the advantages of LTO's integrated
|
||||||
approach and clean interface. This example requires a system linker which
|
approach and clean interface. This example requires a system linker which
|
||||||
supports LTO through the interface described in this document. Here,
|
supports LTO through the interface described in this document. Here,
|
||||||
llvm-gcc transparently invokes system linker. </p>
|
clang transparently invokes system linker. </p>
|
||||||
<ul>
|
<ul>
|
||||||
<li> Input source file <tt>a.c</tt> is compiled into LLVM bitcode form.
|
<li> Input source file <tt>a.c</tt> is compiled into LLVM bitcode form.
|
||||||
<li> Input source file <tt>main.c</tt> is compiled into native object code.
|
<li> Input source file <tt>main.c</tt> is compiled into native object code.
|
||||||
@ -89,27 +89,29 @@ conservative escape analysis.
|
|||||||
extern int foo1(void);
|
extern int foo1(void);
|
||||||
extern void foo2(void);
|
extern void foo2(void);
|
||||||
extern void foo4(void);
|
extern void foo4(void);
|
||||||
|
|
||||||
--- a.c ---
|
--- a.c ---
|
||||||
#include "a.h"
|
#include "a.h"
|
||||||
|
|
||||||
static signed int i = 0;
|
static signed int i = 0;
|
||||||
|
|
||||||
void foo2(void) {
|
void foo2(void) {
|
||||||
i = -1;
|
i = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int foo3() {
|
static int foo3() {
|
||||||
foo4();
|
foo4();
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
int foo1(void) {
|
int foo1(void) {
|
||||||
int data = 0;
|
int data = 0;
|
||||||
|
|
||||||
if (i < 0) { data = foo3(); }
|
if (i < 0)
|
||||||
|
data = foo3();
|
||||||
|
|
||||||
data = data + 42;
|
data = data + 42;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
--- main.c ---
|
--- main.c ---
|
||||||
@ -117,30 +119,35 @@ return data;
|
|||||||
#include "a.h"
|
#include "a.h"
|
||||||
|
|
||||||
void foo4(void) {
|
void foo4(void) {
|
||||||
printf ("Hi\n");
|
printf("Hi\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
return foo1();
|
return foo1();
|
||||||
}
|
}
|
||||||
|
|
||||||
--- command lines ---
|
--- command lines ---
|
||||||
$ llvm-gcc --emit-llvm -c a.c -o a.o # <-- a.o is LLVM bitcode file
|
$ clang -emit-llvm -c a.c -o a.o # <-- a.o is LLVM bitcode file
|
||||||
$ llvm-gcc -c main.c -o main.o # <-- main.o is native object file
|
$ clang -c main.c -o main.o # <-- main.o is native object file
|
||||||
$ llvm-gcc a.o main.o -o main # <-- standard link command without any modifications
|
$ clang a.o main.o -o main # <-- standard link command without any modifications
|
||||||
</pre>
|
</pre>
|
||||||
<p>In this example, the linker recognizes that <tt>foo2()</tt> is an
|
|
||||||
externally visible symbol defined in LLVM bitcode file. The linker completes
|
<ul>
|
||||||
its usual symbol resolution
|
<li>In this example, the linker recognizes that <tt>foo2()</tt> is an
|
||||||
pass and finds that <tt>foo2()</tt> is not used anywhere. This information
|
externally visible symbol defined in LLVM bitcode file. The linker
|
||||||
is used by the LLVM optimizer and it removes <tt>foo2()</tt>. As soon as
|
completes its usual symbol resolution pass and finds that <tt>foo2()</tt>
|
||||||
<tt>foo2()</tt> is removed, the optimizer recognizes that condition
|
is not used anywhere. This information is used by the LLVM optimizer and
|
||||||
<tt>i < 0</tt> is always false, which means <tt>foo3()</tt> is never
|
it removes <tt>foo2()</tt>.</li>
|
||||||
used. Hence, the optimizer removes <tt>foo3()</tt>, also. And this in turn,
|
<li>As soon as <tt>foo2()</tt> is removed, the optimizer recognizes that condition
|
||||||
enables linker to remove <tt>foo4()</tt>. This example illustrates the
|
<tt>i < 0</tt> is always false, which means <tt>foo3()</tt> is never
|
||||||
advantage of tight integration with the linker. Here, the optimizer can not
|
used. Hence, the optimizer also removes <tt>foo3()</tt>.</li>
|
||||||
remove <tt>foo3()</tt> without the linker's input.
|
<li>And this in turn, enables linker to remove <tt>foo4()</tt>.</li>
|
||||||
</p>
|
</ul>
|
||||||
|
|
||||||
|
<p>This example illustrates the advantage of tight integration with the
|
||||||
|
linker. Here, the optimizer can not remove <tt>foo3()</tt> without the
|
||||||
|
linker's input.</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ======================================================================= -->
|
<!-- ======================================================================= -->
|
||||||
|
Loading…
Reference in New Issue
Block a user