LTO: History and work to be done Rafael Avila de Esp ndola World - - PowerPoint PPT Presentation

lto history and work to be done
SMART_READER_LITE
LIVE PREVIEW

LTO: History and work to be done Rafael Avila de Esp ndola World - - PowerPoint PPT Presentation

LTO: History and work to be done Rafael Avila de Esp ndola World Wide Studios - Sony Computer Entertainment 2014-04-07 Very quick history overview Very quick history overview We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, .


slide-1
SLIDE 1

LTO: History and work to be done

Rafael ´ Avila de Esp´ ındola

World Wide Studios - Sony Computer Entertainment

2014-04-07

slide-2
SLIDE 2

Very quick history overview

slide-3
SLIDE 3

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . )

slide-4
SLIDE 4

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . ) ◮ We wrote plugins for native tools (libLTO.dylib, LLVMgold.so)

slide-5
SLIDE 5

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . ) ◮ We wrote plugins for native tools (libLTO.dylib, LLVMgold.so) ◮ We are writing new tools (new llvm-nm and llvm-ar, lld, . . . )

slide-6
SLIDE 6

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . ) ◮ We wrote plugins for native tools (libLTO.dylib, LLVMgold.so) ◮ We are writing new tools (new llvm-nm and llvm-ar, lld, . . . ) ◮ Are we going back and forth?!?

slide-7
SLIDE 7

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . ) ◮ We wrote plugins for native tools (libLTO.dylib, LLVMgold.so) ◮ We are writing new tools (new llvm-nm and llvm-ar, lld, . . . ) ◮ Are we going back and forth?!? ◮ Yes!

slide-8
SLIDE 8

Very quick history overview

◮ We had llvm specific tools (llvm-nm, llvm-ar, llvm-ld, . . . ) ◮ We wrote plugins for native tools (libLTO.dylib, LLVMgold.so) ◮ We are writing new tools (new llvm-nm and llvm-ar, lld, . . . ) ◮ Are we going back and forth?!? ◮ Yes! ◮ Probably the correct choice at every point in time.

slide-9
SLIDE 9

Early tools

slide-10
SLIDE 10

Early tools

◮ They were llvm only.

slide-11
SLIDE 11

Early tools

◮ They were llvm only. ◮ Easy to write. Important for a small (at the time) project.

slide-12
SLIDE 12

Early tools

◮ They were llvm only. ◮ Easy to write. Important for a small (at the time) project. ◮ llvm-link was “95% persent working” in October 2001.

slide-13
SLIDE 13

Early tools

◮ They were llvm only. ◮ Easy to write. Important for a small (at the time) project. ◮ llvm-link was “95% persent working” in October 2001. ◮ Combine with opt and we already had LTO!

slide-14
SLIDE 14

Evolution of the early tools

slide-15
SLIDE 15

Evolution of the early tools

◮ Adding llvm-link, opt and llc to a build is a pain.

slide-16
SLIDE 16

Evolution of the early tools

◮ Adding llvm-link, opt and llc to a build is a pain. ◮ We added gccld to help in January 2002. It hides the extra

build steps. Produces a shell script that runs lli.

slide-17
SLIDE 17

Evolution of the early tools

◮ Adding llvm-link, opt and llc to a build is a pain. ◮ We added gccld to help in January 2002. It hides the extra

build steps. Produces a shell script that runs lli.

◮ Libraries can be created with llvm-ar since August 2003.

slide-18
SLIDE 18

Evolution of the early tools

◮ Adding llvm-link, opt and llc to a build is a pain. ◮ We added gccld to help in January 2002. It hides the extra

build steps. Produces a shell script that runs lli.

◮ Libraries can be created with llvm-ar since August 2003. ◮ Native codegen added to gccld in September 2003).

slide-19
SLIDE 19

Evolution of the early tools

◮ Adding llvm-link, opt and llc to a build is a pain. ◮ We added gccld to help in January 2002. It hides the extra

build steps. Produces a shell script that runs lli.

◮ Libraries can be created with llvm-ar since August 2003. ◮ Native codegen added to gccld in September 2003). ◮ gccld is renamed llvm-ld in r16305 September 2004.

