Skip to content

Commit d62469a

Browse files
Split ExternSymbolNode into two types for functions and data
This allows to distinguish the symbol type for a node with a simple type check.
1 parent 9e5e6aa commit d62469a

File tree

17 files changed

+81
-54
lines changed

17 files changed

+81
-54
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t
344344
case ReadyToRunHelperId.ObjectAllocator:
345345
{
346346
var type = (TypeDesc)targetOfLookup;
347-
return NodeFactory.ExternSymbol(JitHelper.GetNewObjectHelperForType(type));
347+
return NodeFactory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(type));
348348
}
349349

350350
default:

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternEETypeSymbolNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis
99
/// Represents a symbol that is defined externally but modelled as a type in the
1010
/// DependencyAnalysis infrastructure during compilation.
1111
/// </summary>
12-
public sealed class ExternEETypeSymbolNode : ExternSymbolNode, IEETypeNode
12+
public sealed class ExternEETypeSymbolNode : ExternDataSymbolNode, IEETypeNode
1313
{
1414
private TypeDesc _type;
1515

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternMethodSymbolNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis
99
/// Represents a symbol that is defined externally but modelled as a method
1010
/// in the DependencyAnalysis infrastructure during compilation
1111
/// </summary>
12-
public sealed class ExternMethodSymbolNode : ExternSymbolNode, IMethodNode
12+
public sealed class ExternMethodSymbolNode : ExternFunctionSymbolNode, IMethodNode
1313
{
1414
private MethodDesc _method;
1515

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolNode.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace ILCompiler.DependencyAnalysis
1111
{
1212
/// <summary>
1313
/// Represents a symbol that is defined externally and statically linked to the output obj file.
14+
/// When making a new node, do not derived from this class directly, derive from one of its subclasses
15+
/// (ExternFunctionSymbolNode / ExternDataSymbolNode) instead.
1416
/// </summary>
15-
public class ExternSymbolNode : SortableDependencyNode, ISortableSymbolNode
17+
public abstract class ExternSymbolNode : SortableDependencyNode, ISortableSymbolNode
1618
{
1719
private readonly Utf8String _name;
1820
private readonly bool _isIndirection;
1921

20-
public ExternSymbolNode(Utf8String name, bool isIndirection = false)
22+
protected ExternSymbolNode(Utf8String name, bool isIndirection = false)
2123
{
2224
_name = name;
2325
_isIndirection = isIndirection;
@@ -29,6 +31,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
2931
{
3032
sb.Append(_name);
3133
}
34+
3235
public int Offset => 0;
3336
public virtual bool RepresentsIndirectionCell => _isIndirection;
3437

@@ -42,8 +45,6 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
4245
public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory factory) => null;
4346

4447
#if !SUPPORT_JIT
45-
public override int ClassCode => 1092559304;
46-
4748
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
4849
{
4950
return _name.CompareTo(((ExternSymbolNode)other)._name);
@@ -56,11 +57,26 @@ public override string ToString()
5657
}
5758
}
5859

59-
public class AddressTakenExternSymbolNode : ExternSymbolNode
60+
/// <summary>
61+
/// Represents a function symbol that is defined externally and statically linked to the output obj file.
62+
/// </summary>
63+
public class ExternFunctionSymbolNode(Utf8String name, bool isIndirection = false) : ExternSymbolNode(name, isIndirection)
6064
{
61-
public AddressTakenExternSymbolNode(Utf8String name)
62-
: base(name) { }
65+
public override int ClassCode => 1452455506;
66+
}
6367

68+
public class AddressTakenExternFunctionSymbolNode(Utf8String name) : ExternFunctionSymbolNode(name)
69+
{
6470
public override int ClassCode => -45645737;
6571
}
72+
73+
/// <summary>
74+
/// Represents a data symbol that is defined externally and statically linked to the output obj file.
75+
/// </summary>
76+
public class ExternDataSymbolNode(Utf8String name) : ExternSymbolNode(name)
77+
{
78+
public override int ClassCode => 1428609964;
79+
80+
protected override string GetName(NodeFactory factory) => $"ExternDataSymbolNode {ToString()}";
81+
}
6682
}

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolsImportedNodeProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public override IEETypeNode ImportedEETypeNode(NodeFactory factory, TypeDesc typ
1515

1616
public override ISortableSymbolNode ImportedGCStaticNode(NodeFactory factory, MetadataType type)
1717
{
18-
return new ExternSymbolNode(GCStaticsNode.GetMangledName(type, factory.NameMangler));
18+
return new ExternDataSymbolNode(GCStaticsNode.GetMangledName(type, factory.NameMangler));
1919
}
2020

2121
public override ISortableSymbolNode ImportedNonGCStaticNode(NodeFactory factory, MetadataType type)
2222
{
23-
return new ExternSymbolNode(NonGCStaticsNode.GetMangledName(type, factory.NameMangler));
23+
return new ExternDataSymbolNode(NonGCStaticsNode.GetMangledName(type, factory.NameMangler));
2424
}
2525

2626
public override ISortableSymbolNode ImportedMethodDictionaryNode(NodeFactory factory, MethodDesc method)

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public ObjectAllocatorGenericLookupResult(TypeDesc type)
728728
public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultContext dictionary)
729729
{
730730
TypeDesc instantiatedType = _type.GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(dictionary.TypeInstantiation, dictionary.MethodInstantiation);
731-
return factory.ExternSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType));
731+
return factory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType));
732732
}
733733

