llvm.org GIT mirror llvm / 18a65be
ThinLTO renaming: use module hash instead of position in the summary This is more robust to changes in the link ordering. Differential Revision: http://reviews.llvm.org/D18946 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266018 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 3 years ago
5 changed file(s) with 24 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
1919 #include "llvm/ADT/DenseSet.h"
2020 #include "llvm/ADT/STLExtras.h"
2121 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/StringExtras.h"
2223 #include "llvm/ADT/StringMap.h"
2324 #include "llvm/IR/Function.h"
2425 #include "llvm/IR/Module.h"
402403
403404 /// Convenience method for creating a promoted global name
404405 /// for the given value name of a local, and its original module's ID.
405 static std::string getGlobalNameForLocal(StringRef Name, uint64_t ModId) {
406 static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
406407 SmallString<256> NewName(Name);
407408 NewName += ".llvm.";
408 raw_svector_ostream(NewName) << ModId;
409 NewName += utohexstr(ModHash[0]); // Take the first 32 bits
409410 return NewName.str();
410411 }
411412
7979 (doPromoteLocalToGlobal(SGV) || isPerformingImport()))
8080 return ModuleSummaryIndex::getGlobalNameForLocal(
8181 SGV->getName(),
82 ImportIndex.getModuleId(SGV->getParent()->getModuleIdentifier()));
82 ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier()));
8383 return SGV->getName();
8484 }
8585
1212 ; Ensure statics are promoted/renamed correctly from this file (all but
1313 ; constant variable need promotion).
1414 ; RUN: llvm-link %t.bc -summary-index=%t3.thinlto.bc -S | FileCheck %s --check-prefix=EXPORTSTATIC
15 ; EXPORTSTATIC-DAG: @staticvar.llvm.1 = hidden global
15 ; EXPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = hidden global
1616 ; EXPORTSTATIC-DAG: @staticconstvar = internal unnamed_addr constant
17 ; EXPORTSTATIC-DAG: @P.llvm.1 = hidden global void ()* null
18 ; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.1
19 ; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.1
17 ; EXPORTSTATIC-DAG: @P.llvm.{{.*}} = hidden global void ()* null
18 ; EXPORTSTATIC-DAG: define hidden i32 @staticfunc.llvm.
19 ; EXPORTSTATIC-DAG: define hidden void @staticfunc2.llvm.
2020
2121 ; Ensure that both weak alias to an imported function and strong alias to a
2222 ; non-imported function are correctly turned into declarations.
6666 ; Ensure that imported static variable and function references are correctly
6767 ; promoted and renamed (including static constant variable).
6868 ; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=referencestatics:%t.bc -S | FileCheck %s --check-prefix=IMPORTSTATIC
69 ; IMPORTSTATIC-DAG: @staticvar.llvm.1 = external hidden global
70 ; IMPORTSTATIC-DAG: @staticconstvar.llvm.1 = internal unnamed_addr constant
69 ; IMPORTSTATIC-DAG: @staticvar.llvm.{{.*}} = external hidden global
70 ; IMPORTSTATIC-DAG: @staticconstvar.llvm.{{.*}} = internal unnamed_addr constant
7171 ; IMPORTSTATIC-DAG: define available_externally i32 @referencestatics
72 ; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.1
73 ; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.1
74 ; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.1
72 ; IMPORTSTATIC-DAG: %call = call i32 @staticfunc.llvm.
73 ; IMPORTSTATIC-DAG: %0 = load i32, i32* @staticvar.llvm.
74 ; IMPORTSTATIC-DAG: declare hidden i32 @staticfunc.llvm.
7575
7676 ; Ensure that imported global (external) function and variable references
7777 ; are handled correctly (including referenced variable imported as
8888
8989 ; Ensure that imported static function pointer correctly promoted and renamed.
9090 ; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=callfuncptr:%t.bc -S | FileCheck %s --check-prefix=IMPORTFUNCPTR
91 ; IMPORTFUNCPTR-DAG: @P.llvm.1 = external hidden global void ()*
91 ; IMPORTFUNCPTR-DAG: @P.llvm.{{.*}} = external hidden global void ()*
9292 ; IMPORTFUNCPTR-DAG: define available_externally void @callfuncptr
93 ; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.1
93 ; IMPORTFUNCPTR-DAG: %0 = load void ()*, void ()** @P.llvm.
9494
9595 ; Ensure that imported weak function reference/definition handled properly.
9696 ; Imported weak_any definition should be skipped with warning, and imported
44
55 ; Test import with default progressive instruction factor
66 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=10 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM-DEFAULT
7 ; INSTLIM-DEFAULT: call void @staticfunc2.llvm.2()
7 ; INSTLIM-DEFAULT: call void @staticfunc2.llvm.
88
99 ; Test import with a reduced progressive instruction factor
1010 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=10 -import-instr-evolution-factor=0.5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM-PROGRESSIVE
99
1010 ; Test import with smaller instruction limit
1111 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=5 -S | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIM5
12 ; INSTLIM5-NOT: @staticfunc.llvm.2
12 ; INSTLIM5-NOT: @staticfunc.llvm.
1313
1414 define i32 @main() #0 {
1515 entry:
4747 ; should in turn be imported as a promoted/renamed and hidden function.
4848 ; Ensure that the call is to the properly-renamed function.
4949 ; INSTLIMDEF-DAG: Import staticfunc
50 ; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.2()
51 ; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.2()
50 ; INSTLIMDEF-DAG: %call = call i32 @staticfunc.llvm.
51 ; INSTLIMDEF-DAG: define available_externally hidden i32 @staticfunc.llvm.
5252
5353 ; INSTLIMDEF-DAG: Import referenceglobals
5454 ; CHECK-DAG: define available_externally i32 @referenceglobals(i32 %i)
7373
7474 ; Ensure that all uses of local variable @P which has used in setfuncptr
7575 ; and callfuncptr are to the same promoted/renamed global.
76 ; CHECK-DAG: @P.llvm.2 = external hidden global void ()*
77 ; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.2,
78 ; CHECK-DAG: store void ()* @staticfunc2.llvm.2, void ()** @P.llvm.2,
76 ; CHECK-DAG: @P.llvm.{{.*}} = external hidden global void ()*
77 ; CHECK-DAG: %0 = load void ()*, void ()** @P.llvm.
78 ; CHECK-DAG: store void ()* @staticfunc2.llvm.{{.*}}, void ()** @P.llvm.
7979
8080 ; Won't import weak func
8181 ; CHECK-DAG: declare void @weakfunc(...)
8282 declare void @weakfunc(...) #1
8383
8484 ; INSTLIMDEF-DAG: Import funcwithpersonality
85 ; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.2() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
86 ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.2()
85 ; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
86 ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()
8787
8888 ; INSTLIMDEF-DAG: Import globalfunc2
8989 ; INSTLIMDEF-DAG: 9 function-import - Number of functions imported