Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 68 additions & 41 deletions src/coreclr/src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,23 +1719,62 @@ void Compiler::compDisplayStaticSizes(FILE* fout)
*
* Constructor
*/

void Compiler::compInit(ArenaAllocator* pAlloc, InlineInfo* inlineInfo)
void Compiler::compInit(ArenaAllocator* pAlloc,
CORINFO_METHOD_HANDLE methodHnd,
COMP_HANDLE compHnd,
CORINFO_METHOD_INFO* methodInfo,
InlineInfo* inlineInfo)
{
assert(pAlloc);
compArenaAllocator = pAlloc;

// Inlinee Compile object will only be allocated when needed for the 1st time.
InlineeCompiler = nullptr;

// Set the inline info.
impInlineInfo = inlineInfo;
info.compCompHnd = compHnd;
info.compMethodHnd = methodHnd;
info.compMethodInfo = methodInfo;

#ifdef DEBUG
bRangeAllowStress = false;
#endif

#if defined(DEBUG) || defined(LATE_DISASM)
// Initialize the method name and related info, as it is used early in determining whether to
// apply stress modes, and which ones to apply.
// Note that even allocating memory can invoke the stress mechanism, so ensure that both
// 'compMethodName' and 'compFullName' are either null or valid before we allocate.
// (The stress mode checks references these prior to checking bRangeAllowStress.)
//
info.compMethodName = nullptr;
info.compClassName = nullptr;
info.compFullName = nullptr;
#endif // defined(DEBUG) || defined(LATE_DISASM)

// Inlinee Compile object will only be allocated when needed for the 1st time.
InlineeCompiler = nullptr;
const char* classNamePtr;
const char* methodName;

// Set the inline info.
impInlineInfo = inlineInfo;
methodName = eeGetMethodName(methodHnd, &classNamePtr);
unsigned len = (unsigned)roundUp(strlen(classNamePtr) + 1);
info.compClassName = getAllocator(CMK_DebugOnly).allocate<char>(len);
info.compMethodName = methodName;
strcpy_s((char*)info.compClassName, len, classNamePtr);

info.compFullName = eeGetMethodFullName(methodHnd);
info.compPerfScore = 0.0;
#endif // defined(DEBUG) || defined(LATE_DISASM)

#ifdef DEBUG
// Opt-in to jit stress based on method hash ranges.
//
// Note the default (with JitStressRange not set) is that all
// methods will be subject to stress.
static ConfigMethodRange fJitStressRange;
fJitStressRange.EnsureInit(JitConfig.JitStressRange());
assert(!fJitStressRange.Error());
bRangeAllowStress = fJitStressRange.Contains(info.compMethodHash());
#endif // DEBUG

eeInfoInitialized = false;

Expand Down Expand Up @@ -1771,10 +1810,6 @@ void Compiler::compInit(ArenaAllocator* pAlloc, InlineInfo* inlineInfo)
compJitTelemetry.Initialize(this);
#endif

#ifdef DEBUG
bRangeAllowStress = false;
#endif

fgInit();
lvaInit();

Expand Down Expand Up @@ -2682,6 +2717,9 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
setUsesSIMDTypes(false);
#endif // FEATURE_SIMD

lvaEnregEHVars = (((opts.compFlags & CLFLG_REGVAR) != 0) && JitConfig.EnableEHWriteThru());
lvaEnregMultiRegVars = (((opts.compFlags & CLFLG_REGVAR) != 0) && JitConfig.EnableMultiRegLocals());

if (compIsForImportOnly())
{
return;
Expand Down Expand Up @@ -5209,14 +5247,16 @@ bool Compiler::skipMethod()

/*****************************************************************************/

int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
CORINFO_MODULE_HANDLE classPtr,
COMP_HANDLE compHnd,
CORINFO_METHOD_INFO* methodInfo,
int Compiler::compCompile(CORINFO_MODULE_HANDLE classPtr,
void** methodCodePtr,
ULONG* methodCodeSize,
JitFlags* compileFlags)
{
// compInit should have set these already.
noway_assert(info.compMethodInfo != nullptr);
noway_assert(info.compCompHnd != nullptr);
noway_assert(info.compMethodHnd != nullptr);

#ifdef FEATURE_JIT_METHOD_PERF
static bool checkedForJitTimeLog = false;

Expand All @@ -5227,7 +5267,7 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
// Call into VM to get the config strings. FEATURE_JIT_METHOD_PERF is enabled for
// retail builds. Do not call the regular Config helper here as it would pull
// in a copy of the config parser into the clrjit.dll.
InterlockedCompareExchangeT(&Compiler::compJitTimeLogFilename, compHnd->getJitTimeLogFilename(), NULL);
InterlockedCompareExchangeT(&Compiler::compJitTimeLogFilename, info.compCompHnd->getJitTimeLogFilename(), NULL);

// At a process or module boundary clear the file and start afresh.
JitTimer::PrintCsvHeader();
Expand All @@ -5236,7 +5276,7 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
}
if ((Compiler::compJitTimeLogFilename != nullptr) || (JitTimeLogCsv() != nullptr))
{
pCompJitTimer = JitTimer::Create(this, methodInfo->ILCodeSize);
pCompJitTimer = JitTimer::Create(this, info.compMethodInfo->ILCodeSize);
}
#endif // FEATURE_JIT_METHOD_PERF

Expand Down Expand Up @@ -5274,10 +5314,6 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,

// if (s_compMethodsCount==0) setvbuf(jitstdout, NULL, _IONBF, 0);

info.compCompHnd = compHnd;
info.compMethodHnd = methodHnd;
info.compMethodInfo = methodInfo;

if (compIsForInlining())
{
compileFlags->Clear(JitFlags::JIT_FLAG_OSR);
Expand Down Expand Up @@ -5346,7 +5382,7 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
{
impTokenLookupContextHandle = impInlineInfo->tokenLookupContextHandle;

assert(impInlineInfo->inlineCandidateInfo->clsHandle == compHnd->getMethodClass(methodHnd));
assert(impInlineInfo->inlineCandidateInfo->clsHandle == info.compCompHnd->getMethodClass(info.compMethodHnd));
info.compClassHnd = impInlineInfo->inlineCandidateInfo->clsHandle;

assert(impInlineInfo->inlineCandidateInfo->clsAttr == info.compCompHnd->getClassAttribs(info.compClassHnd));
Expand All @@ -5358,7 +5394,7 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
{
impTokenLookupContextHandle = MAKE_METHODCONTEXT(info.compMethodHnd);

info.compClassHnd = compHnd->getMethodClass(methodHnd);
info.compClassHnd = info.compCompHnd->getMethodClass(info.compMethodHnd);
info.compClassAttr = info.compCompHnd->getClassAttribs(info.compClassHnd);
}

Expand All @@ -5367,12 +5403,12 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
#if defined(DEBUG) || defined(LATE_DISASM)
const char* classNamePtr;

info.compMethodName = eeGetMethodName(methodHnd, &classNamePtr);
info.compMethodName = eeGetMethodName(info.compMethodHnd, &classNamePtr);
unsigned len = (unsigned)roundUp(strlen(classNamePtr) + 1);
info.compClassName = getAllocator(CMK_DebugOnly).allocate<char>(len);
strcpy_s((char*)info.compClassName, len, classNamePtr);

info.compFullName = eeGetMethodFullName(methodHnd);
info.compFullName = eeGetMethodFullName(info.compMethodHnd);
info.compPerfScore = 0.0;
#endif // defined(DEBUG) || defined(LATE_DISASM)

Expand All @@ -5392,15 +5428,6 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
return CORJIT_SKIPPED;
}

// Opt-in to jit stress based on method hash ranges.
//
// Note the default (with JitStressRange not set) is that all
// methods will be subject to stress.
static ConfigMethodRange fJitStressRange;
fJitStressRange.EnsureInit(JitConfig.JitStressRange());
assert(!fJitStressRange.Error());
bRangeAllowStress = fJitStressRange.Contains(info.compMethodHash());

#endif // DEBUG

// Set this before the first 'BADCODE'
Expand All @@ -5427,14 +5454,14 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
} param;
param.pThis = this;
param.classPtr = classPtr;
param.compHnd = compHnd;
param.methodInfo = methodInfo;
param.compHnd = info.compCompHnd;
param.methodInfo = info.compMethodInfo;
param.methodCodePtr = methodCodePtr;
param.methodCodeSize = methodCodeSize;
param.compileFlags = compileFlags;
param.result = CORJIT_INTERNALERROR;

setErrorTrap(compHnd, Param*, pParam, &param) // ERROR TRAP: Start normal block
setErrorTrap(info.compCompHnd, Param*, pParam, &param) // ERROR TRAP: Start normal block
{
pParam->result =
pParam->pThis->compCompileHelper(pParam->classPtr, pParam->compHnd, pParam->methodInfo,
Expand Down Expand Up @@ -6732,16 +6759,16 @@ int jitNativeCode(CORINFO_METHOD_HANDLE methodHnd,
assert(pParam->pComp != nullptr);
#endif

pParam->pComp->compInit(pParam->pAlloc, pParam->inlineInfo);
pParam->pComp->compInit(pParam->pAlloc, pParam->methodHnd, pParam->compHnd, pParam->methodInfo,
pParam->inlineInfo);

#ifdef DEBUG
pParam->pComp->jitFallbackCompile = pParam->jitFallbackCompile;
#endif

// Now generate the code
pParam->result =
pParam->pComp->compCompile(pParam->methodHnd, pParam->classPtr, pParam->compHnd, pParam->methodInfo,
pParam->methodCodePtr, pParam->methodCodeSize, pParam->compileFlags);
pParam->result = pParam->pComp->compCompile(pParam->classPtr, pParam->methodCodePtr, pParam->methodCodeSize,
pParam->compileFlags);
}
finallyErrorTrap()
{
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9321,7 +9321,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
static void compStartup(); // One-time initialization
static void compShutdown(); // One-time finalization

void compInit(ArenaAllocator* pAlloc, InlineInfo* inlineInfo);
void compInit(ArenaAllocator* pAlloc,
CORINFO_METHOD_HANDLE methodHnd,
COMP_HANDLE compHnd,
CORINFO_METHOD_INFO* methodInfo,
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
Expand All @@ -9344,10 +9348,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void compDoComponentUnitTestsOnce();
#endif // DEBUG

int compCompile(CORINFO_METHOD_HANDLE methodHnd,
CORINFO_MODULE_HANDLE classPtr,
COMP_HANDLE compHnd,
CORINFO_METHOD_INFO* methodInfo,
int compCompile(CORINFO_MODULE_HANDLE classPtr,
void** methodCodePtr,
ULONG* methodCodeSize,
JitFlags* compileFlags);
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/src/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ void Compiler::lvaInit()
lvaCurEpoch = 0;

structPromotionHelper = new (this, CMK_Generic) StructPromotionHelper(this);

lvaEnregEHVars = (((opts.compFlags & CLFLG_REGVAR) != 0) && JitConfig.EnableEHWriteThru());
lvaEnregMultiRegVars = (((opts.compFlags & CLFLG_REGVAR) != 0) && JitConfig.EnableMultiRegLocals());
}

/*****************************************************************************/
Expand Down