Skip to content

Commit

Permalink
PGO: Profile Buffer.Memmove's length (#96311)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
Co-authored-by: Andy Ayers <andya@microsoft.com>
  • Loading branch information
3 people authored Jan 5, 2024
1 parent a5ff7e6 commit adb4c18
Show file tree
Hide file tree
Showing 19 changed files with 637 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ enum CorInfoHelpFunc
CORINFO_HELP_VTABLEPROFILE64, // Update 64-bit method profile for a vtable call site
CORINFO_HELP_COUNTPROFILE32, // Update 32-bit block or edge count profile
CORINFO_HELP_COUNTPROFILE64, // Update 64-bit block or edge count profile
CORINFO_HELP_VALUEPROFILE32, // Update 32-bit value profile
CORINFO_HELP_VALUEPROFILE64, // Update 64-bit value profile

CORINFO_HELP_VALIDATE_INDIRECT_CALL, // CFG: Validate function pointer
CORINFO_HELP_DISPATCH_INDIRECT_CALL, // CFG: Validate and dispatch to pointer
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/inc/corjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ class ICorJitInfo : public ICorDynamicInfo
void* HandleTable[HandleHistogram32::SIZE];
};

struct ValueHistogram32
{
uint32_t Count;
intptr_t ValueTable[HandleHistogram32::SIZE];
};

struct ValueHistogram64
{
uint64_t Count;
intptr_t ValueTable[HandleHistogram32::SIZE];
};

enum class PgoInstrumentationKind
{
// This must be kept in sync with PgoInstrumentationKind in PgoFormat.cs
Expand Down Expand Up @@ -394,6 +406,11 @@ class ICorJitInfo : public ICorDynamicInfo
EdgeLongCount = (DescriptorMin * 6) | EightByte, // edge counter using unsigned 8 byte int
GetLikelyClass = (DescriptorMin * 7) | TypeHandle, // Compressed get likely class data
GetLikelyMethod = (DescriptorMin * 7) | MethodHandle, // Compressed get likely method data

// Same as type/method histograms, but for generic integer values
ValueHistogramIntCount = (DescriptorMin * 8) | FourByte | AlignPointer,
ValueHistogramLongCount = (DescriptorMin * 8) | EightByte,
ValueHistogram = (DescriptorMin * 9) | EightByte,
};

