Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2015-12-29 00:05:54 +0300
committerJan Kotas <jkotas@microsoft.com>2015-12-30 16:54:24 +0300
commit1bc1dfa2a8470ec9508e04b11d7504e7df907206 (patch)
tree7d8de2269e8647662494a4162096f5ddd14c7ce7 /src/ILCompiler.Compiler
parent5a6227d2a5645cc429905654685f36b2c516e2ba (diff)
Implement most RyuJIT intrinsics
- Add lookup of all RyuJIT intrinsics - Update manage implementations of the intrinsics to fit with what RyuJIT is capable of - Make intrinsic expansions by the codegen to be optional by providing fallback paths - Fix USE_PORTABLE_HELPERS to be defined for portable runtime only These changes are under CORERT ifdefs as necessary to be reconciled with .NET Native for UWP later.
Diffstat (limited to 'src/ILCompiler.Compiler')
-rw-r--r--src/ILCompiler.Compiler/src/Compiler/IntrinsicMethods.cs60
-rw-r--r--src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs35
-rw-r--r--src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj13
3 files changed, 33 insertions, 75 deletions
diff --git a/src/ILCompiler.Compiler/src/Compiler/IntrinsicMethods.cs b/src/ILCompiler.Compiler/src/Compiler/IntrinsicMethods.cs
deleted file mode 100644
index a14d21fd3..000000000
--- a/src/ILCompiler.Compiler/src/Compiler/IntrinsicMethods.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using Internal.TypeSystem;
-
-using Debug = System.Diagnostics.Debug;
-
-namespace ILCompiler
-{
- internal enum IntrinsicMethodKind
- {
- None,
- RuntimeHelpersInitializeArray,
- }
-
- internal class IntrinsicMethods
- {
- public static IntrinsicMethodKind GetIntrinsicMethodClassification(MethodDesc method)
- {
- // TODO: make this reliable
- MetadataType owningMdType = method.OwningType as MetadataType;
-
- if (owningMdType != null && method.Name == "InitializeArray" && owningMdType.Name == "RuntimeHelpers" && owningMdType.Namespace == "System.Runtime.CompilerServices")
- {
- return IntrinsicMethodKind.RuntimeHelpersInitializeArray;
- }
-
- return IntrinsicMethodKind.None;
- }
-
- /// <summary>
- /// NEWOBJ operation on String type is actually a call to a static method that returs a String
- /// instance (i.e. there's an explict call to the runtime allocator from the static method body).
- /// This method returns the alloc+init helper corresponding to a given string constructor.
- /// </summary>
- public static MethodDesc GetStringInitializer(MethodDesc constructorMethod)
- {
- Debug.Assert(constructorMethod.IsConstructor);
- Debug.Assert(constructorMethod.OwningType.IsString);
-
- // There's an extra (useless) Object as the first arg to match RyuJIT expectations.
- var parameters = new TypeDesc[constructorMethod.Signature.Length + 1];
- parameters[0] = constructorMethod.Context.GetWellKnownType(WellKnownType.Object);
- for (int i = 0; i < constructorMethod.Signature.Length; i++)
- parameters[i + 1] = constructorMethod.Signature[i];
-
- MethodSignature sig = new MethodSignature(
- MethodSignatureFlags.Static, 0, constructorMethod.OwningType, parameters);
-
- MethodDesc result = constructorMethod.OwningType.GetMethod("Ctor", sig);
-
- // TODO: Better exception type. Should be: "CoreLib doesn't have a required thing in it".
- if (result == null)
- throw new NotImplementedException();
-
- return result;
- }
- }
-}
diff --git a/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs b/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
index 4a864fe6b..4969a25c0 100644
--- a/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
+++ b/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
@@ -635,18 +635,29 @@ namespace Internal.IL
Finish();
}
- private void ImportIntrinsicCall(IntrinsicMethodKind intrinsicClassification)
+ private static bool IsTypeName(MethodDesc method, string typeNamespace, string typeName)
{
- switch (intrinsicClassification)
+ var metadataType = method.OwningType as MetadataType;
+ if (metadataType == null)
+ return false;
+ return metadataType.Namespace == typeNamespace && metadataType.Name == typeName;
+ }
+
+ private bool ImportIntrinsicCall(MethodDesc method)
+ {
+ Debug.Assert(method.IsIntrinsic);
+
+ switch (method.Name)
{
- case IntrinsicMethodKind.RuntimeHelpersInitializeArray:
+ case "InitializeArray":
+ if (IsTypeName(method, "System.Runtime.CompilerServices", "RuntimeHelpers"))
{
var fieldSlot = Pop();
var arraySlot = Pop();
var fieldDesc = (TypeSystem.Ecma.EcmaField)fieldSlot.Value.Aux;
var memBlock = TypeSystem.Ecma.EcmaFieldExtensions.GetFieldRvaData(fieldDesc);
-
+
// TODO: Need to do more for arches with different endianness?
var preinitDataHolder = NewTempName();
Append("static const char ");
@@ -671,10 +682,13 @@ namespace Internal.IL
Append(")");
Finish();
- break;
+ return true;
}
- default: throw new NotImplementedException();
+ break;
+ default:
+ break;
}
+ return false;
}
private void ImportCall(ILOpcode opcode, int token)
@@ -686,11 +700,10 @@ namespace Internal.IL
MethodDesc method = (MethodDesc)_methodIL.GetObject(token);
- var intrinsicClassification = IntrinsicMethods.GetIntrinsicMethodClassification(method);
- if (intrinsicClassification != IntrinsicMethodKind.None)
+ if (method.IsIntrinsic)
{
- ImportIntrinsicCall(intrinsicClassification);
- return;
+ if (ImportIntrinsicCall(method))
+ return;
}
TypeDesc constrained = null;
@@ -719,7 +732,7 @@ namespace Internal.IL
if (owningType.IsString)
{
// String constructors actually look like regular method calls
- method = IntrinsicMethods.GetStringInitializer(method);
+ method = method.GetStringInitializer();
opcode = ILOpcode.call;
// WORKAROUND: the static method expects an extra arg
diff --git a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj
index 43af2acab..9e5916457 100644
--- a/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj
+++ b/src/ILCompiler.Compiler/src/ILCompiler.Compiler.csproj
@@ -29,9 +29,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\PInvokeMarshallingILEmitter.cs">
- <Link>IL\Stubs\PInvokeMarshallingThunk.cs</Link>
- </Compile>
<Compile Include="Compiler\AsmStringWriter.cs" />
<Compile Include="Compiler\Compilation.cs" />
<Compile Include="Compiler\CompilerMetadataFieldLayoutAlgorithm.cs" />
@@ -75,7 +72,6 @@
<Compile Include="Compiler\MethodExtensions.cs" />
<Compile Include="Compiler\NameMangler.cs" />
<Compile Include="Compiler\PdbSymbolProvider.cs" />
- <Compile Include="Compiler\IntrinsicMethods.cs" />
<Compile Include="Compiler\VirtualMethodCallHelper.cs" />
<Compile Include="CppCodeGen\CppWriter.cs" />
</ItemGroup>
@@ -130,12 +126,18 @@
<Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\CalliIntrinsic.cs">
<Link>IL\Stubs\CalliIntrinsic.cs</Link>
</Compile>
+ <Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\InterlockedIntrinsic.cs">
+ <Link>IL\Stubs\InterlockedIntrinsic.cs</Link>
+ </Compile>
<Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\DelegateThunks.cs">
<Link>IL\Stubs\DelegateThunks.cs</Link>
</Compile>
<Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\ILEmitter.cs">
<Link>IL\Stubs\ILEmitter.cs</Link>
</Compile>
+ <Compile Include="..\..\Common\src\TypeSystem\IL\Stubs\PInvokeMarshallingILEmitter.cs">
+ <Link>IL\Stubs\PInvokeMarshallingThunk.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\JitInterface\src\CorInfoBase.cs">
@@ -147,6 +149,9 @@
<Compile Include="..\..\JitInterface\src\CorInfoImpl.cs">
<Link>JitInterface\CorInfoImpl.cs</Link>
</Compile>
+ <Compile Include="..\..\JitInterface\src\CorInfoImpl.Intrinsics.cs">
+ <Link>JitInterface\CorInfoImpl.Intrinsics.cs</Link>
+ </Compile>
<Compile Include="..\..\JitInterface\src\CorInfoTypes.cs">
<Link>JitInterface\CorInfoTypes.cs</Link>
</Compile>