slide-20
SLIDE 20

Some limitations remained

slide-21
SLIDE 21

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

slide-22
SLIDE 22

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members.

slide-23
SLIDE 23

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members. ◮ To assemble and link, llvm-ld runs gcc.

slide-24
SLIDE 24

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members. ◮ To assemble and link, llvm-ld runs gcc. ◮ Semantics not exactly right.

slide-25
SLIDE 25

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members. ◮ To assemble and link, llvm-ld runs gcc. ◮ Semantics not exactly right. ◮ Slow.

slide-26
SLIDE 26

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members. ◮ To assemble and link, llvm-ld runs gcc. ◮ Semantics not exactly right. ◮ Slow. ◮ Build changes are still required.

slide-27
SLIDE 27

Some limitations remained

◮ They don’t know about native object files. Have to be

conservative.

◮ The archive symbol table only lists llvm members. ◮ To assemble and link, llvm-ld runs gcc. ◮ Semantics not exactly right. ◮ Slow. ◮ Build changes are still required. ◮ Hacks everywhere.

slide-28
SLIDE 28

The native tools

slide-29
SLIDE 29

The native tools

◮ Native tools (ld, ar, ranlib . . . ) know the command line args.

slide-30
SLIDE 30

The native tools

◮ Native tools (ld, ar, ranlib . . . ) know the command line args. ◮ They know all semantic corner cases.

slide-31
SLIDE 31

The native tools

◮ Native tools (ld, ar, ranlib . . . ) know the command line args. ◮ They know all semantic corner cases. ◮ They know the library format.

slide-32
SLIDE 32

The native tools

◮ Native tools (ld, ar, ranlib . . . ) know the command line args. ◮ They know all semantic corner cases. ◮ They know the library format. ◮ Build systems are already using them!

slide-33
SLIDE 33

The native tools

◮ Native tools (ld, ar, ranlib . . . ) know the command line args. ◮ They know all semantic corner cases. ◮ They know the library format. ◮ Build systems are already using them! ◮ They know all there is to know about LTO, except llvm IR.

slide-34
SLIDE 34

The plugin era

slide-35
SLIDE 35

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help.

slide-36
SLIDE 36

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64.

slide-37
SLIDE 37

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006.

slide-38
SLIDE 38

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006. ◮ gold got plugin support in September 2008.

slide-39
SLIDE 39

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006. ◮ gold got plugin support in September 2008. ◮ tools/gold added in February 2009.

slide-40
SLIDE 40

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006. ◮ gold got plugin support in September 2008. ◮ tools/gold added in February 2009. ◮ bfd (nm, ar) gets plugin support in May 2009.

slide-41
SLIDE 41

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006. ◮ gold got plugin support in September 2008. ◮ tools/gold added in February 2009. ◮ bfd (nm, ar) gets plugin support in May 2009. ◮ bfd (ld) gets plugin support in October 2010.

slide-42
SLIDE 42

The plugin era

◮ Idea: Use the native tools, but have them ask llvm for help. ◮ First implemented in ld64. ◮ tools/lto added in August 2006. ◮ gold got plugin support in September 2008. ◮ tools/gold added in February 2009. ◮ bfd (nm, ar) gets plugin support in May 2009. ◮ bfd (ld) gets plugin support in October 2010. ◮ We can now do LTO by setting CFLAGS, CXXFLAGS and

LDFLAGS!

slide-43
SLIDE 43

The llvm project around 2009

slide-44
SLIDE 44

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

slide-45
SLIDE 45

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality.

slide-46
SLIDE 46

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license.

slide-47
SLIDE 47

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular.

slide-48
SLIDE 48

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

slide-49
SLIDE 49

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough!

slide-50
SLIDE 50

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

slide-51
SLIDE 51

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

◮ Assemblers

slide-52
SLIDE 52

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

◮ Assemblers ◮ Linkers

slide-53
SLIDE 53

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

◮ Assemblers ◮ Linkers ◮ Debuggers

slide-54
SLIDE 54

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

