Skip to content

Commit ce33e12

Browse files
[NativeAOT-LLVM] Port the ExternSymbolNode change (#3131)
* [NativeAOT] Split `ExternSymbolNode` into two types for data and functions (#117346) This allows to distinguish the symbol type for a node with a simple type check. * NAOT-LLVM fixes
1 parent bfe5ebb commit ce33e12

23 files changed

+91
-68
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
@@ -329,7 +329,7 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t
329329
case ReadyToRunHelperId.ObjectAllocator:
330330
{
331331
var type = (TypeDesc)targetOfLookup;
332-
return NodeFactory.ExternSymbol(JitHelper.GetNewObjectHelperForType(type));
332+
return NodeFactory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(type));
333333
}
334334

335335
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 derive 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;
@@ -31,6 +33,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
3133
{
3234
sb.Append(_name);
3335
}
36+
3437
public int Offset => 0;
3538
public virtual bool RepresentsIndirectionCell => _isIndirection;
3639

@@ -44,8 +47,6 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
4447
public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory factory) => null;
4548

4649
#if !SUPPORT_JIT
47-
public override int ClassCode => 1092559304;
48-
4950
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
5051
{
5152
return _name.CompareTo(((ExternSymbolNode)other)._name);
@@ -58,11 +59,26 @@ public override string ToString()
5859
}
5960
}
6061

61-
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)
6266
{
63-
public AddressTakenExternSymbolNode(Utf8String name)
64-
: base(name) { }
67+
public override int ClassCode => 1452455506;
68+
}
6569

70+
public class AddressTakenExternFunctionSymbolNode(Utf8String name) : ExternFunctionSymbolNode(name)
71+
{
6672
public override int ClassCode => -45645737;
6773
}
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+
}
6884
}

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
@@ -735,7 +735,7 @@ public ObjectAllocatorGenericLookupResult(TypeDesc type)
735735
public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultContext dictionary)
736736
{
737737
TypeDesc instantiatedType = _type.GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(dictionary.TypeInstantiation, dictionary.MethodInstantiation);
738-
return factory.ExternSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType));
738+
return factory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType));
739739
}
740740

741741
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) =>
@@ -762,7 +766,7 @@ public ISortableSymbolNode TypeThreadStaticIndex(MetadataType type)
762766
}
763767
else
764768
{
765-
return ExternSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
769+
return ExternDataSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type));
766770
}
767771
}
768772

@@ -872,24 +876,31 @@ internal ISymbolNode GenericVariance(GenericVarianceDetails details)
872876
return _genericVariances.GetOrAdd(details);
873877
}
874878

875-
private NodeCache<string, ExternSymbolNode> _externSymbols;
879+
private NodeCache<string, ExternFunctionSymbolNode> _externFunctionSymbols;
876880

877-
public ISortableSymbolNode ExternSymbol(string name)
881+
public ISortableSymbolNode ExternFunctionSymbol(string name)
878882
{
879-
return _externSymbols.GetOrAdd(name);
883+
return _externFunctionSymbols.GetOrAdd(name);
880884
}
881885

882-
public ISortableSymbolNode ExternVariable(string name)
886+
private NodeCache<string, ExternFunctionSymbolNode> _externIndirectFunctionSymbols;
887+
888+
public ISortableSymbolNode ExternIndirectFunctionSymbol(string name)
883889
{
884-
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
885-
return _externSymbols.GetOrAdd(mangledName);
890+
return _externIndirectFunctionSymbols.GetOrAdd(name);
886891
}
887892

888-
private NodeCache<string, ExternSymbolNode> _externIndirectSymbols;
893+
private NodeCache<string, ExternDataSymbolNode> _externDataSymbols;
889894

890-
public ISortableSymbolNode ExternIndirectSymbol(string name)
895+
public ISortableSymbolNode ExternDataSymbol(string name)
891896
{
892-
return _externIndirectSymbols.GetOrAdd(name);
897+
return _externDataSymbols.GetOrAdd(name);
898+
}
899+
900+
public ISortableSymbolNode ExternVariable(string name)
901+
{
902+
string mangledName = NameMangler.NodeMangler.ExternVariable(name);
903+
return _externDataSymbols.GetOrAdd(mangledName);
893904
}
894905

895906
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)