struct PgoInstrumentationSchema
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* a19264d9-82b9-4aa4-833f-ee4b52352d7e */
0xa19264d9,
0x82b9,
0x4aa4,
{0x83, 0x3f, 0xee, 0x4b, 0x52, 0x35, 0x2d, 0x7e}
constexpr GUID JITEEVersionIdentifier = { /* 0cb8113f-52e5-444f-b713-dcb749b5d211 */
0x0cb8113f,
0x52e5,
0x444f,
{0xb7, 0x13, 0xdc, 0xb7, 0x49, 0xb5, 0xd2, 0x11}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@
JITHELPER(CORINFO_HELP_VTABLEPROFILE64, JIT_VTableProfile64, CORINFO_HELP_SIG_4_STACK)
JITHELPER(CORINFO_HELP_COUNTPROFILE32, JIT_CountProfile32, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_COUNTPROFILE64, JIT_CountProfile64, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_VALUEPROFILE32, JIT_ValueProfile32, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_VALUEPROFILE64, JIT_ValueProfile64, CORINFO_HELP_SIG_REG_ONLY)

#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
JITHELPER(CORINFO_HELP_VALIDATE_INDIRECT_CALL, JIT_ValidateIndirectCall, CORINFO_HELP_SIG_REG_ONLY)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ enum BasicBlockFlags : unsigned __int64
// This is just to reduce diffs from removing BBJ_NONE.
// (TODO: Remove this quirk after refactoring Compiler::fgFindInsertPoint)
BBF_OLD_LOOP_HEADER_QUIRK = MAKE_BBFLAG(42), // Block was the header ('entry') of a loop recognized by old loop finding
BBF_HAS_VALUE_PROFILE = MAKE_BBFLAG(43), // Block has a node that needs a value probing

// The following are sets of flags.

Expand Down Expand Up @@ -460,7 +461,7 @@ enum BasicBlockFlags : unsigned __int64
// TODO: Should BBF_RUN_RARELY be added to BBF_SPLIT_GAINED ?

BBF_SPLIT_GAINED = BBF_DONT_REMOVE | BBF_HAS_JMP | BBF_BACKWARD_JUMP | BBF_HAS_IDX_LEN | BBF_HAS_MD_IDX_LEN | BBF_PROF_WEIGHT | \
BBF_HAS_NEWOBJ | BBF_KEEP_BBJ_ALWAYS | BBF_CLONED_FINALLY_END | BBF_HAS_NULLCHECK | BBF_HAS_HISTOGRAM_PROFILE | BBF_HAS_MDARRAYREF | BBF_NEEDS_GCPOLL | BBF_NONE_QUIRK,
BBF_HAS_NEWOBJ | BBF_KEEP_BBJ_ALWAYS | BBF_CLONED_FINALLY_END | BBF_HAS_NULLCHECK | BBF_HAS_HISTOGRAM_PROFILE | BBF_HAS_VALUE_PROFILE | BBF_HAS_MDARRAYREF | BBF_NEEDS_GCPOLL | BBF_NONE_QUIRK,

// Flags that must be propagated to a new block if code is copied from a block to a new block. These are flags that
// limit processing of a block if the code in question doesn't exist. This is conservative; we might not
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4388,6 +4388,8 @@ class Compiler

GenTree* impFixupStructReturnType(GenTree* op);

GenTree* impDuplicateWithProfiledArg(GenTreeCall* call, IL_OFFSET ilOffset);

#ifdef DEBUG
var_types impImportJitTestLabelMark(int numArgs);
#endif // DEBUG
Expand Down Expand Up @@ -4473,7 +4475,7 @@ class Compiler
bool isMax,
bool isMagnitude,
bool isNumber);
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);

NamedIntrinsic lookupPrimitiveFloatNamedIntrinsic(CORINFO_METHOD_HANDLE method, const char* methodName);
NamedIntrinsic lookupPrimitiveIntNamedIntrinsic(CORINFO_METHOD_HANDLE method, const char* methodName);
GenTree* impUnsupportedNamedIntrinsic(unsigned helper,
Expand Down Expand Up @@ -4558,6 +4560,7 @@ class Compiler
static const unsigned CHECK_SPILL_ALL = static_cast<unsigned>(-1);
static const unsigned CHECK_SPILL_NONE = static_cast<unsigned>(-2);

NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);
void impBeginTreeList();
void impEndTreeList(BasicBlock* block, Statement* firstStmt, Statement* lastStmt);
void impEndTreeList(BasicBlock* block);
Expand Down Expand Up @@ -6270,6 +6273,7 @@ class Compiler

Instrumentor* fgCountInstrumentor;
Instrumentor* fgHistogramInstrumentor;
Instrumentor* fgValueInstrumentor;

PhaseStatus fgPrepareToInstrumentMethod();
PhaseStatus fgInstrumentMethod();
Expand Down Expand Up @@ -10047,6 +10051,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR);
}

bool IsOptimizedWithProfile() const
{
return OptimizationEnabled() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
}

bool IsInstrumentedAndOptimized() const
{
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void Compiler::fgInit()
fgPgoInlineeNoPgoSingleBlock = 0;
fgCountInstrumentor = nullptr;
fgHistogramInstrumentor = nullptr;
fgValueInstrumentor = nullptr;
fgPredListSortVector = nullptr;
fgCanonicalizedFirstBB = false;
}
Expand Down
Loading

0 comments on commit adb4c18

Please sign in to comment.