Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Oct 27, 2022
1 parent 33e6066 commit c045cf9
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 195 deletions.
27 changes: 16 additions & 11 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,17 +1711,22 @@ void CodeGen::genGenerateMachineCode()

printf("; Emitting ");

if (compiler->compCodeOpt() == Compiler::SMALL_CODE)
switch (compiler->opts.OptLevel())
{
printf("SMALL_CODE");
}
else if (compiler->compCodeOpt() == Compiler::FAST_CODE)
{
printf("FAST_CODE");
}
else
{
printf("BLENDED_CODE");
case Compiler::OPT_MinOpts:
printf("MinOpts code");
break;
case Compiler::OPT_SizeAndThroughput:
printf("size/throughput-aware code");
break;
case Compiler::OPT_Blended:
printf("blended code");
break;
case Compiler::OPT_Speed:
printf("fast code");
break;
default:
unreached();
}

printf(" for ");
Expand Down Expand Up @@ -1883,7 +1888,7 @@ void CodeGen::genGenerateMachineCode()
GetEmitter()->emitBegFN(isFramePointerUsed()
#if defined(DEBUG)
,
(compiler->compCodeOpt() != Compiler::SMALL_CODE) &&
(compiler->opts.OptLevel() >= Compiler::OPT_Blended) &&
!compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT)
#endif
,
Expand Down
82 changes: 45 additions & 37 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,10 +1914,8 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
compRationalIRForm = false;

#ifdef DEBUG
compCodeGenDone = false;
opts.compMinOptsIsUsed = false;
compCodeGenDone = false;
#endif
opts.compMinOptsIsSet = false;

// Used by fgFindJumpTargets for inlining heuristics.
opts.instrCount = 0;
Expand Down Expand Up @@ -2402,33 +2400,39 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.compFlags = CLFLG_MINOPT;
}

// Default value is to generate a blend of size and speed optimizations
//
opts.compCodeOpt = BLENDED_CODE;

// If the EE sets SIZE_OPT or if we are compiling a Class constructor
// we will optimize for code size at the expense of speed
//
if (jitFlags->IsSet(JitFlags::JIT_FLAG_SIZE_OPT) || ((info.compFlags & FLG_CCTOR) == FLG_CCTOR))
{
opts.compCodeOpt = SMALL_CODE;
}
//
// If the EE sets SPEED_OPT we will optimize for speed at the expense of code size
//
else if (jitFlags->IsSet(JitFlags::JIT_FLAG_SPEED_OPT) ||
(jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1) && !jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT)))
{
opts.compCodeOpt = FAST_CODE;
assert(!jitFlags->IsSet(JitFlags::JIT_FLAG_SIZE_OPT));
}

//-------------------------------------------------------------------------

opts.compDbgCode = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_CODE);
opts.compDbgInfo = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_INFO);
opts.compDbgEnC = jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_EnC);

if (opts.compDbgCode || jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT) || jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0))
{
// MinOpts level in case of explicit miopts mode or debug-friendly codegen request
opts.compOptLevel = OPT_MinOpts;
}
else if (!jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT) && ((info.compFlags & FLG_CCTOR) == FLG_CCTOR) &&
!compIsForInlining())
{
// Don't waste time on static cctors (unless prejitted)
opts.compOptLevel = OPT_MinOpts;
}
else
{
if (jitFlags->IsSet(JitFlags::JIT_FLAG_SIZE_OPT))
{
opts.compOptLevel = OPT_SizeAndThroughput;
}
else if (jitFlags->IsSet(JitFlags::JIT_FLAG_SPEED_OPT))
{
opts.compOptLevel = OPT_Speed;
}
else
{
opts.compOptLevel = OPT_Blended;
}
}

#ifdef DEBUG
opts.compJitAlignLoopAdaptive = JitConfig.JitAlignLoopAdaptive() == 1;
opts.compJitAlignLoopBoundary = (unsigned short)JitConfig.JitAlignLoopBoundary();
Expand Down Expand Up @@ -3266,11 +3270,23 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
printf("OPTIONS: OSR variant with entry point 0x%x\n", info.compILEntry);
}

printf("OPTIONS: compCodeOpt = %s\n",
(opts.compCodeOpt == BLENDED_CODE)
? "BLENDED_CODE"
: (opts.compCodeOpt == SMALL_CODE) ? "SMALL_CODE"
: (opts.compCodeOpt == FAST_CODE) ? "FAST_CODE" : "UNKNOWN_CODE");
switch (opts.OptLevel())
{
case OPT_MinOpts:
printf("OPTIONS: OptLevel() = MinOpts\n");
break;
case OPT_SizeAndThroughput:
printf("OPTIONS: OptLevel() = SizeAndThroughput\n");
break;
case OPT_Blended:
printf("OPTIONS: OptLevel() = Blended\n");
break;
case OPT_Speed:
printf("OPTIONS: OptLevel() = Speed\n");
break;
default:
unreached();
}

