Skip to content

Commit 8875a47

Browse files
Last ILCompiler.TypeSystem <-> ILCompiler.TypeSystem.ReadyToRun diff
After this and dotnet#63280 there will be no differences between ILCompiler.TypeSystem and ILCompiler.TypeSystem.ReadyToRun and we can unify them.
1 parent 699b0ae commit 8875a47

File tree

7 files changed

+221
-266
lines changed

7 files changed

+221
-266
lines changed

src/coreclr/tools/Common/TypeSystem/Aot/TargetDetails.Aot.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/coreclr/tools/Common/TypeSystem/Common/Utilities/GCPointerMap.Algorithm.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,73 @@ private static void FromInstanceLayoutHelper(ref GCPointerMapBuilder builder, De
5151
}
5252
}
5353
}
54+
55+
/// <summary>
56+
/// Computes the GC pointer map of the GC static region of the type.
57+
/// </summary>
58+
public static GCPointerMap FromStaticLayout(DefType type)
59+
{
60+
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.GCStaticFieldSize.AsInt, type.Context.Target.PointerSize);
61+
62+
foreach (FieldDesc field in type.GetFields())
63+
{
64+
if (!field.IsStatic || field.HasRva || field.IsLiteral
65+
|| field.IsThreadStatic || !field.HasGCStaticBase)
66+
continue;
67+
68+
TypeDesc fieldType = field.FieldType;
69+
if (fieldType.IsGCPointer)
70+
{
71+
builder.MarkGCPointer(field.Offset.AsInt);
72+
}
73+
else
74+
{
75+
Debug.Assert(fieldType.IsValueType);
76+
var fieldDefType = (DefType)fieldType;
77+
if (fieldDefType.ContainsGCPointers)
78+
{
79+
GCPointerMapBuilder innerBuilder =
80+
builder.GetInnerBuilder(field.Offset.AsInt, fieldDefType.InstanceByteCount.AsInt);
81+
FromInstanceLayoutHelper(ref innerBuilder, fieldDefType);
82+
}
83+
}
84+
}
85+
86+
Debug.Assert(builder.ToGCMap().Size * type.Context.Target.PointerSize >= type.GCStaticFieldSize.AsInt);
87+
return builder.ToGCMap();
88+
}
89+
90+
/// <summary>
91+
/// Computes the GC pointer map of the thread static region of the type.
92+
/// </summary>
93+
public static GCPointerMap FromThreadStaticLayout(DefType type)
94+
{
95+
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.ThreadGcStaticFieldSize.AsInt, type.Context.Target.PointerSize);
96+
97+
foreach (FieldDesc field in type.GetFields())
98+
{
99+
if (!field.IsStatic || field.HasRva || field.IsLiteral || !field.IsThreadStatic || !field.HasGCStaticBase)
100+
continue;
101+
102+
TypeDesc fieldType = field.FieldType;
103+
if (fieldType.IsGCPointer)
104+
{
105+
builder.MarkGCPointer(field.Offset.AsInt);
106+
}
107+
else if (fieldType.IsValueType)
108+
{
109+
var fieldDefType = (DefType)fieldType;
110+
if (fieldDefType.ContainsGCPointers)
111+
{
112+
GCPointerMapBuilder innerBuilder =
113+
builder.GetInnerBuilder(field.Offset.AsInt, fieldDefType.InstanceByteCount.AsInt);
114+
FromInstanceLayoutHelper(ref innerBuilder, fieldDefType);
115+
}
116+
}
117+
}
118+
119+
Debug.Assert(builder.ToGCMap().Size * type.Context.Target.PointerSize >= type.ThreadGcStaticFieldSize.AsInt);
120+
return builder.ToGCMap();
121+
}
54122
}
55123
}

src/coreclr/tools/Common/TypeSystem/Common/Utilities/GCPointerMap.Aot.cs

