llvm.org GIT mirror llvm / 2c1292f
Fix verification failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29661 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 13 years ago
1 changed file(s) with 16 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
66
77
88
9 LLVM Link Time Optimization: design and implentation
9 LLVM Link Time Optimization: design and implementation
1010
1111
1212
1616
  • Example of link time optimization
  • 1717
  • Alternative Approaches
  • 1818
    19
  • Multi-phase communication between LLVM and linker
  • 19
  • Multi-phase communication between LLVM and linker
  • 2020
    2121
  • Phase 1 : Read LLVM Bytecode Files
  • 2222
  • Phase 2 : Symbol Resolution
  • 2323
  • Phase 3 : Optimize Bytecode Files
  • 2424
  • Phase 4 : Symbol Resolution after optimization
  • 2525
    26
  • LLVMlto
  • 26
  • LLVMlto
  • 2727
    2828
  • LLVMSymbol
  • 2929
  • readLLVMObjectFile()
  • 3030
  • optimizeModules()
  • 31
    31
    3232
  • Debugging Information
  • 3333
    3434
    3535
    36

    Written by Devang Patela>p>

    36

    Written by Devang Patelp>

    3737
    3838
    3939
    7070 optimizations that are not possible in other models. The linker input allows
    7171 optimizer to avoid relying on conservative escape analysis.
    7272

    73
    7374
    7475
    7576
    8081
    8182

    Following example illustrates advantage of integrated approach that uses

    8283 clean interface.
    84
    8385
  • Input source file a.c is compiled into LLVM byte code form.
  • 8486
  • Input source file main.c is compiled into native object code.
  • 85 <br>
    87 </ul>
    8688
    87
    --- a.h ---
    89 --- a.h ---
    8890
    extern int foo1(void);
    8991
    extern void foo2(void);
    9092
    extern void foo4(void);
    112114
    }
    113115
    114116
    --- main.c ---
    115
    #include <stdio.h>
    117
    #include < stdio.h >
    116118
    #include "a.h"
    117119
    118120
    void foo4(void) {
    129131
    $ llvm-gcc4 a.o main.o -o main # <-- standard link command without any modifications
    130132
    131133
    132

    133134

    134135 In this example, the linker recognizes that foo2() is a externally visible
    135136 symbol defined in LLVM byte code file. This information is collected using
    136 #lreadllvmbytecodefile> readLLVMByteCodeFile() . Based on this
    137 "#readllvmobjectfile"> readLLVMObjectFile() . Based on this
    137138 information, linker completes its usual symbol resolution pass and finds that
    138139 foo2() is not used anywhere. This information is used by LLVM optimizer
    139140 and it removes foo2(). As soon as foo2() is removed, optimizer
    152153
    153154
    154155

    156
    155157
  • Compiler driver invokes link time optimizer separately.
  • 156158

    In this model link time optimizer is not able to take advantage of information
    157159 collected during normal linker's symbol resolution phase. In above example,
    170172 synchronized with linker developements on various platforms, which is not the
    171173 main focus of link time optimizer. Finally, this approach increases end user's build
    172174 time due to duplicate work done by this separate tool and linker itself.
    173 p>
    175 ul>
    174176
    175177
    176178
    202204

    203205 The linker first reads all object files in natural order and collects symbol
    204206 information. This includes native object files as well as LLVM byte code files.
    205 In this phase, the linker uses #lreadllvmbytecodefile> readLLVMByteCodeFile()
    207 In this phase, the linker uses "#readllvmobjectfile"> readLLVMObjectFile()
    206208 to collect symbol information from each LLVM bytecode files and updates its
    207209 internal global symbol table accordingly. The intent of this interface is to
    208210 avoid overhead in the non LLVM case, where all input object files are native
    223225 to report undefined symbol errors, read archive members, resolve weak
    224226 symbols etc... The linker is able to do this seamlessly even though it does not
    225227 know exact content of input LLVM bytecode files because it uses symbol information
    226 provided by #lreadllvmbytecodefile> readLLVMByteCodeFile() .
    228 provided by "#readllvmobjectfile"> readLLVMObjectFile() .
    227229 If dead code stripping is enabled then linker collects list of live symbols.
    228230

    229231
    351353
    352354 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!">
    353355
    354 Devang Patel</a><br>
    356 Devang Patel<br>
    355357 LLVM Compiler Infrastructure
    356358 Last modified: $Date$
    357359