diff --git a/llvm/examples/ThinLtoJIT/ModuleIndex.cpp b/llvm/examples/ThinLtoJIT/ModuleIndex.cpp --- a/llvm/examples/ThinLtoJIT/ModuleIndex.cpp +++ b/llvm/examples/ThinLtoJIT/ModuleIndex.cpp @@ -425,7 +425,7 @@ if (GlobalValueSummary *S = getSummary(Guid)) { ModuleInfo &MI = MIs[S->modulePath()]; - // TODO: Infer symbol flags from the ThinLTO module summary. + MI.SymbolFlags[KV.first] = JITSymbolFlags::fromSummary(S); MI.Guids.push_back(Guid); if (!isa(S)) diff --git a/llvm/include/llvm/ExecutionEngine/JITSymbol.h b/llvm/include/llvm/ExecutionEngine/JITSymbol.h --- a/llvm/include/llvm/ExecutionEngine/JITSymbol.h +++ b/llvm/include/llvm/ExecutionEngine/JITSymbol.h @@ -30,6 +30,7 @@ namespace llvm { class GlobalValue; +class GlobalValueSummary; namespace object { @@ -161,6 +162,10 @@ /// value. static JITSymbolFlags fromGlobalValue(const GlobalValue &GV); + /// Construct a JITSymbolFlags value based on the flags of the given global + /// value summary. + static JITSymbolFlags fromSummary(GlobalValueSummary *S); + /// Construct a JITSymbolFlags value based on the flags of the given libobject /// symbol. static Expected diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp --- a/llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalValue.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/Object/ObjectFile.h" using namespace llvm; @@ -36,6 +37,22 @@ return Flags; } +JITSymbolFlags llvm::JITSymbolFlags::fromSummary(GlobalValueSummary *S) { + JITSymbolFlags Flags = JITSymbolFlags::None; + auto L = S->linkage(); + if (GlobalValue::isWeakLinkage(L) || GlobalValue::isLinkOnceLinkage(L)) + Flags |= JITSymbolFlags::Weak; + if (GlobalValue::isCommonLinkage(L)) + Flags |= JITSymbolFlags::Common; + if (GlobalValue::isExternalLinkage(L) || GlobalValue::isExternalWeakLinkage(L)) + Flags |= JITSymbolFlags::Exported; + + if (isa(S)) + Flags |= JITSymbolFlags::Callable; + + return Flags; +} + Expected llvm::JITSymbolFlags::fromObjectSymbol(const object::SymbolRef &Symbol) { JITSymbolFlags Flags = JITSymbolFlags::None;