734734
public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public NodeFactory(
4646
{
4747
_target = context.Target;
4848

49-
InitialInterfaceDispatchStub = new AddressTakenExternSymbolNode("RhpInitialDynamicInterfaceDispatch");
49+
InitialInterfaceDispatchStub = new AddressTakenExternFunctionSymbolNode("RhpInitialDynamicInterfaceDispatch");
5050

5151
_context = context;
5252
_compilationModuleGroup = compilationModuleGroup;
@@ -263,13 +263,17 @@ private void CreateNodeCaches()
263263
return new FieldRvaDataNode(key);
264264
});
265265

266-
_externSymbols = new NodeCache<string, ExternSymbolNode>((string name) =>
266+
_externFunctionSymbols = new NodeCache<string, ExternFunctionSymbolNode>((string name) =>
267267
{
268-
return new ExternSymbolNode(name);
268+
return new ExternFunctionSymbolNode(name);
269269
});
270-
_externIndirectSymbols = new NodeCache<string, ExternSymbolNode>((string name) =>
270+
_externIndirectFunctionSymbols = new NodeCache<string, ExternFunctionSymbolNode>((string name) =>
271271
{
272-
return new ExternSymbolNode(name, isIndirection: true);
272+
return new ExternFunctionSymbolNode(name, isIndirection: true);
273+
});
274+
_externDataSymbols = new NodeCache<string, ExternDataSymbolNode>((string name) =>
275+
{
276+
return new ExternDataSymbolNode(name);
273277
});
274278

275279
_pInvokeModuleFixups = new NodeCache<PInvokeModuleData, PInvokeModuleFixupNode>((PInvokeModuleData moduleData) =>
@@ -793,7 +797,7 @@ public ISortableSymbolNode TypeThreadStaticIndex(MetadataType type)
793797
}
794798
else
795799
{
796-
return ExternSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
800+
return ExternDataSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
797801
}
798802
}
799803

@@ -903,24 +907,31 @@ internal ISymbolNode GenericVariance(GenericVarianceDetails details)
903907
return _genericVariances.GetOrAdd(details);
904908
}
905909

906-
private NodeCache<string, ExternSymbolNode> _externSymbols;
910+
private NodeCache<string, ExternFunctionSymbolNode> _externFunctionSymbols;
907911

908-
public ISortableSymbolNode ExternSymbol(string name)
912+
public ISortableSymbolNode ExternFunctionSymbol(string name)
909913
{
910-
return _externSymbols.GetOrAdd(name);
914+
return _externFunctionSymbols.GetOrAdd(name);
911915
}
912916

913-
public ISortableSymbolNode ExternVariable(string name)
917+
private NodeCache<string, ExternFunctionSymbolNode> _externIndirectFunctionSymbols;
918+
919+
public ISortableSymbolNode ExternIndirectFunctionSymbol(string name)
914920
{
915-
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
916-
return _externSymbols.GetOrAdd(mangledName);
921+
return _externIndirectFunctionSymbols.GetOrAdd(name);
917922
}
918923

919-
private NodeCache<string, ExternSymbolNode> _externIndirectSymbols;
924+
private NodeCache<string, ExternDataSymbolNode> _externDataSymbols;
920925

921-
public ISortableSymbolNode ExternIndirectSymbol(string name)
926+
public ISortableSymbolNode ExternDataSymbol(string name)
927+
{
928+
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
929+
return _externDataSymbols.GetOrAdd(mangledName);
930+
}
931+
932+
public ISortableSymbolNode ExternVariable(string name)
922933
{
923-
return _externIndirectSymbols.GetOrAdd(name);
934+
return _externDataSymbols.GetOrAdd(name);
924935
}
925936

926937
private NodeCache<PInvokeModuleData, PInvokeModuleFixupNode> _pInvokeModuleFixups;

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeImportMethodNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis
99
/// <summary>
1010
/// Represents a method that is imported from the runtime library.
1111
/// </summary>
12-
public class RuntimeImportMethodNode : ExternSymbolNode, IMethodNode, ISymbolDefinitionNode
12+
public class RuntimeImportMethodNode : ExternFunctionSymbolNode, IMethodNode, ISymbolDefinitionNode
1313
{
1414
private MethodDesc _method;
1515

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM/ARMReadyToRunHelperNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected override void EmitCode(NodeFactory factory, ref ARMEmitter encoder, bo
128128
if (targetMethod.OwningType.IsInterface)
129129
{
130130
encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod));
131-
encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod"));
131+
encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod"));
132132
}
133133
else
134134
{

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder,
144144
if (targetMethod.OwningType.IsInterface)
145145
{
146146
encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod));
147-
encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod"));
147+
encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod"));
148148
}
149149
else
150150
{

0 commit comments

Comments
 (0)