◮ Assemblers ◮ Linkers ◮ Debuggers ◮ . . .

slide-55
SLIDE 55

The llvm project around 2009

◮ llvm had become a good compiler toolkit:

◮ High quality. ◮ Liberal license. ◮ Modular. ◮ . . .

◮ That is not enough! ◮ These are also desirabilities of

◮ Assemblers ◮ Linkers ◮ Debuggers ◮ . . .

◮ We need a toolchain toolkit!

slide-56
SLIDE 56

The project expands to other areas

slide-57
SLIDE 57

The project expands to other areas

◮ lib/MC added in June 2009.

slide-58
SLIDE 58

The project expands to other areas

◮ lib/MC added in June 2009. ◮ libcxx added in r103490 May 2010.

slide-59
SLIDE 59

The project expands to other areas

◮ lib/MC added in June 2009. ◮ libcxx added in r103490 May 2010. ◮ lldb added in r105617 June 2010.

slide-60
SLIDE 60

The project expands to other areas

◮ lib/MC added in June 2009. ◮ libcxx added in r103490 May 2010. ◮ lldb added in r105617 June 2010. ◮ lib/Object added in r119107 November 2010.

slide-61
SLIDE 61

The project expands to other areas

◮ lib/MC added in June 2009. ◮ libcxx added in r103490 May 2010. ◮ lldb added in r105617 June 2010. ◮ lib/Object added in r119107 November 2010. ◮ lld added in r146598 December 2011 (was named lold).

slide-62
SLIDE 62

The new tools and LTO

slide-63
SLIDE 63

The new tools and LTO

◮ We are building a complete toolchain.

slide-64
SLIDE 64

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO!

slide-65
SLIDE 65

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO! ◮ Very different tools form the original tools:

slide-66
SLIDE 66

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO! ◮ Very different tools form the original tools:

◮ They are not llvm only. ELF, COFF and MachO work.

slide-67
SLIDE 67

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO! ◮ Very different tools form the original tools:

◮ They are not llvm only. ELF, COFF and MachO work. ◮ In archives, IR files go in the same symbol table.

slide-68
SLIDE 68

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO! ◮ Very different tools form the original tools:

◮ They are not llvm only. ELF, COFF and MachO work. ◮ In archives, IR files go in the same symbol table. ◮ Implement the same semantics and options as the native tools.

slide-69
SLIDE 69

The new tools and LTO

◮ We are building a complete toolchain. ◮ Lets make sure it supports LTO! ◮ Very different tools form the original tools:

◮ They are not llvm only. ELF, COFF and MachO work. ◮ In archives, IR files go in the same symbol table. ◮ Implement the same semantics and options as the native tools. ◮ Should still be able to do LTO by setting CFLAGS,

CXXFLAGS and LDFLAGS.

slide-70
SLIDE 70

Recent developments

Decided to start with llvm-ar and make it generic.

slide-71
SLIDE 71

The first expected items

slide-72
SLIDE 72

The first expected items

◮ lvm-ar was rewritten to use lib/Object.

slide-73
SLIDE 73

The first expected items

◮ lvm-ar was rewritten to use lib/Object. ◮ Removed lib/Archive.

slide-74
SLIDE 74

The first expected items

◮ lvm-ar was rewritten to use lib/Object. ◮ Removed lib/Archive. ◮ llvm-ar could then create native symbol tables!

slide-75
SLIDE 75

The first expected items

◮ lvm-ar was rewritten to use lib/Object. ◮ Removed lib/Archive. ◮ llvm-ar could then create native symbol tables! ◮ And they include native object formats!

slide-76
SLIDE 76

The first expected items

◮ lvm-ar was rewritten to use lib/Object. ◮ Removed lib/Archive. ◮ llvm-ar could then create native symbol tables! ◮ And they include native object formats! ◮ Pretty much done by July 2013.

slide-77
SLIDE 77

The first expected items

◮ lvm-ar was rewritten to use lib/Object. ◮ Removed lib/Archive. ◮ llvm-ar could then create native symbol tables! ◮ And they include native object formats! ◮ Pretty much done by July 2013. ◮ Then I “only” needed to add IR support to lib/Object.

