llvm.org GIT mirror llvm / fbe1078
[ThinLTO] Add an option to disable (thin)lto internalization. Summary: LTO and ThinLTO optimizes the IR differently. One source of differences is the amount of internalizations that can happen. Add an option to enable/disable internalization so that other differences can be studied in isolation. e.g. inlining. There are other things lto and thinlto do differently, I will add flags to enable/disable them as needed. Reviewers: tejohnson, pcc, steven_wu Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, dang, llvm-commits Differential Revision: https://reviews.llvm.org/D53294 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346140 91177308-0d34-0410-b5e6-96231b3b80d8 Xin Tong 10 months ago
4 changed file(s) with 75 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4646 #include "llvm/Target/TargetOptions.h"
4747 #include
4848 #include
49
50 /// Enable global value internalization in LTO.
51 extern llvm::cl::opt EnableLTOInternalization;
4952
5053 namespace llvm {
5154 template class ArrayRef;
232235 unsigned OptLevel = 2;
233236 lto_diagnostic_handler_t DiagHandler = nullptr;
234237 void *DiagContext = nullptr;
235 bool ShouldInternalize = true;
238 bool ShouldInternalize = EnableLTOInternalization;
236239 bool ShouldEmbedUselists = false;
237240 bool ShouldRestoreGlobalsLinkage = false;
238241 TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_ObjectFile;
5454 static cl::opt
5555 DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden,
5656 cl::desc("Dump the SCCs in the ThinLTO index's callgraph"));
57
58 /// Enable global value internalization in LTO.
59 cl::opt EnableLTOInternalization(
60 "enable-lto-internalization", cl::init(true), cl::Hidden,
61 cl::desc("Enable global value internalization in LTO"));
5762
5863 // Returns a unique hash for the Module considering the current list of
5964 // export/import and other global analysis results.
343348 if (isExported(S->modulePath(), GUID)) {
344349 if (GlobalValue::isLocalLinkage(S->linkage()))
345350 S->setLinkage(GlobalValue::ExternalLinkage);
346 } else if (!GlobalValue::isLocalLinkage(S->linkage()))
351 } else if (EnableLTOInternalization &&
352 !GlobalValue::isLocalLinkage(S->linkage()))
347353 S->setLinkage(GlobalValue::InternalLinkage);
348354 }
349355 }
875881 continue;
876882 GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
877883 : GlobalValue::UnnamedAddr::None);
878 if (R.second.Partition == 0)
884 if (EnableLTOInternalization && R.second.Partition == 0)
879885 GV->setLinkage(GlobalValue::InternalLinkage);
880886 }
881887
0 ; RUN: opt %s -o %t1.bc
1
2 ; RUN: llvm-lto %t1.bc -o %t1.save.opt --exported-symbol=_foo -save-merged-module -O0
3 ; RUN: llvm-dis < %t1.save.opt.merged.bc | FileCheck %s --check-prefix=INTERNALIZE
4
5 ; Test the enable-lto-internalization option by setting it to false.
6 ; This makes sure internalization does not happen.
7 ; RUN: llvm-lto %t1.bc -enable-lto-internalization=false -o %t1.save.opt \
8 ; RUN: --exported-symbol=_foo -save-merged-module -O0
9 ; RUN: llvm-dis < %t1.save.opt.merged.bc | FileCheck %s --check-prefix=INTERNALIZE-OPTION-DISABLE
10
11 ; RUN: llvm-lto2 run %t1.bc -o %t.o -save-temps \
12 ; RUN: -r=%t1.bc,_foo,pxl \
13 ; RUN: -r=%t1.bc,_bar,pl
14 ; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2
15
16 ; Test the enable-lto-internalization option by setting it to false.
17 ; This makes sure internalization does not happen in runRegularLTO().
18 ; RUN: llvm-lto2 run %t1.bc -o %t.o -save-temps -enable-lto-internalization=false \
19 ; RUN: -r=%t1.bc,_foo,pxl \
20 ; RUN: -r=%t1.bc,_bar,pl
21 ; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2-OPTION-DISABLE
22
23 ; INTERNALIZE: define void @foo
24 ; INTERNALIZE: define internal void @bar
25 ; INTERNALIZE-OPTION-DISABLE: define void @foo
26 ; INTERNALIZE-OPTION-DISABLE: define void @bar
27 ; INTERNALIZE2: define dso_local void @foo
28 ; INTERNALIZE2: define internal void @bar
29 ; INTERNALIZE2-OPTION-DISABLE: define dso_local void @foo
30 ; INTERNALIZE2-OPTION-DISABLE: define dso_local void @bar
31
32 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-apple-macosx10.11.0"
34
35 define void @foo() {
36 call void @bar()
37 ret void
38 }
39 define void @bar() {
40 ret void
41 }
11 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc
22 ; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=REGULAR
33 ; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc -o - --exported-symbol=foo | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZE
4
5 ; Test the enable-lto-internalization option by setting it to false.
6 ; This makes sure indices are not marked as internallinkage and therefore
7 ; internalization does not happen.
8 ; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc %t1.bc \
9 ; RUN: -enable-lto-internalization=false --exported-symbol=foo
10 ; RUN: llvm-dis < %t1.bc.thinlto.internalized.bc | FileCheck %s --check-prefix=INTERNALIZE-OPTION-DISABLE
411
512 ; RUN: llvm-lto2 run %t1.bc -o %t.o -save-temps \
613 ; RUN: -r=%t1.bc,_foo,pxl \
815 ; RUN: -r=%t1.bc,_linkonce_func,pl
916 ; RUN: llvm-dis < %t.o.1.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2
1017
18 ; Test the enable-lto-internalization option by setting it to false.
19 ; This makes sure indices are not marked as internallinkage and therefore
20 ; internalization does not happen.
21 ; RUN: llvm-lto2 run %t1.bc -o %t.o -save-temps -enable-lto-internalization=false \
22 ; RUN: -r=%t1.bc,_foo,pxl \
23 ; RUN: -r=%t1.bc,_bar,pl \
24 ; RUN: -r=%t1.bc,_linkonce_func,pl
25 ; RUN: llvm-dis < %t.o.1.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2-OPTION-DISABLE
1126
1227 ; REGULAR: define void @foo
1328 ; REGULAR: define void @bar
1530 ; INTERNALIZE: define void @foo
1631 ; INTERNALIZE: define internal void @bar
1732 ; INTERNALIZE: define internal void @linkonce_func()
33 ; INTERNALIZE-OPTION-DISABLE: define void @foo
34 ; INTERNALIZE-OPTION-DISABLE: define void @bar
35 ; INTERNALIZE-OPTION-DISABLE: define linkonce void @linkonce_func()
1836 ; INTERNALIZE2: define dso_local void @foo
1937 ; INTERNALIZE2: define internal void @bar
2038 ; INTERNALIZE2: define internal void @linkonce_func()
39 ; INTERNALIZE2-OPTION-DISABLE: define dso_local void @foo
40 ; INTERNALIZE2-OPTION-DISABLE: define dso_local void @bar
41 ; INTERNALIZE2-OPTION-DISABLE: define weak dso_local void @linkonce_func()
2142
2243 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2344 target triple = "x86_64-apple-macosx10.11.0"