Skip to content

Commit

Permalink
Move DevirtualizationManager to NodeFactory (#97855)
Browse files Browse the repository at this point in the history
This is prep work - I want to be able to use this from dependency analysis, not just codegen (`Compilation` is not available to dependency analysis, `NodeFactory` is). I think there are optimization opportunities around this.
  • Loading branch information
MichalStrehovsky authored Feb 3, 2024
1 parent df0778d commit 2361c00
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public abstract class Compilation : ICompilation
protected readonly NodeFactory _nodeFactory;
protected readonly Logger _logger;
protected readonly DebugInformationProvider _debugInformationProvider;
protected readonly DevirtualizationManager _devirtualizationManager;
private readonly IInliningPolicy _inliningPolicy;

public NameMangler NameMangler => _nodeFactory.NameMangler;
Expand All @@ -44,15 +43,13 @@ protected Compilation(
IEnumerable<ICompilationRootProvider> compilationRoots,
ILProvider ilProvider,
DebugInformationProvider debugInformationProvider,
DevirtualizationManager devirtualizationManager,
IInliningPolicy inliningPolicy,
Logger logger)
{
_dependencyGraph = dependencyGraph;
_nodeFactory = nodeFactory;
_logger = logger;
_debugInformationProvider = debugInformationProvider;
_devirtualizationManager = devirtualizationManager;
_inliningPolicy = inliningPolicy;

_dependencyGraph.ComputeDependencyRoutine += ComputeDependencyNodeDependencies;
Expand Down Expand Up @@ -108,7 +105,7 @@ public bool CanInline(MethodDesc caller, MethodDesc callee)

public bool CanConstructType(TypeDesc type)
{
return _devirtualizationManager.CanConstructType(type);
return NodeFactory.DevirtualizationManager.CanConstructType(type);
}

public DelegateCreationInfo GetDelegateCtor(TypeDesc delegateType, MethodDesc target, TypeDesc constrainedType, bool followVirtualDispatch)
Expand Down Expand Up @@ -215,22 +212,22 @@ public bool HasFixedSlotVTable(TypeDesc type)

public bool IsEffectivelySealed(TypeDesc type)
{
return _devirtualizationManager.IsEffectivelySealed(type);
return NodeFactory.DevirtualizationManager.IsEffectivelySealed(type);
}

public TypeDesc[] GetImplementingClasses(TypeDesc type)
{
return _devirtualizationManager.GetImplementingClasses(type);
return NodeFactory.DevirtualizationManager.GetImplementingClasses(type);
}

public bool IsEffectivelySealed(MethodDesc method)
{
return _devirtualizationManager.IsEffectivelySealed(method);
return NodeFactory.DevirtualizationManager.IsEffectivelySealed(method);
}

public MethodDesc ResolveVirtualMethod(MethodDesc declMethod, TypeDesc implType, out CORINFO_DEVIRTUALIZATION_DETAIL devirtualizationDetail)
{
return _devirtualizationManager.ResolveVirtualMethod(declMethod, implType, out devirtualizationDetail);
return NodeFactory.DevirtualizationManager.ResolveVirtualMethod(declMethod, implType, out devirtualizationDetail);
}

public bool NeedsRuntimeLookup(ReadyToRunHelperId lookupKind, object targetOfLookup)
Expand Down Expand Up @@ -264,7 +261,7 @@ public bool NeedsRuntimeLookup(ReadyToRunHelperId lookupKind, object targetOfLoo

public ReadyToRunHelperId GetLdTokenHelperForType(TypeDesc type)
{
bool canConstructPerWholeProgramAnalysis = _devirtualizationManager == null ? true : _devirtualizationManager.CanConstructType(type);
bool canConstructPerWholeProgramAnalysis = NodeFactory.DevirtualizationManager.CanConstructType(type);
bool creationAllowed = ConstructedEETypeNode.CreationAllowed(type);
return (canConstructPerWholeProgramAnalysis && creationAllowed)
? ReadyToRunHelperId.TypeHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ILCompiler.DependencyAnalysis
public sealed class ILScanNodeFactory : NodeFactory
{
public ILScanNodeFactory(CompilerTypeSystemContext context, CompilationModuleGroup compilationModuleGroup, MetadataManager metadataManager, InteropStubManager interopStubManager, NameMangler nameMangler, PreinitializationManager preinitManager)
: base(context, compilationModuleGroup, metadataManager, interopStubManager, nameMangler, new LazyGenericsDisabledPolicy(), new LazyVTableSliceProvider(), new LazyDictionaryLayoutProvider(), new InlinedThreadStatics(), new ExternSymbolsImportedNodeProvider(), preinitManager)
: base(context, compilationModuleGroup, metadataManager, interopStubManager, nameMangler, new LazyGenericsDisabledPolicy(), new LazyVTableSliceProvider(), new LazyDictionaryLayoutProvider(), new InlinedThreadStatics(), new ExternSymbolsImportedNodeProvider(), preinitManager, new DevirtualizationManager())
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public NodeFactory(
DictionaryLayoutProvider dictionaryLayoutProvider,
InlinedThreadStatics inlinedThreadStatics,
ImportedNodeProvider importedNodeProvider,
PreinitializationManager preinitializationManager)
PreinitializationManager preinitializationManager,
DevirtualizationManager devirtualizationManager)
{
_target = context.Target;
_context = context;
Expand All @@ -54,6 +55,7 @@ public NodeFactory(
LazyGenericsPolicy = lazyGenericsPolicy;
_importedNodeProvider = importedNodeProvider;
PreinitializationManager = preinitializationManager;
DevirtualizationManager = devirtualizationManager;
}

public void SetMarkingComplete()
Expand Down Expand Up @@ -103,6 +105,11 @@ public PreinitializationManager PreinitializationManager
get;
}

public DevirtualizationManager DevirtualizationManager
{
get;
}

public InteropStubManager InteropStubManager
{
get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal ILScanner(
DebugInformationProvider debugInformationProvider,
Logger logger,
int parallelism)
: base(dependencyGraph, nodeFactory, roots, ilProvider, debugInformationProvider, null, nodeFactory.CompilationModuleGroup, logger)
: base(dependencyGraph, nodeFactory, roots, ilProvider, debugInformationProvider, nodeFactory.CompilationModuleGroup, logger)
{
_helperCache = new HelperCache(this);
_parallelism = parallelism;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace ILCompiler.DependencyAnalysis
public sealed class RyuJitNodeFactory : NodeFactory
{
public RyuJitNodeFactory(CompilerTypeSystemContext context, CompilationModuleGroup compilationModuleGroup, MetadataManager metadataManager,
InteropStubManager interopStubManager, NameMangler nameMangler, VTableSliceProvider vtableSliceProvider, DictionaryLayoutProvider dictionaryLayoutProvider, InlinedThreadStatics inlinedThreadStatics, PreinitializationManager preinitializationManager)
: base(context, compilationModuleGroup, metadataManager, interopStubManager, nameMangler, new LazyGenericsDisabledPolicy(), vtableSliceProvider, dictionaryLayoutProvider, inlinedThreadStatics, new ExternSymbolsImportedNodeProvider(), preinitializationManager)
InteropStubManager interopStubManager, NameMangler nameMangler, VTableSliceProvider vtableSliceProvider, DictionaryLayoutProvider dictionaryLayoutProvider, InlinedThreadStatics inlinedThreadStatics, PreinitializationManager preinitializationManager,
DevirtualizationManager devirtualizationManager)
: base(context, compilationModuleGroup, metadataManager, interopStubManager, nameMangler, new LazyGenericsDisabledPolicy(), vtableSliceProvider, dictionaryLayoutProvider, inlinedThreadStatics, new ExternSymbolsImportedNodeProvider(), preinitializationManager, devirtualizationManager)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ internal RyuJitCompilation(
ILProvider ilProvider,
DebugInformationProvider debugInformationProvider,
Logger logger,
DevirtualizationManager devirtualizationManager,
IInliningPolicy inliningPolicy,
InstructionSetSupport instructionSetSupport,
ProfileDataManager profileDataManager,
MethodImportationErrorProvider errorProvider,
ReadOnlyFieldPolicy readOnlyFieldPolicy,
RyuJitCompilationOptions options,
int parallelism)
: base(dependencyGraph, nodeFactory, roots, ilProvider, debugInformationProvider, devirtualizationManager, inliningPolicy, logger)
: base(dependencyGraph, nodeFactory, roots, ilProvider, debugInformationProvider, inliningPolicy, logger)
{
_compilationOptions = options;
InstructionSetSupport = instructionSetSupport;
Expand All @@ -73,8 +72,7 @@ public override IEETypeNode NecessaryTypeSymbolIfPossible(TypeDesc type)
// information proving that it isn't, give RyuJIT the constructed symbol even
// though we just need the unconstructed one.
// https://github.com/dotnet/runtimelab/issues/1128
bool canPotentiallyConstruct = _devirtualizationManager == null
? true : _devirtualizationManager.CanConstructType(type);
bool canPotentiallyConstruct = NodeFactory.DevirtualizationManager.CanConstructType(type);
if (canPotentiallyConstruct)
return _nodeFactory.MaximallyConstructableType(type);

Expand All @@ -83,8 +81,7 @@ public override IEETypeNode NecessaryTypeSymbolIfPossible(TypeDesc type)

public FrozenRuntimeTypeNode NecessaryRuntimeTypeIfPossible(TypeDesc type)
{
bool canPotentiallyConstruct = _devirtualizationManager == null
? true : _devirtualizationManager.CanConstructType(type);
bool canPotentiallyConstruct = NodeFactory.DevirtualizationManager.CanConstructType(type);
if (canPotentiallyConstruct)
return _nodeFactory.SerializedMaximallyConstructableRuntimeTypeObject(type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public override ICompilation ToCompilation()
if (_resilient)
options |= RyuJitCompilationOptions.UseResilience;

var factory = new RyuJitNodeFactory(_context, _compilationGroup, _metadataManager, _interopStubManager, _nameMangler, _vtableSliceProvider, _dictionaryLayoutProvider, _inlinedThreadStatics, GetPreinitializationManager());
var factory = new RyuJitNodeFactory(_context, _compilationGroup, _metadataManager, _interopStubManager, _nameMangler, _vtableSliceProvider, _dictionaryLayoutProvider, _inlinedThreadStatics, GetPreinitializationManager(), _devirtualizationManager);

JitConfigProvider.Initialize(_context.Target, jitFlagBuilder.ToArray(), _ryujitOptions, _jitPath);
DependencyAnalyzerBase<NodeFactory> graph = CreateDependencyGraph(factory, new ObjectNode.ObjectNodeComparer(CompilerComparer.Instance));
return new RyuJitCompilation(graph, factory, _compilationRoots, _ilProvider, _debugInformationProvider, _logger, _devirtualizationManager, _inliningPolicy ?? _compilationGroup, _instructionSetSupport, _profileDataManager, _methodImportationErrorProvider, _readOnlyFieldPolicy, options, _parallelism);
return new RyuJitCompilation(graph, factory, _compilationRoots, _ilProvider, _debugInformationProvider, _logger, _inliningPolicy ?? _compilationGroup, _instructionSetSupport, _profileDataManager, _methodImportationErrorProvider, _readOnlyFieldPolicy, options, _parallelism);
}
}
}

0 comments on commit 2361c00

Please sign in to comment.