Skip to content

Commit

Permalink
JIT: Use metadata names for SIMD intrinsic method recognition (#76786)
Browse files Browse the repository at this point in the history
* JIT: Use metadata names for SIMD intrinsic method recognition

eeGetMethodName is only expected to be used for diagnostics.

* Reorder checks in impSIMDIntrinsic

* Suggested refactoring

* Avoid unnecessary metadata lookups in getMethodNameFromMetadata

* Fix nested lookup

* Fix repGetMethodNameFromMetadata
  • Loading branch information
jakobbotsch authored Oct 22, 2022
1 parent 2f9418d commit 3f40c3d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 62 deletions.
11 changes: 7 additions & 4 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,14 @@ var_types Compiler::impImportCall(OPCODE opcode,
}

#ifdef FEATURE_SIMD
call = impSIMDIntrinsic(opcode, newobjThis, clsHnd, methHnd, sig, mflags, pResolvedToken->token);
if (call != nullptr)
if (isIntrinsic)
{
bIntrinsicImported = true;
goto DONE_CALL;
call = impSIMDIntrinsic(opcode, newobjThis, clsHnd, methHnd, sig, mflags, pResolvedToken->token);
if (call != nullptr)
{
bIntrinsicImported = true;
goto DONE_CALL;
}
}
#endif // FEATURE_SIMD

Expand Down
13 changes: 5 additions & 8 deletions src/coreclr/jit/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ const SIMDIntrinsicInfo* Compiler::getSIMDIntrinsicInfo(CORINFO_CLASS_HANDLE* in
if (sig->numArgs == 0)
{
const SIMDIntrinsicInfo* hwAccelIntrinsicInfo = &(simdIntrinsicInfoArray[SIMDIntrinsicHWAccel]);
if ((strcmp(eeGetMethodName(methodHnd, nullptr), hwAccelIntrinsicInfo->methodName) == 0) &&
const char* methodName = info.compCompHnd->getMethodNameFromMetadata(methodHnd, nullptr, nullptr, nullptr);
if ((strcmp(methodName, hwAccelIntrinsicInfo->methodName) == 0) &&
JITtype2varType(sig->retType) == hwAccelIntrinsicInfo->retType)
{
// Sanity check
Expand Down Expand Up @@ -993,7 +994,7 @@ const SIMDIntrinsicInfo* Compiler::getSIMDIntrinsicInfo(CORINFO_CLASS_HANDLE* in
// TODO-Throughput: replace sequential search by binary search by arranging entries
// sorted by method name.
SIMDIntrinsicID intrinsicId = SIMDIntrinsicInvalid;
const char* methodName = eeGetMethodName(methodHnd, nullptr);
const char* methodName = info.compCompHnd->getMethodNameFromMetadata(methodHnd, nullptr, nullptr, nullptr);
for (int i = SIMDIntrinsicNone + 1; i < SIMDIntrinsicInvalid; ++i)
{
if (strcmp(methodName, simdIntrinsicInfoArray[i].methodName) == 0)
Expand Down Expand Up @@ -1855,18 +1856,14 @@ GenTree* Compiler::impSIMDIntrinsic(OPCODE opcode,
unsigned methodFlags,
int memberRef)
{
assert((methodFlags & CORINFO_FLG_INTRINSIC) != 0);

// Exit early if we are not in one of the SIMD types.
if (!isSIMDClass(clsHnd))
{
return nullptr;
}

// Exit early if the method is not a JIT Intrinsic (which requires the [Intrinsic] attribute).
if ((methodFlags & CORINFO_FLG_INTRINSIC) == 0)
{
return nullptr;
}

// Get base type and intrinsic Id
CorInfoType simdBaseJitType = CORINFO_TYPE_UNDEF;
unsigned size = 0;
Expand Down
55 changes: 26 additions & 29 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,46 +1180,43 @@ const char* MethodContext::repGetMethodNameFromMetadata(CORINFO_METHOD_HANDLE ft
const char** namespaceName,
const char** enclosingClassName)
{
const char* result = nullptr;
Agnostic_CORINFO_METHODNAME_TOKENout value;
Agnostic_CORINFO_METHODNAME_TOKENin key;

key.ftn = CastHandle(ftn);
key.className = (moduleName != nullptr);
key.namespaceName = (namespaceName != nullptr);
key.enclosingClassName = (enclosingClassName != nullptr);

int itemIndex = -1;
if (GetMethodNameFromMetadata != nullptr)
itemIndex = GetMethodNameFromMetadata->GetIndex(key);
if (itemIndex < 0)
{
if (moduleName != nullptr)
{
*moduleName = nullptr;
}
}
else
{
value = GetMethodNameFromMetadata->Get(key);
DEBUG_REP(dmpGetMethodNameFromMetadata(key, value));
AssertMapAndKeyExist(
GetMethodNameFromMetadata,
key,
": ftn-%016llX className-%u namespaceName-%u enclosingClassName-%u",
key.ftn,
key.className,
key.namespaceName,
key.enclosingClassName);

result = (const char*)GetMethodNameFromMetadata->GetBuffer(value.methodName);
Agnostic_CORINFO_METHODNAME_TOKENout value = GetMethodNameFromMetadata->Get(key);

if (moduleName != nullptr)
{
*moduleName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.className);
}
DEBUG_REP(dmpGetMethodNameFromMetadata(key, value));

if (namespaceName != nullptr)
{
*namespaceName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.namespaceName);
}
const char* result = (const char*)GetMethodNameFromMetadata->GetBuffer(value.methodName);

if (enclosingClassName != nullptr)
{
*enclosingClassName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.enclosingClassName);
}
if (moduleName != nullptr)
{
*moduleName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.className);
}

if (namespaceName != nullptr)
{
*namespaceName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.namespaceName);
}

if (enclosingClassName != nullptr)
{
*enclosingClassName = (const char*)GetMethodNameFromMetadata->GetBuffer(value.enclosingClassName);
}

return result;
}

Expand Down
42 changes: 21 additions & 21 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6299,12 +6299,24 @@ const char* CEEInfo::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftnHnd, con
} CONTRACTL_END;

const char* result = NULL;
const char* classResult = NULL;
const char* namespaceResult = NULL;
const char* enclosingResult = NULL;

JIT_TO_EE_TRANSITION();

if (className != NULL)
{
*className = NULL;
}

if (namespaceName != NULL)
{
*namespaceName = NULL;
}

if (enclosingClassName != NULL)
{
*enclosingClassName = NULL;
}

MethodDesc *ftn = GetMethod(ftnHnd);
mdMethodDef token = ftn->GetMemberDef();

Expand All @@ -6314,30 +6326,18 @@ const char* CEEInfo::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftnHnd, con
IMDInternalImport* pMDImport = pMT->GetMDImport();

IfFailThrow(pMDImport->GetNameOfMethodDef(token, &result));
IfFailThrow(pMDImport->GetNameOfTypeDef(pMT->GetCl(), &classResult, &namespaceResult));
if (className != NULL || namespaceName != NULL)
{
IfFailThrow(pMDImport->GetNameOfTypeDef(pMT->GetCl(), className, namespaceName));
}
// Query enclosingClassName when the method is in a nested class
// and get the namespace of enclosing classes (nested class's namespace is empty)
if (pMT->GetClass()->IsNested())
if ((enclosingClassName != NULL || namespaceName != NULL) && pMT->GetClass()->IsNested())
{
IfFailThrow(pMDImport->GetNameOfTypeDef(pMT->GetEnclosingCl(), &enclosingResult, &namespaceResult));
IfFailThrow(pMDImport->GetNameOfTypeDef(pMT->GetEnclosingCl(), enclosingClassName, namespaceName));
}
}

if (className != NULL)
{
*className = classResult;
}

if (namespaceName != NULL)
{
*namespaceName = namespaceResult;
}

if (enclosingClassName != NULL)
{
*enclosingClassName = enclosingResult;
}

EE_TO_JIT_TRANSITION();

return result;
Expand Down

0 comments on commit 3f40c3d

Please sign in to comment.