Lines changed: 0 additions & 78 deletions
This file was deleted.

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

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,156 @@ public static string GetName(this MethodSignature signature)
7878
return nameBuilder.ToString();
7979
}
8080
}
81+
82+
public class UniqueTypeNameFormatter : TypeNameFormatter
83+
{
84+
public static UniqueTypeNameFormatter Instance { get; } = new UniqueTypeNameFormatter();
85+
86+
public override void AppendName(StringBuilder sb, PointerType type)
87+
{
88+
AppendName(sb, type.ParameterType);
89+
sb.Append('*');
90+
}
91+
92+
public override void AppendName(StringBuilder sb, GenericParameterDesc type)
93+
{
94+
string prefix = type.Kind == GenericParameterKind.Type ? "!" : "!!";
95+
sb.Append(prefix);
96+
sb.Append(type.Name);
97+
}
98+
99+
public override void AppendName(StringBuilder sb, SignatureTypeVariable type)
100+
{
101+
sb.Append("!");
102+
sb.Append(type.Index.ToStringInvariant());
103+
}
104+
105+
public override void AppendName(StringBuilder sb, SignatureMethodVariable type)
106+
{
107+
sb.Append("!!");
108+
sb.Append(type.Index.ToStringInvariant());
109+
}
110+
111+
public override void AppendName(StringBuilder sb, FunctionPointerType type)
112+
{
113+
MethodSignature signature = type.Signature;
114+
115+
AppendName(sb, signature.ReturnType);
116+
117+
sb.Append(" (");
118+
for (int i = 0; i < signature.Length; i++)
119+
{
120+
if (i > 0)
121+
sb.Append(", ");
122+
AppendName(sb, signature[i]);
123+
}
124+
125+
// TODO: Append '...' for vararg methods
126+
127+
sb.Append(')');
128+
}
129+
130+
public override void AppendName(StringBuilder sb, ByRefType type)
131+
{
132+
AppendName(sb, type.ParameterType);
133+
sb.Append(" ByRef");
134+
}
135+
136+
public override void AppendName(StringBuilder sb, ArrayType type)
137+
{
138+
AppendName(sb, type.ElementType);
139+
sb.Append('[');
140+
141+
if (type.Rank == 1 && type.IsMdArray)
142+
sb.Append('*');
143+
sb.Append(',', type.Rank - 1);
144+
145+
sb.Append(']');
146+
}
147+
148+
protected override void AppendNameForInstantiatedType(StringBuilder sb, DefType type)
149+
{
150+
AppendName(sb, type.GetTypeDefinition());
151+
sb.Append('<');
152+
153+
for (int i = 0; i < type.Instantiation.Length; i++)
154+
{
155+
if (i > 0)
156+
sb.Append(", ");
157+
AppendName(sb, type.Instantiation[i]);
158+
}
159+
160+
sb.Append('>');
161+
}
162+
163+
protected override void AppendNameForNamespaceType(StringBuilder sb, DefType type)
164+
{
165+
string ns = GetTypeNamespace(type);
166+
if (ns.Length > 0)
167+
{
168+
AppendEscapedIdentifier(sb, ns);
169+
sb.Append('.');
170+
}
171+
AppendEscapedIdentifier(sb, GetTypeName(type));
172+
173+
if (type is MetadataType)
174+
{
175+
IAssemblyDesc homeAssembly = ((MetadataType)type).Module as IAssemblyDesc;
176+
AppendAssemblyName(sb, homeAssembly);
177+
}
178+
}
179+
180+
private void AppendAssemblyName(StringBuilder sb, IAssemblyDesc assembly)
181+
{
182+
if (assembly == null)
183+
return;
184+
185+
sb.Append(',');
186+
AppendEscapedIdentifier(sb, assembly.GetName().Name);
187+
}
188+
189+
protected override void AppendNameForNestedType(StringBuilder sb, DefType nestedType, DefType containingType)
190+
{
191+
AppendName(sb, containingType);
192+
193+
sb.Append('+');
194+
195+
string ns = GetTypeNamespace(nestedType);
196+
if (ns.Length > 0)
197+
{
198+
AppendEscapedIdentifier(sb, ns);
199+
sb.Append('.');
200+
}
201+
AppendEscapedIdentifier(sb, GetTypeName(nestedType));
202+
}
203+
204+
private string GetTypeName(DefType type)
205+
{
206+
return type.Name;
207+
}
208+
209+
private string GetTypeNamespace(DefType type)
210+
{
211+
return type.Namespace;
212+
}
213+
214+
private static char[] s_escapedChars = new char[] { ',', '=', '"', ']', '[', '*', '&', '+', '\\' };
215+
private void AppendEscapedIdentifier(StringBuilder sb, string identifier)
216+
{
217+
if (identifier.IndexOfAny(s_escapedChars) < 0)
218+
{
219+
string escapedIdentifier = identifier;
220+
foreach (char escapedChar in s_escapedChars)
221+
{
222+
string escapedCharString = new string(escapedChar, 1);
223+
escapedIdentifier = escapedIdentifier.Replace(escapedCharString, "\\" + escapedCharString);
224+
}
225+
sb.Append(escapedIdentifier);
226+
}
227+
else
228+
{
229+
sb.Append(identifier);
230+
}
231+
}
232+
}
81233
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
3535
}
3636

3737
int ISymbolDefinitionNode.Offset => 0;
38-
int ISymbolNode.Offset => Method.Context.Target.FatFunctionPointerOffset;
38+
int ISymbolNode.Offset => Method.Context.Target.Architecture == TargetArchitecture.Wasm32 ? 1 << 31 : 2;
3939

4040
public override bool IsShareable => true;
4141

src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@
100100
<Compile Include="..\..\Common\TypeSystem\Canon\TypeSystemContext.Canon.cs">
101101
<Link>TypeSystem\Canon\TypeSystemContext.Canon.cs</Link>
102102
</Compile>
103-
<Compile Include="..\..\Common\TypeSystem\Aot\TargetDetails.Aot.cs">
104-
<Link>TypeSystem\Aot\TargetDetails.Aot.cs</Link>
105-
</Compile>
106103
<Compile Include="..\..\Common\TypeSystem\CodeGen\FieldDesc.CodeGen.cs">
107104
<Link>TypeSystem\CodeGen\FieldDesc.CodeGen.cs</Link>
108105
</Compile>
@@ -181,9 +178,6 @@
181178
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.Algorithm.cs">
182179
<Link>Utilities\GCPointerMap.Algorithm.cs</Link>
183180
</Compile>
184-
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.Aot.cs">
185-
<Link>Utilities\GCPointerMap.Aot.cs</Link>
186-
</Compile>
187181
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.cs">
188182
<Link>Utilities\GCPointerMap.cs</Link>
189183
</Compile>
@@ -808,6 +802,5 @@
808802
<Compile Include="..\..\Common\TypeSystem\Sorting\TypeSystemComparer.cs">
809803
<Link>TypeSystem\Sorting\TypeSystemComparer.cs</Link>
810804
</Compile>
811-
<Compile Include="Utilities\UniqueTypeNameFormatter.cs" />
812805
</ItemGroup>
813806
</Project>

0 commit comments

Comments
 (0)