slide-78
SLIDE 78

Yak shaving, part 1

slide-79
SLIDE 79

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name.

slide-80
SLIDE 80

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name. ◮ llvm-ar should not depend on lib/Target.

slide-81
SLIDE 81

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name. ◮ llvm-ar should not depend on lib/Target. ◮ The mangler had to move from lib/Target to lib/IR.

slide-82
SLIDE 82

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name. ◮ llvm-ar should not depend on lib/Target. ◮ The mangler had to move from lib/Target to lib/IR. ◮ And the mangling had to be specified in DataLayout.

slide-83
SLIDE 83

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name. ◮ llvm-ar should not depend on lib/Target. ◮ The mangler had to move from lib/Target to lib/IR. ◮ And the mangling had to be specified in DataLayout. ◮ The DataLayout specs were out of sync in llvm and clang.

slide-84
SLIDE 84

Yak shaving, part 1

◮ The symbol table in archives uses the final (mangled) name. ◮ llvm-ar should not depend on lib/Target. ◮ The mangler had to move from lib/Target to lib/IR. ◮ And the mangling had to be specified in DataLayout. ◮ The DataLayout specs were out of sync in llvm and clang. ◮ Move completed in Jan 2014.

slide-85
SLIDE 85

Yak shaving, part 2

slide-86
SLIDE 86

Yak shaving, part 2

◮ The ObjectFile interface is huge.

slide-87
SLIDE 87

Yak shaving, part 2

◮ The ObjectFile interface is huge. ◮ Has to handle symbols, sections, segments, relocations, . . . .

slide-88
SLIDE 88

Yak shaving, part 2

◮ The ObjectFile interface is huge. ◮ Has to handle symbols, sections, segments, relocations, . . . . ◮ For IR, only symbols make sense.

slide-89
SLIDE 89

Yak shaving, part 2

◮ The ObjectFile interface is huge. ◮ Has to handle symbols, sections, segments, relocations, . . . . ◮ For IR, only symbols make sense. ◮ Added a new SymbolicFile with a simpler interface.

slide-90
SLIDE 90

Yak shaving, part 2

◮ The ObjectFile interface is huge. ◮ Has to handle symbols, sections, segments, relocations, . . . . ◮ For IR, only symbols make sense. ◮ Added a new SymbolicFile with a simpler interface. ◮ An ObjectFile is a SymbolicFile.

slide-91
SLIDE 91

Yak shaving, part 2

◮ The ObjectFile interface is huge. ◮ Has to handle symbols, sections, segments, relocations, . . . . ◮ For IR, only symbols make sense. ◮ Added a new SymbolicFile with a simpler interface. ◮ An ObjectFile is a SymbolicFile. ◮ Finally implemented IRObjectFile in February 2014.

slide-92
SLIDE 92

Yak shaving, part 3

slide-93
SLIDE 93

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

slide-94
SLIDE 94

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

◮ But DataLayout is an ImmutablePass.

slide-95
SLIDE 95

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

