[ThinLTO]Record import type in GlobalValueSummary::GVFlags (#87597)
The motivating use case is to support import the function declaration across modules to construct call graph edges for indirect calls [1] when importing the function definition costs too much compile time (e.g., the function is too large has no `noinline` attribute). 1. Currently, when the compiled IR module doesn't have a function definition but its postlink combined summary contains the function summary or a global alias summary with this function as aliasee, the function definition will be imported from source module by IRMover. The implementation is in FunctionImporter::importFunctions [2] 2. In order for FunctionImporter to import a declaration of a function, both function summary and alias summary need to carry the def / decl state. Specifically, all existing summary fields doesn't differ across import modules, but the def / decl state of is decided by `<ImportModule, Function>`. This change encodes the def/decl state in `GlobalValueSummary::GVFlags`. In the subsequent changes 1. The indexing step `computeImportForModule` [3] will compute the set of definitions and the set of declarations for each module, and passing on the information to bitcode writer. 2. Bitcode writer will look up the def/decl state and sets the state when it writes out the flag value. This is demonstrated in https://github.com/llvm/llvm-project/pull/87600 3. Function importer will read the def/decl state when reading the combined summary to figure out two sets of global values, and IRMover will be updated to import the declaration (aka linkGlobalValuePrototype [4]) into the destination module. - The next change is https://github.com/llvm/llvm-project/pull/87600 [1] mentioned in rfc https://discourse.llvm.org/t/rfc-for-better-call-graph-sort-build-a-more-complete-call-graph-by-adding-more-indirect-call-edges/74029#support-cross-module-function-declaration-import-5 [2]3b337242ee/llvm/lib/Transforms/IPO/FunctionImport.cpp (L1608-L1764)[3]3b337242ee/llvm/lib/Transforms/IPO/FunctionImport.cpp (L856)[4]3b337242ee/llvm/lib/Linker/IRMover.cpp (L605)
This commit is contained in:
@@ -301,6 +301,8 @@ namespace llvm {
|
||||
bool &DSOLocal);
|
||||
void parseOptionalDSOLocal(bool &DSOLocal);
|
||||
void parseOptionalVisibility(unsigned &Res);
|
||||
bool parseOptionalImportType(lltok::Kind Kind,
|
||||
GlobalValueSummary::ImportKind &Res);
|
||||
void parseOptionalDLLStorageClass(unsigned &Res);
|
||||
bool parseOptionalCallingConv(unsigned &CC);
|
||||
bool parseOptionalAlignment(MaybeAlign &Alignment,
|
||||
|
||||
@@ -370,6 +370,9 @@ enum Kind {
|
||||
kw_live,
|
||||
kw_dsoLocal,
|
||||
kw_canAutoHide,
|
||||
kw_importType,
|
||||
kw_definition,
|
||||
kw_declaration,
|
||||
kw_function,
|
||||
kw_insts,
|
||||
kw_funcFlags,
|
||||
|
||||
@@ -432,6 +432,18 @@ public:
|
||||
/// Sububclass discriminator (for dyn_cast<> et al.)
|
||||
enum SummaryKind : unsigned { AliasKind, FunctionKind, GlobalVarKind };
|
||||
|
||||
enum ImportKind : unsigned {
|
||||
// The global value definition corresponding to the summary should be
|
||||
// imported from source module
|
||||
Definition = 0,
|
||||
|
||||
// When its definition doesn't exist in the destination module and not
|
||||
// imported (e.g., function is too large to be inlined), the global value
|
||||
// declaration corresponding to the summary should be imported, or the
|
||||
// attributes from summary should be annotated on the function declaration.
|
||||
Declaration = 1,
|
||||
};
|
||||
|
||||
/// Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
|
||||
struct GVFlags {
|
||||
/// The linkage type of the associated global value.
|
||||
@@ -472,14 +484,19 @@ public:
|
||||
/// means the symbol was externally visible.
|
||||
unsigned CanAutoHide : 1;
|
||||
|
||||
/// This field is written by the ThinLTO indexing step to postlink combined
|
||||
/// summary. The value is interpreted as 'ImportKind' enum defined above.
|
||||
unsigned ImportType : 1;
|
||||
|
||||
/// Convenience Constructors
|
||||
explicit GVFlags(GlobalValue::LinkageTypes Linkage,
|
||||
GlobalValue::VisibilityTypes Visibility,
|
||||
bool NotEligibleToImport, bool Live, bool IsLocal,
|
||||
bool CanAutoHide)
|
||||
bool CanAutoHide, ImportKind ImportType)
|
||||
: Linkage(Linkage), Visibility(Visibility),
|
||||
NotEligibleToImport(NotEligibleToImport), Live(Live),
|
||||
DSOLocal(IsLocal), CanAutoHide(CanAutoHide) {}
|
||||
DSOLocal(IsLocal), CanAutoHide(CanAutoHide),
|
||||
ImportType(static_cast<unsigned>(ImportType)) {}
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -564,6 +581,12 @@ public:
|
||||
|
||||
bool canAutoHide() const { return Flags.CanAutoHide; }
|
||||
|
||||
bool shouldImportAsDecl() const {
|
||||
return Flags.ImportType == GlobalValueSummary::ImportKind::Declaration;
|
||||
}
|
||||
|
||||
void setImportKind(ImportKind IK) { Flags.ImportType = IK; }
|
||||
|
||||
GlobalValue::VisibilityTypes getVisibility() const {
|
||||
return (GlobalValue::VisibilityTypes)Flags.Visibility;
|
||||
}
|
||||
@@ -813,7 +836,7 @@ public:
|
||||
GlobalValue::LinkageTypes::AvailableExternallyLinkage,
|
||||
GlobalValue::DefaultVisibility,
|
||||
/*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
|
||||
/*CanAutoHide=*/false),
|
||||
/*CanAutoHide=*/false, GlobalValueSummary::ImportKind::Definition),
|
||||
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
|
||||
std::vector<ValueInfo>(), std::move(Edges),
|
||||
std::vector<GlobalValue::GUID>(),
|
||||
|
||||
@@ -138,6 +138,7 @@ template <> struct MappingTraits<TypeIdSummary> {
|
||||
struct FunctionSummaryYaml {
|
||||
unsigned Linkage, Visibility;
|
||||
bool NotEligibleToImport, Live, IsLocal, CanAutoHide;
|
||||
unsigned ImportType;
|
||||
std::vector<uint64_t> Refs;
|
||||
std::vector<uint64_t> TypeTests;
|
||||
std::vector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
|
||||
@@ -183,6 +184,7 @@ template <> struct MappingTraits<FunctionSummaryYaml> {
|
||||
io.mapOptional("Live", summary.Live);
|
||||
io.mapOptional("Local", summary.IsLocal);
|
||||
io.mapOptional("CanAutoHide", summary.CanAutoHide);
|
||||
io.mapOptional("ImportType", summary.ImportType);
|
||||
io.mapOptional("Refs", summary.Refs);
|
||||
io.mapOptional("TypeTests", summary.TypeTests);
|
||||
io.mapOptional("TypeTestAssumeVCalls", summary.TypeTestAssumeVCalls);
|
||||
@@ -227,7 +229,8 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
|
||||
static_cast<GlobalValue::LinkageTypes>(FSum.Linkage),
|
||||
static_cast<GlobalValue::VisibilityTypes>(FSum.Visibility),
|
||||
FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal,
|
||||
FSum.CanAutoHide),
|
||||
FSum.CanAutoHide,
|
||||
static_cast<GlobalValueSummary::ImportKind>(FSum.ImportType)),
|
||||
/*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, Refs,
|
||||
ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
|
||||
std::move(FSum.TypeTestAssumeVCalls),
|
||||
@@ -251,9 +254,9 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
|
||||
static_cast<bool>(FSum->flags().NotEligibleToImport),
|
||||
static_cast<bool>(FSum->flags().Live),
|
||||
static_cast<bool>(FSum->flags().DSOLocal),
|
||||
static_cast<bool>(FSum->flags().CanAutoHide), Refs,
|
||||
FSum->type_tests(), FSum->type_test_assume_vcalls(),
|
||||
FSum->type_checked_load_vcalls(),
|
||||
static_cast<bool>(FSum->flags().CanAutoHide),
|
||||
FSum->flags().ImportType, Refs, FSum->type_tests(),
|
||||
FSum->type_test_assume_vcalls(), FSum->type_checked_load_vcalls(),
|
||||
FSum->type_test_assume_const_vcalls(),
|
||||
FSum->type_checked_load_const_vcalls()});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user