printf("OPTIONS: compDbgCode = %s\n", dspBool(opts.compDbgCode));
printf("OPTIONS: compDbgInfo = %s\n", dspBool(opts.compDbgInfo));
Expand Down Expand Up @@ -4093,14 +4109,6 @@ const char* Compiler::compGetTieringName(bool wantShortName) const
const bool tier1 = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1);
const bool instrumenting = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR);

if (!opts.compMinOptsIsSet)
{
// If 'compMinOptsIsSet' is not set, just return here. Otherwise, if this method is called
// by the assertAbort(), we would recursively call assert while trying to get MinOpts()
// and eventually stackoverflow.
return "Optimization-Level-Not-Yet-Set";
}

assert(!tier0 || !tier1); // We don't expect multiple TIER flags to be set at one time.

if (tier0)
Expand Down
66 changes: 14 additions & 52 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9050,13 +9050,13 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//---------------------------- JITing options -----------------------------

enum codeOptimize
enum OptLevel
{
BLENDED_CODE,
SMALL_CODE,
FAST_CODE,

COUNT_OPT_CODE
// Order is important
OPT_MinOpts,
OPT_SizeAndThroughput,
OPT_Blended,
OPT_Speed
};

struct Options
Expand All @@ -9083,7 +9083,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
unsigned instrCount;
unsigned lvRefCount;

codeOptimize compCodeOpt; // what type of code optimizations
OptLevel compOptLevel;

bool compUseCMOV;

Expand All @@ -9098,47 +9098,25 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Maximum number of locals before turning off the inlining
#define MAX_LV_NUM_COUNT_FOR_INLINING 512

bool compMinOpts;
bool compMinOptsIsSet;
#ifdef DEBUG
mutable bool compMinOptsIsUsed;

bool MinOpts() const
{
assert(compMinOptsIsSet);
compMinOptsIsUsed = true;
return compMinOpts;
}
bool IsMinOptsSet() const
{
return compMinOptsIsSet;
}
#else // !DEBUG
bool MinOpts() const
{
return compMinOpts;
}
bool IsMinOptsSet() const
{
return compMinOptsIsSet;
return compOptLevel == OPT_MinOpts;
}
#endif // !DEBUG

bool OptimizationDisabled() const
{
return MinOpts() || compDbgCode;
return compOptLevel < OPT_Blended;
}
bool OptimizationEnabled() const
{
return !OptimizationDisabled();
}

OptLevel OptLevel() const
{
return compOptLevel;
}
void SetMinOpts(bool val)
{
assert(!compMinOptsIsUsed);
assert(!compMinOptsIsSet || (compMinOpts == val));
compMinOpts = val;
compMinOptsIsSet = true;
compOptLevel = OPT_MinOpts;
}

// true if the CLFLG_* for an optimization is set.
Expand Down Expand Up @@ -9589,22 +9567,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
const char* compGetPgoSourceName() const;
const char* compGetStressMessage() const;

codeOptimize compCodeOpt() const
{
#if 0
// Switching between size & speed has measurable throughput impact
// (3.5% on NGen CoreLib when measured). It used to be enabled for
// DEBUG, but should generate identical code between CHK & RET builds,
// so that's not acceptable.
// TODO-Throughput: Figure out what to do about size vs. speed & throughput.
// Investigate the cause of the throughput regression.

return opts.compCodeOpt;
#else
return BLENDED_CODE;
#endif
}

//--------------------- Info about the procedure --------------------------

struct Info
Expand Down
31 changes: 0 additions & 31 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7594,16 +7594,6 @@ CORINFO_FIELD_HANDLE emitter::emitFltOrDblConst(double constValue, emitAttr attr
unsigned cnsSize = (attr == EA_4BYTE) ? sizeof(float) : sizeof(double);
unsigned cnsAlign = cnsSize;

#ifdef TARGET_XARCH
if (emitComp->compCodeOpt() == Compiler::SMALL_CODE)
{
// Some platforms don't require doubles to be aligned and so
// we can use a smaller alignment to help with smaller code

cnsAlign = dataSection::MIN_DATA_ALIGN;
}
#endif // TARGET_XARCH

UNATIVE_OFFSET cnum = emitDataConst(cnsAddr, cnsSize, cnsAlign, dataType);
return emitComp->eeFindJitDataOffs(cnum);
}
Expand All @@ -7628,13 +7618,6 @@ CORINFO_FIELD_HANDLE emitter::emitSimd8Const(simd8_t constValue)
unsigned cnsSize = 8;
unsigned cnsAlign = cnsSize;

#ifdef TARGET_XARCH
if (emitComp->compCodeOpt() == Compiler::SMALL_CODE)
{
cnsAlign = dataSection::MIN_DATA_ALIGN;
}
#endif // TARGET_XARCH

UNATIVE_OFFSET cnum = emitDataConst(&constValue, cnsSize, cnsAlign, TYP_SIMD8);
return emitComp->eeFindJitDataOffs(cnum);
#else
Expand All @@ -7653,13 +7636,6 @@ CORINFO_FIELD_HANDLE emitter::emitSimd16Const(simd16_t constValue)
unsigned cnsSize = 16;
unsigned cnsAlign = cnsSize;

