Skip to content

Commit 93f79af

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 15bcd62 commit 93f79af

File tree

17 files changed

+80
-51
lines changed

17 files changed

+80
-51
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
@@ -335,7 +335,7 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t
335335
case ReadyToRunHelperId.ObjectAllocator:
336336
{
337337
var type = (TypeDesc)targetOfLookup;
338-
return NodeFactory.ExternSymbol(JitHelper.GetNewObjectHelperForType(type));
338+
return NodeFactory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(type));
339339
}
340340

341341
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 & 5 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

@@ -56,11 +59,26 @@ public override string ToString()
5659
}
5760
}
5861

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

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

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
@@ -45,7 +45,7 @@ public NodeFactory(
4545
{
4646
_target = context.Target;
4747

48-
InitialInterfaceDispatchStub = new AddressTakenExternSymbolNode("RhpInitialDynamicInterfaceDispatch");
48+
InitialInterfaceDispatchStub = new AddressTakenExternFunctionSymbolNode("RhpInitialDynamicInterfaceDispatch");
4949

5050
_context = context;
5151
_compilationModuleGroup = compilationModuleGroup;
@@ -256,13 +256,17 @@ private void CreateNodeCaches()
256256
return new FieldRvaDataNode(key);
257257
});
258258

259-
_externSymbols = new NodeCache<string, ExternSymbolNode>((string name) =>
259+
_externFunctionSymbols = new NodeCache<string, ExternFunctionSymbolNode>((string name) =>
260260
{
261-
return new ExternSymbolNode(name);
261+
return new ExternFunctionSymbolNode(name);
262262
});
263-
_externIndirectSymbols = new NodeCache<string, ExternSymbolNode>((string name) =>
263+
_externIndirectFunctionSymbols = new NodeCache<string, ExternFunctionSymbolNode>((string name) =>
264264
{
265-
return new ExternSymbolNode(name, isIndirection: true);
265+
return new ExternFunctionSymbolNode(name, isIndirection: true);
266+
});
267+
_externDataSymbols = new NodeCache<string, ExternDataSymbolNode>((string name) =>
268+
{
269+
return new ExternDataSymbolNode(name);
266270
});
267271

268272
_pInvokeModuleFixups = new NodeCache<PInvokeModuleData, PInvokeModuleFixupNode>((PInvokeModuleData moduleData) =>
@@ -776,7 +780,7 @@ public ISortableSymbolNode TypeThreadStaticIndex(MetadataType type)
776780
}
777781
else
778782
{
779-
return ExternSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
783+
return ExternDataSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
780784
}
781785
}
782786

@@ -886,24 +890,31 @@ internal ISymbolNode GenericVariance(GenericVarianceDetails details)
886890
return _genericVariances.GetOrAdd(details);
887891
}
888892

889-
private NodeCache<string, ExternSymbolNode> _externSymbols;
893+
private NodeCache<string, ExternFunctionSymbolNode> _externFunctionSymbols;
890894

891-
public ISortableSymbolNode ExternSymbol(string name)
895+
public ISortableSymbolNode ExternFunctionSymbol(string name)
892896
{
893-
return _externSymbols.GetOrAdd(name);
897+
return _externFunctionSymbols.GetOrAdd(name);
894898
}
895899

896-
public ISortableSymbolNode ExternVariable(string name)
900+
private NodeCache<string, ExternFunctionSymbolNode> _externIndirectFunctionSymbols;
901+
902+
public ISortableSymbolNode ExternIndirectFunctionSymbol(string name)
897903
{
898-
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
899-
return _externSymbols.GetOrAdd(mangledName);
904+
return _externIndirectFunctionSymbols.GetOrAdd(name);
900905
}
901906

902-
private NodeCache<string, ExternSymbolNode> _externIndirectSymbols;
907+
private NodeCache<string, ExternDataSymbolNode> _externDataSymbols;
903908

904-
public ISortableSymbolNode ExternIndirectSymbol(string name)
909+
public ISortableSymbolNode ExternDataSymbol(string name)
910+
{
911+
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
912+
return _externDataSymbols.GetOrAdd(mangledName);
913+
}
914+
915+
public ISortableSymbolNode ExternVariable(string name)
905916
{
906-
return _externIndirectSymbols.GetOrAdd(name);
917+
return _externDataSymbols.GetOrAdd(name);
907918
}
908919

909920
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
@@ -147,7 +147,7 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder,
147147
encoder.EmitINT3();
148148

149149
encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod));
150-
encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod"));
150+
encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod"));
151151
}
152152
else
153153
{

0 commit comments

Comments
 (0)