26
26
#include " llvm/Transforms/IPO/PassManagerBuilder.h"
27
27
28
28
#if LLVM_VERSION_GE(4, 0)
29
- #include " llvm/Object/ModuleSummaryIndexObjectFile.h"
30
29
#include " llvm/Transforms/IPO/AlwaysInliner.h"
31
30
#include " llvm/Transforms/IPO/FunctionImport.h"
32
31
#include " llvm/Transforms/Utils/FunctionImportUtils.h"
33
32
#include " llvm/LTO/LTO.h"
33
+ #if LLVM_VERSION_LE(4, 0)
34
+ #include " llvm/Object/ModuleSummaryIndexObjectFile.h"
35
+ #endif
34
36
#endif
35
37
36
38
#include " llvm-c/Transforms/PassManagerBuilder.h"
@@ -888,6 +890,28 @@ addPreservedGUID(const ModuleSummaryIndex &Index,
888
890
return ;
889
891
Preserved.insert (GUID);
890
892
893
+ #if LLVM_VERSION_GE(5, 0)
894
+ auto Info = Index.getValueInfo (GUID);
895
+ if (!Info) {
896
+ return ;
897
+ }
898
+ for (auto &Summary : Info.getSummaryList ()) {
899
+ for (auto &Ref : Summary->refs ()) {
900
+ addPreservedGUID (Index, Preserved, Ref.getGUID ());
901
+ }
902
+
903
+ GlobalValueSummary *GVSummary = Summary.get ();
904
+ if (isa<FunctionSummary>(GVSummary)) {
905
+ FunctionSummary *FS = cast<FunctionSummary>(GVSummary);
906
+ for (auto &Call: FS->calls ()) {
907
+ addPreservedGUID (Index, Preserved, Call.first .getGUID ());
908
+ }
909
+ for (auto &GUID: FS->type_tests ()) {
910
+ addPreservedGUID (Index, Preserved, GUID);
911
+ }
912
+ }
913
+ }
914
+ #else
891
915
auto SummaryList = Index.findGlobalValueSummaryList (GUID);
892
916
if (SummaryList == Index.end ())
893
917
return ;
@@ -919,6 +943,7 @@ addPreservedGUID(const ModuleSummaryIndex &Index,
919
943
addPreservedGUID (Index, Preserved, GUID);
920
944
}
921
945
}
946
+ #endif
922
947
}
923
948
924
949
// The main entry point for creating the global ThinLTO analysis. The structure
@@ -939,6 +964,12 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
939
964
940
965
Ret->ModuleMap [module->identifier ] = mem_buffer;
941
966
967
+ #if LLVM_VERSION_GE(5, 0)
968
+ if (Error Err = readModuleSummaryIndex (mem_buffer, Ret->Index , i)) {
969
+ LLVMRustSetLastError (toString (std::move (Err)).c_str ());
970
+ return nullptr ;
971
+ }
972
+ #else
942
973
Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
943
974
object::ModuleSummaryIndexObjectFile::create (mem_buffer);
944
975
if (!ObjOrErr) {
@@ -947,6 +978,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
947
978
}
948
979
auto Index = (*ObjOrErr)->takeIndex ();
949
980
Ret->Index .mergeFrom (std::move (Index), i);
981
+ #endif
950
982
}
951
983
952
984
// Collect for each module the list of function it defines (GUID -> Summary)
@@ -981,8 +1013,13 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
981
1013
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
982
1014
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
983
1015
for (auto &I : Ret->Index ) {
1016
+ #if LLVM_VERSION_GE(5, 0)
1017
+ if (I.second .SummaryList .size () > 1 )
1018
+ PrevailingCopy[I.first ] = getFirstDefinitionForLinker (I.second .SummaryList );
1019
+ #else
984
1020
if (I.second .size () > 1 )
985
1021
PrevailingCopy[I.first ] = getFirstDefinitionForLinker (I.second );
1022
+ #endif
986
1023
}
987
1024
auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
988
1025
const auto &Prevailing = PrevailingCopy.find (GUID);
0 commit comments