Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Guarded devirtualization foundations #21270

Merged
merged 8 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
533 changes: 533 additions & 0 deletions Documentation/design-docs/GuardedDevirtualization.md

Large diffs are not rendered by default.

Binary file added Documentation/design-docs/ThreeClassesDevirt.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/design-docs/TwoClassesBaseline.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/design-docs/TwoClassesDevirt.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4543,10 +4543,8 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
fgRemovePreds();
}

if (IsTargetAbi(CORINFO_CORERT_ABI) && doesMethodHaveFatPointer())
{
fgTransformFatCalli();
}
// Transform indirect calls that require control flow expansion.
fgTransformIndirectCalls();

EndPhase(PHASE_IMPORTATION);

Expand Down
48 changes: 38 additions & 10 deletions src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,13 @@ class Compiler
return IsTargetAbi(CORINFO_CORERT_ABI) ? TYP_I_IMPL : TYP_REF;
}

void impDevirtualizeCall(GenTreeCall* call,
CORINFO_METHOD_HANDLE* method,
unsigned* methodFlags,
CORINFO_CONTEXT_HANDLE* contextHandle,
CORINFO_CONTEXT_HANDLE* exactContextHandle,
bool isLateDevirtualization);

//=========================================================================
// PROTECTED
//=========================================================================
Expand Down Expand Up @@ -3355,12 +3362,6 @@ class Compiler
CORINFO_CALL_INFO* callInfo,
IL_OFFSET rawILOffset);

void impDevirtualizeCall(GenTreeCall* call,
CORINFO_METHOD_HANDLE* method,
unsigned* methodFlags,
CORINFO_CONTEXT_HANDLE* contextHandle,
CORINFO_CONTEXT_HANDLE* exactContextHandle);

CORINFO_CLASS_HANDLE impGetSpecialIntrinsicExactReturnType(CORINFO_METHOD_HANDLE specialIntrinsicHandle);

bool impMethodInfo_hasRetBuffArg(CORINFO_METHOD_INFO* methInfo);
Expand Down Expand Up @@ -3866,7 +3867,7 @@ class Compiler
bool forceInline,
InlineResult* inlineResult);

void impCheckCanInline(GenTree* call,
void impCheckCanInline(GenTreeCall* call,
CORINFO_METHOD_HANDLE fncHandle,
unsigned methAttr,
CORINFO_CONTEXT_HANDLE exactContextHnd,
Expand Down Expand Up @@ -3895,6 +3896,11 @@ class Compiler
bool exactContextNeedsRuntimeLookup,
CORINFO_CALL_INFO* callInfo);

void impMarkInlineCandidateHelper(GenTreeCall* call,
CORINFO_CONTEXT_HANDLE exactContextHnd,
bool exactContextNeedsRuntimeLookup,
CORINFO_CALL_INFO* callInfo);

bool impTailCallRetTypeCompatible(var_types callerRetType,
CORINFO_CLASS_HANDLE callerRetTypeClass,
var_types calleeRetType,
Expand Down Expand Up @@ -4134,7 +4140,7 @@ class Compiler

void fgImport();

void fgTransformFatCalli();
void fgTransformIndirectCalls();

void fgInline();

Expand Down Expand Up @@ -5355,8 +5361,8 @@ class Compiler
#ifdef DEBUG
static fgWalkPreFn fgDebugCheckInlineCandidates;

void CheckNoFatPointerCandidatesLeft();
static fgWalkPreFn fgDebugCheckFatPointerCandidates;
void CheckNoTransformableIndirectCallsRemain();
static fgWalkPreFn fgDebugCheckForTransformableIndirectCalls;
#endif

void fgPromoteStructs();
Expand Down Expand Up @@ -6139,6 +6145,7 @@ class Compiler
#define OMF_HAS_NULLCHECK 0x00000010 // Method contains null check.
#define OMF_HAS_FATPOINTER 0x00000020 // Method contains call, that needs fat pointer transformation.
#define OMF_HAS_OBJSTACKALLOC 0x00000040 // Method contains an object allocated on the stack.
#define OMF_HAS_GUARDEDDEVIRT 0x00000080 // Method contains guarded devirtualization candidate

bool doesMethodHaveFatPointer()
{
Expand All @@ -6157,6 +6164,27 @@ class Compiler

void addFatPointerCandidate(GenTreeCall* call);

bool doesMethodHaveGuardedDevirtualization()
{
return (optMethodFlags & OMF_HAS_GUARDEDDEVIRT) != 0;
}

void setMethodHasGuardedDevirtualization()
{
optMethodFlags |= OMF_HAS_GUARDEDDEVIRT;
}

void clearMethodHasGuardedDevirtualization()
{
optMethodFlags &= ~OMF_HAS_GUARDEDDEVIRT;
}

void addGuardedDevirtualizationCandidate(GenTreeCall* call,
CORINFO_METHOD_HANDLE methodHandle,
CORINFO_CLASS_HANDLE classHandle,
unsigned methodAttr,
unsigned classAttr);

unsigned optMethodFlags;

// Recursion bound controls how far we can go backwards tracking for a SSA value.
Expand Down
Loading