@@ -1864,21 +1864,22 @@ void jl_merge_module(orc::ThreadSafeModule &destTSM, orc::ThreadSafeModule srcTS
1864
1864
assert (dest.getDataLayout () == src.getDataLayout () && " Cannot merge modules with different data layouts!" );
1865
1865
assert (dest.getTargetTriple () == src.getTargetTriple () && " Cannot merge modules with different target triples!" );
1866
1866
1867
- for (Module::global_iterator I = src.global_begin (), E = src.global_end (); I != E;) {
1868
- GlobalVariable *sG = &*I;
1869
- GlobalVariable *dG = cast_or_null<GlobalVariable>(dest.getNamedValue (sG ->getName ()));
1870
- ++I;
1867
+ for (auto &SG : make_early_inc_range (src.globals ())) {
1868
+ GlobalVariable *dG = cast_or_null<GlobalVariable>(dest.getNamedValue (SG.getName ()));
1869
+ if (SG.hasLocalLinkage ()) {
1870
+ dG = nullptr ;
1871
+ }
1871
1872
// Replace a declaration with the definition:
1872
- if (dG) {
1873
- if (sG -> isDeclaration ()) {
1874
- sG -> replaceAllUsesWith (dG);
1875
- sG -> eraseFromParent ();
1873
+ if (dG && !dG-> hasLocalLinkage () ) {
1874
+ if (SG. isDeclaration ()) {
1875
+ SG. replaceAllUsesWith (dG);
1876
+ SG. eraseFromParent ();
1876
1877
continue ;
1877
1878
}
1878
1879
// // If we start using llvm.used, we need to enable and test this
1879
- // else if (!dG->isDeclaration() && dG->hasAppendingLinkage() && sG-> hasAppendingLinkage()) {
1880
+ // else if (!dG->isDeclaration() && dG->hasAppendingLinkage() && SG. hasAppendingLinkage()) {
1880
1881
// auto *dCA = cast<ConstantArray>(dG->getInitializer());
1881
- // auto *sCA = cast<ConstantArray>(sG-> getInitializer());
1882
+ // auto *sCA = cast<ConstantArray>(SG. getInitializer());
1882
1883
// SmallVector<Constant *, 16> Init;
1883
1884
// for (auto &Op : dCA->operands())
1884
1885
// Init.push_back(cast_or_null<Constant>(Op));
@@ -1890,67 +1891,69 @@ void jl_merge_module(orc::ThreadSafeModule &destTSM, orc::ThreadSafeModule srcTS
1890
1891
// GlobalValue::AppendingLinkage, ConstantArray::get(ATy, Init), "",
1891
1892
// dG->getThreadLocalMode(), dG->getType()->getAddressSpace());
1892
1893
// GV->copyAttributesFrom(dG);
1893
- // sG-> replaceAllUsesWith(GV);
1894
+ // SG. replaceAllUsesWith(GV);
1894
1895
// dG->replaceAllUsesWith(GV);
1895
- // GV->takeName(sG );
1896
- // sG-> eraseFromParent();
1896
+ // GV->takeName(SG );
1897
+ // SG. eraseFromParent();
1897
1898
// dG->eraseFromParent();
1898
1899
// continue;
1899
1900
// }
1900
1901
else {
1901
- assert (dG->isDeclaration () || dG->getInitializer () == sG -> getInitializer ());
1902
- dG->replaceAllUsesWith (sG );
1902
+ assert (dG->isDeclaration () || dG->getInitializer () == SG. getInitializer ());
1903
+ dG->replaceAllUsesWith (&SG );
1903
1904
dG->eraseFromParent ();
1904
1905
}
1905
1906
}
1906
1907
// Reparent the global variable:
1907
- sG -> removeFromParent ();
1908
- dest.getGlobalList ().push_back (sG );
1908
+ SG. removeFromParent ();
1909
+ dest.getGlobalList ().push_back (&SG );
1909
1910
// Comdat is owned by the Module
1910
- sG -> setComdat (nullptr );
1911
+ SG. setComdat (nullptr );
1911
1912
}
1912
1913
1913
- for (Module::iterator I = src.begin (), E = src.end (); I != E;) {
1914
- Function *sG = &*I;
1915
- Function *dG = cast_or_null<Function>(dest.getNamedValue (sG ->getName ()));
1916
- ++I;
1914
+ for (auto &SG : make_early_inc_range (src)) {
1915
+ Function *dG = cast_or_null<Function>(dest.getNamedValue (SG.getName ()));
1916
+ if (SG.hasLocalLinkage ()) {
1917
+ dG = nullptr ;
1918
+ }
1917
1919
// Replace a declaration with the definition:
1918
- if (dG) {
1919
- if (sG -> isDeclaration ()) {
1920
- sG -> replaceAllUsesWith (dG);
1921
- sG -> eraseFromParent ();
1920
+ if (dG && !dG-> hasLocalLinkage () ) {
1921
+ if (SG. isDeclaration ()) {
1922
+ SG. replaceAllUsesWith (dG);
1923
+ SG. eraseFromParent ();
1922
1924
continue ;
1923
1925
}
1924
1926
else {
1925
1927
assert (dG->isDeclaration ());
1926
- dG->replaceAllUsesWith (sG );
1928
+ dG->replaceAllUsesWith (&SG );
1927
1929
dG->eraseFromParent ();
1928
1930
}
1929
1931
}
1930
1932
// Reparent the global variable:
1931
- sG -> removeFromParent ();
1932
- dest.getFunctionList ().push_back (sG );
1933
+ SG. removeFromParent ();
1934
+ dest.getFunctionList ().push_back (&SG );
1933
1935
// Comdat is owned by the Module
1934
- sG -> setComdat (nullptr );
1936
+ SG. setComdat (nullptr );
1935
1937
}
1936
1938
1937
- for (Module::alias_iterator I = src.alias_begin (), E = src.alias_end (); I != E;) {
1938
- GlobalAlias *sG = &*I;
1939
- GlobalAlias *dG = cast_or_null<GlobalAlias>(dest.getNamedValue (sG ->getName ()));
1940
- ++I;
1941
- if (dG) {
1939
+ for (auto &SG : make_early_inc_range (src.aliases ())) {
1940
+ GlobalAlias *dG = cast_or_null<GlobalAlias>(dest.getNamedValue (SG.getName ()));
1941
+ if (SG.hasLocalLinkage ()) {
1942
+ dG = nullptr ;
1943
+ }
1944
+ if (dG && !dG->hasLocalLinkage ()) {
1942
1945
if (!dG->isDeclaration ()) { // aliases are always definitions, so this test is reversed from the above two
1943
- sG -> replaceAllUsesWith (dG);
1944
- sG -> eraseFromParent ();
1946
+ SG. replaceAllUsesWith (dG);
1947
+ SG. eraseFromParent ();
1945
1948
continue ;
1946
1949
}
1947
1950
else {
1948
- dG->replaceAllUsesWith (sG );
1951
+ dG->replaceAllUsesWith (&SG );
1949
1952
dG->eraseFromParent ();
1950
1953
}
1951
1954
}
1952
- sG -> removeFromParent ();
1953
- dest.getAliasList ().push_back (sG );
1955
+ SG. removeFromParent ();
1956
+ dest.getAliasList ().push_back (&SG );
1954
1957
}
1955
1958
1956
1959
// metadata nodes need to be explicitly merged not just copied
0 commit comments