#ifdef TARGET_XARCH
if (emitComp->compCodeOpt() == Compiler::SMALL_CODE)
{
cnsAlign = dataSection::MIN_DATA_ALIGN;
}
#endif // TARGET_XARCH

UNATIVE_OFFSET cnum = emitDataConst(&constValue, cnsSize, cnsAlign, TYP_SIMD16);
return emitComp->eeFindJitDataOffs(cnum);
#else
Expand All @@ -7678,13 +7654,6 @@ CORINFO_FIELD_HANDLE emitter::emitSimd32Const(simd32_t constValue)
unsigned cnsSize = 32;
unsigned cnsAlign = cnsSize;

#ifdef TARGET_XARCH
if (emitComp->compCodeOpt() == Compiler::SMALL_CODE)
{
cnsAlign = dataSection::MIN_DATA_ALIGN;
}
#endif // TARGET_XARCH

UNATIVE_OFFSET cnum = emitDataConst(&constValue, cnsSize, cnsAlign, TYP_SIMD32);
return emitComp->eeFindJitDataOffs(cnum);
#else
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12815,7 +12815,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
// we expect the same alignment as the size of the constant.

assert((emitChkAlign == false) || (ins == INS_lea) ||
((emitComp->compCodeOpt() == Compiler::SMALL_CODE) && (((size_t)addr & 3) == 0)) ||
((emitComp->opts.OptLevel() < Compiler::OPT_Blended) && (((size_t)addr & 3) == 0)) ||
(((size_t)addr & (byteSize - 1)) == 0));
#endif // DEBUG
}
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ bool Compiler::fgCanSwitchToOptimized()
{
// Ensure that it would be safe to change the opt level
assert(opts.compFlags == CLFLG_MINOPT);
assert(!opts.IsMinOptsSet());
}

return result;
Expand Down Expand Up @@ -2718,7 +2717,7 @@ PhaseStatus Compiler::fgAddInternal()
// We are allowed to have multiple individual exits
// However we can still decide to have a single return
//
if ((compCodeOpt() == SMALL_CODE) || stressMerging)
if ((opts.OptLevel() == OPT_SizeAndThroughput) || stressMerging)
{
// Under stress or for Small_Code case we always
// generate a single return block when we have multiple
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4303,7 +4303,7 @@ GenTree* Compiler::impTransformThis(GenTree* thisPtr,

bool Compiler::impCanPInvokeInline()
{
return getInlinePInvokeEnabled() && (!opts.compDbgCode) && (compCodeOpt() != SMALL_CODE) &&
return getInlinePInvokeEnabled() && (!opts.compDbgCode) && (opts.OptLevel() >= OPT_Blended) &&
(!opts.compNoPInvokeInlineCB) // profiler is preventing inline pinvoke
;
}
Expand Down Expand Up @@ -7629,7 +7629,7 @@ GenTree* Compiler::impArrayAccessIntrinsic(
assert((intrinsicName == NI_Array_Address) || (intrinsicName == NI_Array_Get) || (intrinsicName == NI_Array_Set));

// If we are generating SMALL_CODE, we don't want to use intrinsics, as it generates fatter code.
if (compCodeOpt() == SMALL_CODE)
if (opts.OptLevel() < OPT_Blended)
{
JITDUMP("impArrayAccessIntrinsic: rejecting array intrinsic due to SMALL_CODE\n");
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inlinepolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ InlinePolicy* InlinePolicy::GetPolicy(Compiler* compiler, bool isPrejitRoot)
}

const bool isPrejit = compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_PREJIT);
const bool isSpeedOpt = compiler->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_SPEED_OPT);
const bool isSpeedOpt = compiler->opts.OptLevel() == Compiler::OPT_Speed;

if ((JitConfig.JitExtDefaultPolicy() != 0))
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ void Compiler::lvaSortByRefCount()
}

// Now sort the tracked variable table by ref-count
if (compCodeOpt() == SMALL_CODE)
if (opts.OptLevel() == OPT_SizeAndThroughput)
{
jitstd::sort(tracked, tracked + trackedCount, LclVarDsc_SmallCode_Less(lvaTable DEBUGARG(lvaCount)));
}
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7517,11 +7517,8 @@ void Lowering::LowerSIMD(GenTreeSIMD* simdNode)
const unsigned cnsSize = genTypeSize(simdNode);
assert(cnsSize <= sizeof(constArgValues));

const unsigned cnsAlign =
(comp->compCodeOpt() != Compiler::SMALL_CODE) ? cnsSize : emitter::dataSection::MIN_DATA_ALIGN;

CORINFO_FIELD_HANDLE hnd =
comp->GetEmitter()->emitBlkConst(constArgValues, cnsSize, cnsAlign, simdNode->GetSimdBaseType());
comp->GetEmitter()->emitBlkConst(constArgValues, cnsSize, cnsSize, simdNode->GetSimdBaseType());
GenTree* clsVarAddr = new (comp, GT_CLS_VAR_ADDR) GenTreeClsVar(TYP_I_IMPL, hnd);
BlockRange().InsertBefore(simdNode, clsVarAddr);
simdNode->ChangeOper(GT_IND);
Expand Down
Loading

0 comments on commit c045cf9

Please sign in to comment.