Skip to content

Commit

Permalink
Intrinsify Object.MemberwiseClone() (#46243)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Dec 27, 2020
1 parent 4f020cb commit 86047aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class Object
// object. This is always a shallow copy of the instance. The method is protected
// so that other object may only call this method on themselves. It is intended to
// support the ICloneable interface.
[Intrinsic]
protected unsafe object MemberwiseClone()
{
object clone = RuntimeHelpers.AllocateUninitializedClone(this);
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17759,7 +17759,8 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
GenTreeCall* call = tree->AsCall();
if (call->gtFlags & CORINFO_FLG_JIT_INTRINSIC)
{
if (lookupNamedIntrinsic(call->gtCallMethHnd) == NI_System_Array_Clone)
NamedIntrinsic ni = lookupNamedIntrinsic(call->gtCallMethHnd);
if ((ni == NI_System_Array_Clone) || (ni == NI_System_Object_MemberwiseClone))
{
objClass = gtGetClassHandle(call->gtCallThisArg->GetNode(), pIsExact, pIsNonNull);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4816,6 +4816,13 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
result = NI_System_Array_Clone;
}
}
else if (strcmp(className, "Object") == 0)
{
if (strcmp(methodName, "MemberwiseClone") == 0)
{
result = NI_System_Object_MemberwiseClone;
}
}
else if (strcmp(className, "Type") == 0)
{
if (strcmp(methodName, "get_IsValueType") == 0)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/namedintrinsiclist.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum NamedIntrinsic : unsigned short
NI_System_Type_IsAssignableFrom,
NI_System_Type_IsAssignableTo,
NI_System_Array_Clone,
NI_System_Object_MemberwiseClone,

// These are used by HWIntrinsics but are defined more generally
// to allow dead code optimization and handle the recursion case
Expand Down

0 comments on commit 86047aa

Please sign in to comment.