◮ But DataLayout is an ImmutablePass. ◮ And llvm-ar has no pass manager :-(

slide-96
SLIDE 96

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

◮ But DataLayout is an ImmutablePass. ◮ And llvm-ar has no pass manager :-( ◮ Split DataLayout into DataLayoutPass and DataLayout.

slide-97
SLIDE 97

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

◮ But DataLayout is an ImmutablePass. ◮ And llvm-ar has no pass manager :-( ◮ Split DataLayout into DataLayoutPass and DataLayout. ◮ Split finished in February 2014.

slide-98
SLIDE 98

Yak shaving, part 3

◮ We could then mangle a GlobalValue’s name using

DataLayout!

◮ But DataLayout is an ImmutablePass. ◮ And llvm-ar has no pass manager :-( ◮ Split DataLayout into DataLayoutPass and DataLayout. ◮ Split finished in February 2014. ◮ The symbol tables are now correct and include IR files!

slide-99
SLIDE 99

Work to be done

slide-100
SLIDE 100

Finish llvm-ar

slide-101
SLIDE 101

Finish llvm-ar

◮ We need to finish it so that it can be used on any build.

slide-102
SLIDE 102

Finish llvm-ar

◮ We need to finish it so that it can be used on any build. ◮ Support for non-gnu format is missing.

slide-103
SLIDE 103

Finish llvm-ar

◮ We need to finish it so that it can be used on any build. ◮ Support for non-gnu format is missing. ◮ BFD format should make it possible to align objects!

slide-104
SLIDE 104

Finish llvm-ar

◮ We need to finish it so that it can be used on any build. ◮ Support for non-gnu format is missing. ◮ BFD format should make it possible to align objects! ◮ Thin archives are missing.

slide-105
SLIDE 105

Finish llvm-ar

◮ We need to finish it so that it can be used on any build. ◮ Support for non-gnu format is missing. ◮ BFD format should make it possible to align objects! ◮ Thin archives are missing. ◮ File handling could use open, ftruncate, mmap.

slide-106
SLIDE 106

Finish llvm-ar

◮ We need to finish it so that it can be used on any build. ◮ Support for non-gnu format is missing. ◮ BFD format should make it possible to align objects! ◮ Thin archives are missing. ◮ File handling could use open, ftruncate, mmap. ◮ Hopefully no yaks.

slide-107
SLIDE 107

Some inefficiencies of IR handling in llvm-ar

slide-108
SLIDE 108

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols.

slide-109
SLIDE 109

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out.

slide-110
SLIDE 110

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out. ◮ lib/Object doesn’t know what it is being used

for.

slide-111
SLIDE 111

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out. ◮ lib/Object doesn’t know what it is being used

for.

◮ lib/Object uses lib/IR to find out.

slide-112
SLIDE 112

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out. ◮ lib/Object doesn’t know what it is being used

for.

◮ lib/Object uses lib/IR to find out. ◮ lib/IR doesn’t know what it is being used for.

slide-113
SLIDE 113

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out. ◮ lib/Object doesn’t know what it is being used

for.

◮ lib/Object uses lib/IR to find out. ◮ lib/IR doesn’t know what it is being used for. ◮ lib/IR parses the entire file.

slide-114
SLIDE 114

Some inefficiencies of IR handling in llvm-ar

◮ llvm-ar needs the name of global symbols. ◮ llvm-ar uses lib/Object to find out. ◮ lib/Object doesn’t know what it is being used

for.

◮ lib/Object uses lib/IR to find out. ◮ lib/IR doesn’t know what it is being used for. ◮ lib/IR parses the entire file. ◮ Using a lazy module helps, but still reads metadata.

slide-115
SLIDE 115

Making lib/Object lazier

slide-116
SLIDE 116

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case.

slide-117
SLIDE 117

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case. ◮ Implement it directly with lib/Bitcode.

slide-118
SLIDE 118

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case. ◮ Implement it directly with lib/Bitcode. ◮ llvm-ar would never even create a Module.

slide-119
SLIDE 119

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case. ◮ Implement it directly with lib/Bitcode. ◮ llvm-ar would never even create a Module. ◮ Code that needs more info can create a Module and query.

slide-120
SLIDE 120

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case. ◮ Implement it directly with lib/Bitcode. ◮ llvm-ar would never even create a Module. ◮ Code that needs more info can create a Module and query.

◮ llvm-nm: Not performance critical.

slide-121
SLIDE 121

Making lib/Object lazier

◮ Reading only the names and DataLayout is a special case. ◮ Implement it directly with lib/Bitcode. ◮ llvm-ar would never even create a Module. ◮ Code that needs more info can create a Module and query.

◮ llvm-nm: Not performance critical. ◮ LTO: Can delay creating a Module in some cases.

slide-122
SLIDE 122

How linkers view LTO

slide-123
SLIDE 123

LTO according to ld64

slide-124
SLIDE 124

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files.

slide-125
SLIDE 125

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

slide-126
SLIDE 126

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly.

slide-127
SLIDE 127

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table.

slide-128
SLIDE 128

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table. ◮ C++ inline function whose address is not taken.

slide-129
SLIDE 129

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table. ◮ C++ inline function whose address is not taken. ◮ Requires loading all function bodies.

slide-130
SLIDE 130

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table. ◮ C++ inline function whose address is not taken. ◮ Requires loading all function bodies.

◮ Does symbol resolution.

slide-131
SLIDE 131

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table. ◮ C++ inline function whose address is not taken. ◮ Requires loading all function bodies.

◮ Does symbol resolution. ◮ Decides which symbols llvm should keep.

slide-132
SLIDE 132

LTO according to ld64

◮ ld64 uses libLTO to create Modules for all IR files. ◮ ld64 requests the list of all symbols in each module

◮ Really all symbols, even uses and defs in inline assembly. ◮ Asks whether a symbol can be hidden form the symbol table. ◮ C++ inline function whose address is not taken. ◮ Requires loading all function bodies.

◮ Does symbol resolution. ◮ Decides which symbols llvm should keep. ◮ libLTO creates a MachO file.

slide-133
SLIDE 133

LTO according to gold

slide-134
SLIDE 134

LTO according to gold

◮ Requests the list of global symbols of each file.

slide-135
SLIDE 135

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . .

slide-136
SLIDE 136

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility

slide-137
SLIDE 137

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

slide-138
SLIDE 138

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files.

slide-139
SLIDE 139

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

slide-140
SLIDE 140

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file.

slide-141
SLIDE 141

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table.

slide-142
SLIDE 142

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table. ◮ Symbol was preempted.

slide-143
SLIDE 143

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table. ◮ Symbol was preempted. ◮ . . .

slide-144
SLIDE 144

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table. ◮ Symbol was preempted. ◮ . . .

◮ Plugin decides which symbols to keep and creates an ELF file.

slide-145
SLIDE 145

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table. ◮ Symbol was preempted. ◮ . . .

◮ Plugin decides which symbols to keep and creates an ELF file. ◮ Only now do we need a Module!

slide-146
SLIDE 146

LTO according to gold

◮ Requests the list of global symbols of each file.

◮ Defined/Undefined/Weak/. . . ◮ Visibility ◮ Comdat Key

◮ Does symbol resolution. May close some files. ◮ Notifies the plugin of the result for each symbol.

◮ Symbol is used from an ELF or BC file. ◮ Symbol is used by the symbol table. ◮ Symbol was preempted. ◮ . . .

◮ Plugin decides which symbols to keep and creates an ELF file. ◮ Only now do we need a Module! ◮ Can trim the Module before IR linking!

slide-147
SLIDE 147

Reorganizing lib/LTO, tools/gold and tools/lto

slide-148
SLIDE 148

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

slide-149
SLIDE 149

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it.

slide-150
SLIDE 150

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

slide-151
SLIDE 151

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

slide-152
SLIDE 152

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

◮ Implemented on top of lib/Object and lib/LTO.

slide-153
SLIDE 153

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

◮ Implemented on top of lib/Object and lib/LTO. ◮ No longer uses a C api.

slide-154
SLIDE 154

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

◮ Implemented on top of lib/Object and lib/LTO. ◮ No longer uses a C api. ◮ Will serve to test LTO strategies.

slide-155
SLIDE 155

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

◮ Implemented on top of lib/Object and lib/LTO. ◮ No longer uses a C api. ◮ Will serve to test LTO strategies.

◮ tools/lto

slide-156
SLIDE 156

Reorganizing lib/LTO, tools/gold and tools/lto

◮ lib/LTO logic needed by any linker doing lto.

◮ Codegen can add calls to memcpy, don’t drop it. ◮ MCStreamer to find asm symbols.

◮ tools/gold

◮ Implemented on top of lib/Object and lib/LTO. ◮ No longer uses a C api. ◮ Will serve to test LTO strategies.

◮ tools/lto

◮ Free to be just the api used by ld64 again.

slide-157
SLIDE 157

Metadata issues

slide-158
SLIDE 158

Metadata issues

◮ We have support for lazy loading function bodies.

slide-159
SLIDE 159

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded.

slide-160
SLIDE 160

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded. ◮ It is uniqued at the context level. Many nodes end up dead.

slide-161
SLIDE 161

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded. ◮ It is uniqued at the context level. Many nodes end up dead. ◮ Making Module own metadata would help gold, hurt lld.

slide-162
SLIDE 162

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded. ◮ It is uniqued at the context level. Many nodes end up dead. ◮ Making Module own metadata would help gold, hurt lld. ◮ Lazy loading it during IR linking should be possible.

slide-163
SLIDE 163

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded. ◮ It is uniqued at the context level. Many nodes end up dead. ◮ Making Module own metadata would help gold, hurt lld. ◮ Lazy loading it during IR linking should be possible. ◮ Maybe do a GC pass? Slower than having the module own it.

slide-164
SLIDE 164

Metadata issues

◮ We have support for lazy loading function bodies. ◮ Debug metadata is larger than code and not lazy loaded. ◮ It is uniqued at the context level. Many nodes end up dead. ◮ Making Module own metadata would help gold, hurt lld. ◮ Lazy loading it during IR linking should be possible. ◮ Maybe do a GC pass? Slower than having the module own it. ◮ Might still need to find a denser representation.

slide-165
SLIDE 165

Making LTO useful

slide-166
SLIDE 166

Making LTO useful

◮ One optimization decision can prevent other optimizations.

slide-167
SLIDE 167

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

slide-168
SLIDE 168

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

slide-169
SLIDE 169

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

◮ Try to find loop bounds before unrolling.

slide-170
SLIDE 170

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

◮ Try to find loop bounds before unrolling.

◮ LLVM is fairly well tuned for these.

slide-171
SLIDE 171

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

◮ Try to find loop bounds before unrolling.

◮ LLVM is fairly well tuned for these. ◮ Under the assumption it will never see the code again :-(

slide-172
SLIDE 172

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

◮ Try to find loop bounds before unrolling.

◮ LLVM is fairly well tuned for these. ◮ Under the assumption it will never see the code again :-( ◮ We should probably drop some passes with -flto (loop-unroll,

vectorize).

slide-173
SLIDE 173

Making LTO useful

◮ One optimization decision can prevent other optimizations.

◮ Inlining C in B can prevent inlining B in A.

◮ Some optimization order is also important.

◮ Try to find loop bounds before unrolling.

◮ LLVM is fairly well tuned for these. ◮ Under the assumption it will never see the code again :-( ◮ We should probably drop some passes with -flto (loop-unroll,

vectorize).

◮ Others (inliner) should know that -flto is being used.

slide-174
SLIDE 174

Profiling and LTO

slide-175
SLIDE 175

Profiling and LTO

◮ We need to get basic LTO working well first.

slide-176
SLIDE 176

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer.

slide-177
SLIDE 177

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

slide-178
SLIDE 178

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half.

slide-179
SLIDE 179

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run.

slide-180
SLIDE 180

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

slide-181
SLIDE 181

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

slide-182
SLIDE 182

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

◮ Just cherry pick hot functions for LTO.

slide-183
SLIDE 183

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

◮ Just cherry pick hot functions for LTO. ◮ And use the others from the ELF part (-ffunction-sections).

slide-184
SLIDE 184

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

◮ Just cherry pick hot functions for LTO. ◮ And use the others from the ELF part (-ffunction-sections).

◮ LIPO style build also possible.

slide-185
SLIDE 185

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

◮ Just cherry pick hot functions for LTO. ◮ And use the others from the ELF part (-ffunction-sections).

◮ LIPO style build also possible.

◮ In the second build, read some funtions from other IR files.

slide-186
SLIDE 186

Profiling and LTO

◮ We need to get basic LTO working well first. ◮ Lots of possibilities, have to be careful to not over engineer. ◮ Should we support fat binaries?

◮ Do a first build using the ELF half. ◮ Do a sampling run. ◮ Only LTO relink with the profile info.

◮ Partial LTO.

◮ Just cherry pick hot functions for LTO. ◮ And use the others from the ELF part (-ffunction-sections).

◮ LIPO style build also possible.

◮ In the second build, read some funtions from other IR files. ◮ Add them as available-externally to the current TU.