Skip to content

Commit

Permalink
Ignore method name when doing mcs -removeDup (dotnet#602)
Browse files Browse the repository at this point in the history
Thus, methods with different names but otherwise are identical will
match and only one will be retained.

This improves both Checked and Release, and fixes the Release
build removeDup regression introduced in dotnet#548.
  • Loading branch information
BruceForstall authored Dec 14, 2019
1 parent 496c2a6 commit 379b6ea
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/src/ToolBox/superpmi/mcs/verbremovedup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool unique(MethodContext* mc)
mc->repCompileMethod(&newInfo, &newFlags);

char* md5Buff = new char[MD5_HASH_BUFFER_SIZE];
mc->dumpMethodMD5HashToBuffer(md5Buff, MD5_HASH_BUFFER_SIZE);
mc->dumpMethodMD5HashToBuffer(md5Buff, MD5_HASH_BUFFER_SIZE, /* ignoreMethodName */ true);

if (inFile->GetIndex(newInfo.ILCodeSize) == -1)
inFile->Add(newInfo.ILCodeSize, new DenseLightWeightMap<char*>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,14 @@ const char* CallUtils::GetMethodName(MethodContext* mc, CORINFO_METHOD_HANDLE me
}

// Originally from src/jit/eeinterface.cpp
const char* CallUtils::GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig)
// If `ignoreMethodName` is `true`, we construct the function signature with a dummy method name that will be the
// same for all methods.
const char* CallUtils::GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig, bool ignoreMethodName /* = false */)
{
const char* returnType = NULL;

const char* className;
const char* methodName = GetMethodName(mc, hnd, &className);
const char* className = ignoreMethodName ? "CLASS" : nullptr;
const char* methodName = ignoreMethodName ? "METHOD" : GetMethodName(mc, hnd, &className);
if ((GetHelperNum(hnd) != CORINFO_HELP_UNDEF) || IsNativeMethod(hnd))
{
return methodName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CallUtils
static bool IsNativeMethod(CORINFO_METHOD_HANDLE method);
static CORINFO_METHOD_HANDLE GetMethodHandleForNative(CORINFO_METHOD_HANDLE method);
static const char* GetMethodName(MethodContext* mc, CORINFO_METHOD_HANDLE method, const char** classNamePtr);
static const char* GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig);
static const char* GetMethodFullName(MethodContext* mc, CORINFO_METHOD_HANDLE hnd, CORINFO_SIG_INFO sig, bool ignoreMethodName = false);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6346,7 +6346,7 @@ const WCHAR* MethodContext::repGetStringConfigValue(const WCHAR* name)
return value;
}

int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len)
int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len, bool ignoreMethodName /* = false */)
{
char* obuff = buff;

Expand All @@ -6360,7 +6360,7 @@ int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len)
repCompileMethod(&info, &flags);

// Add the Method Signature
int t = sprintf_s(buff, len, "%s -- ", CallUtils::GetMethodFullName(this, info.ftn, info.args));
int t = sprintf_s(buff, len, "%s -- ", CallUtils::GetMethodFullName(this, info.ftn, info.args, ignoreMethodName));
buff += t;
len -= t;

Expand All @@ -6379,11 +6379,11 @@ int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len)

return (int)(buff - obuff);
}
int MethodContext::dumpMethodMD5HashToBuffer(char* buff, int len)
int MethodContext::dumpMethodMD5HashToBuffer(char* buff, int len, bool ignoreMethodName /* = false */)
{
char bufferIdentityInfo[METHOD_IDENTITY_INFO_SIZE];

int cbLen = dumpMethodIdentityInfoToBuffer(bufferIdentityInfo, METHOD_IDENTITY_INFO_SIZE);
int cbLen = dumpMethodIdentityInfoToBuffer(bufferIdentityInfo, METHOD_IDENTITY_INFO_SIZE, ignoreMethodName);

if (cbLen < 0)
return cbLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ class MethodContext
static int dumpStatTitleToBuffer(char* buff, int len);
int methodSize;

int dumpMethodIdentityInfoToBuffer(char* buff, int len);
int dumpMethodMD5HashToBuffer(char* buff, int len);
int dumpMethodIdentityInfoToBuffer(char* buff, int len, bool ignoreMethodName = false);
int dumpMethodMD5HashToBuffer(char* buff, int len, bool ignoreMethodName = false);

void recGlobalContext(const MethodContext& other);

Expand Down

0 comments on commit 379b6ea

Please sign in to comment.