From 95e8cae134f6cb046e2967bdcb7d8a89ff79ddfe Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Fri, 10 Jun 2022 12:58:37 +0200 Subject: [PATCH] Add disasm comments for field data addresses and code addresses (#70437) * Fix impTokenToHandle when importing parent This was mistakenly creating a handle for the parent (always a class) but specifying the handle type of the child (e.g. constructor method handle). * Do not lie about critical sections being method handles --- src/coreclr/jit/codegenarm64.cpp | 13 +++++----- src/coreclr/jit/codegenxarch.cpp | 9 ++++--- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/compiler.hpp | 5 ++-- src/coreclr/jit/emit.cpp | 44 ++++++++++++++++++++++---------- src/coreclr/jit/emit.h | 4 +-- src/coreclr/jit/emitarm64.cpp | 29 +++++++++++++++++---- src/coreclr/jit/emitarm64.h | 12 ++++++--- src/coreclr/jit/emitxarch.cpp | 29 ++++++++++++++++++--- src/coreclr/jit/emitxarch.h | 5 +++- src/coreclr/jit/flowgraph.cpp | 2 +- src/coreclr/jit/gentree.cpp | 12 ++++++--- src/coreclr/jit/gentree.h | 3 +-- src/coreclr/jit/importer.cpp | 8 +++--- src/coreclr/jit/morph.cpp | 18 ++++++------- 15 files changed, 134 insertions(+), 61 deletions(-) diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index 2b9d4be0abc7d..b891e640cad59 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -2178,7 +2178,7 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, { if (emitter::emitIns_valid_imm_for_mov(imm, size)) { - GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm); + GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm, INS_OPTS_NONE DEBUGARG(targetHandle) DEBUGARG(gtFlags)); } else { @@ -2224,7 +2224,9 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, imm16 = ~imm16; } - GetEmitter()->emitIns_R_I_I(ins, size, reg, imm16, i, INS_OPTS_LSL); + GetEmitter()->emitIns_R_I_I(ins, size, reg, imm16, i, + INS_OPTS_LSL DEBUGARG(i == 0 ? targetHandle : 0) + DEBUGARG(i == 0 ? gtFlags : GTF_EMPTY)); // Once the initial movz/movn is emitted the remaining instructions will all use movk ins = INS_movk; @@ -2258,8 +2260,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre { case GT_CNS_INT: { - GenTreeIntConCommon* con = tree->AsIntConCommon(); - ssize_t cnsVal = con->IconValue(); + GenTreeIntCon* con = tree->AsIntCon(); + ssize_t cnsVal = con->IconValue(); emitAttr attr = emitActualTypeSize(targetType); // TODO-CQ: Currently we cannot do this for all handles because of @@ -2275,8 +2277,7 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre } instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, - INS_FLAGS_DONT_CARE DEBUGARG(tree->AsIntCon()->gtTargetHandle) - DEBUGARG(tree->AsIntCon()->gtFlags)); + INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); regSet.verifyRegUsed(targetReg); } break; diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 039d4c1118522..bb1206bfb5c5b 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -442,7 +442,7 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, } else { - GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm DEBUGARG(gtFlags)); + GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); } } regSet.verifyRegUsed(reg); @@ -462,8 +462,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre { // relocatable values tend to come down as a CNS_INT of native int type // so the line between these two opcodes is kind of blurry - GenTreeIntConCommon* con = tree->AsIntConCommon(); - ssize_t cnsVal = con->IconValue(); + GenTreeIntCon* con = tree->AsIntCon(); + ssize_t cnsVal = con->IconValue(); emitAttr attr = emitActualTypeSize(targetType); // Currently this cannot be done for all handles due to @@ -482,7 +482,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre attr = EA_SET_FLG(attr, EA_BYREF_FLG); } - instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, INS_FLAGS_DONT_CARE DEBUGARG(0) DEBUGARG(tree->gtFlags)); + instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, + INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); regSet.verifyRegUsed(targetReg); } break; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index b4c7eb375b4d2..363ec0b9a2f9a 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2269,7 +2269,7 @@ class Compiler GenTree* gtNewIndOfIconHandleNode(var_types indType, size_t value, GenTreeFlags iconFlags, bool isInvariant); - GenTree* gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields = nullptr); + GenTreeIntCon* gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields = nullptr); GenTreeFlags gtTokenToIconFlags(unsigned token); diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 2fe7c10574c6b..5499893630cbc 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -902,9 +902,8 @@ inline GenTree* Compiler::gtNewLargeOperNode(genTreeOps oper, var_types type, Ge * that may need to be fixed up). */ -inline GenTree* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields) +inline GenTreeIntCon* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields) { - GenTree* node; assert((flags & (GTF_ICON_HDL_MASK | GTF_ICON_FIELD_OFF)) != 0); // Interpret "fields == NULL" as "not a field." @@ -913,6 +912,7 @@ inline GenTree* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags, fields = FieldSeqStore::NotAField(); } + GenTreeIntCon* node; #if defined(LATE_DISASM) node = new (this, LargeOpOpcode()) GenTreeIntCon(TYP_I_IMPL, value, fields DEBUGARG(/*largeNode*/ true)); #else @@ -1370,6 +1370,7 @@ inline void GenTree::SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate) { case GT_CNS_INT: AsIntCon()->gtFieldSeq = FieldSeqStore::NotAField(); + INDEBUG(AsIntCon()->gtTargetHandle = 0); break; #if defined(TARGET_ARM) case GT_MUL_LONG: diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index ebd4f2120585a..a8777adc3ed9c 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -4045,16 +4045,12 @@ void emitter::emitRecomputeIGoffsets() // // Arguments: // handle - a constant value to display a comment for +// cookie - the cookie stored with the handle // flags - a flag that the describes the handle // -void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag) +void emitter::emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlags flag) { #ifdef DEBUG - if (handle == 0) - { - return; - } - #ifdef TARGET_XARCH const char* commentPrefix = " ;"; #else @@ -4062,8 +4058,35 @@ void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag) #endif flag &= GTF_ICON_HDL_MASK; - const char* str = nullptr; + if (cookie != 0) + { + if (flag == GTF_ICON_FTN_ADDR) + { + const char* className = nullptr; + const char* methName = + emitComp->eeGetMethodName(reinterpret_cast(cookie), &className); + printf("%s code for %s:%s", commentPrefix, className, methName); + return; + } + + if ((flag == GTF_ICON_STATIC_HDL) || (flag == GTF_ICON_STATIC_BOX_PTR)) + { + const char* className = nullptr; + const char* fieldName = + emitComp->eeGetFieldName(reinterpret_cast(cookie), &className); + printf("%s %s for %s%s%s", commentPrefix, flag == GTF_ICON_STATIC_HDL ? "data" : "box", className, + className != nullptr ? ":" : "", fieldName); + return; + } + } + + if (handle == 0) + { + return; + } + + const char* str = nullptr; if (flag == GTF_ICON_STR_HDL) { const WCHAR* wstr = emitComp->eeGetCPString(handle); @@ -4103,8 +4126,6 @@ void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag) { str = emitComp->eeGetClassName(reinterpret_cast(handle)); } -#ifndef TARGET_XARCH - // These are less useful for xarch: else if (flag == GTF_ICON_CONST_PTR) { str = "const ptr"; @@ -4133,11 +4154,6 @@ void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag) { str = "token handle"; } - else - { - str = "unknown"; - } -#endif // TARGET_XARCH if (str != nullptr) { diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index fc90bd96d6909..042b50e7e37c5 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -523,7 +523,7 @@ class emitter void emitRecomputeIGoffsets(); - void emitDispCommentForHandle(size_t handle, GenTreeFlags flags); + void emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlags flags); /************************************************************************/ /* The following describes a single instruction */ @@ -554,7 +554,7 @@ class emitter #endif // TARGET_XARCH -#ifdef DEBUG // This information is used in DEBUG builds to display the method name for call instructions +#ifdef DEBUG // This information is used in DEBUG builds for additional diagnostics struct instrDesc; diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index 864ba862edddd..3940f89302911 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -3740,7 +3740,8 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t imm, - insOpts opt /* = INS_OPTS_NONE */ DEBUGARG(GenTreeFlags gtFlags)) + insOpts opt /* = INS_OPTS_NONE */ + DEBUGARG(size_t targetHandle /* = 0 */) DEBUGARG(GenTreeFlags gtFlags /* = GTF_EMPTY */)) { emitAttr size = EA_SIZE(attr); emitAttr elemsize = EA_UNKNOWN; @@ -3990,7 +3991,11 @@ void emitter::emitIns_R_I(instruction ins, id->idInsOpt(opt); id->idReg1(reg); - INDEBUG(id->idDebugOnlyInfo()->idFlags = gtFlags); + +#ifdef DEBUG + id->idDebugOnlyInfo()->idMemCookie = targetHandle; + id->idDebugOnlyInfo()->idFlags = gtFlags; +#endif dispIns(id); appendToCurIG(id); @@ -4927,8 +4932,13 @@ void emitter::emitIns_R_R( * Add an instruction referencing a register and two constants. */ -void emitter::emitIns_R_I_I( - instruction ins, emitAttr attr, regNumber reg, ssize_t imm1, ssize_t imm2, insOpts opt /* = INS_OPTS_NONE */) +void emitter::emitIns_R_I_I(instruction ins, + emitAttr attr, + regNumber reg, + ssize_t imm1, + ssize_t imm2, + insOpts opt /* = INS_OPTS_NONE */ + DEBUGARG(size_t targetHandle /* = 0 */) DEBUGARG(GenTreeFlags gtFlags /* = 0 */)) { emitAttr size = EA_SIZE(attr); insFormat fmt = IF_NONE; @@ -5015,6 +5025,11 @@ void emitter::emitIns_R_I_I( id->idReg1(reg); +#ifdef DEBUG + id->idDebugOnlyInfo()->idFlags = gtFlags; + id->idDebugOnlyInfo()->idMemCookie = targetHandle; +#endif + dispIns(id); appendToCurIG(id); } @@ -12487,7 +12502,7 @@ void emitter::emitDispIns( } else { - emitDispCommentForHandle(id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); + emitDispCommentForHandle(id->idDebugOnlyInfo()->idMemCookie, 0, id->idDebugOnlyInfo()->idFlags); } break; @@ -12623,6 +12638,7 @@ void emitter::emitDispIns( case IF_DI_1A: // DI_1A X.......shiiiiii iiiiiinnnnn..... Rn imm(i12,sh) emitDispReg(id->idReg1(), size, true); emitDispImmOptsLSL12(emitGetInsSC(id), id->idInsOpt()); + emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); break; case IF_DI_1B: // DI_1B X........hwiiiii iiiiiiiiiiiddddd Rd imm(i16,hw) @@ -12641,18 +12657,21 @@ void emitter::emitDispIns( emitDispImm(hwi.immHW * 16, false); } } + emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); break; case IF_DI_1C: // DI_1C X........Nrrrrrr ssssssnnnnn..... Rn imm(N,r,s) emitDispReg(id->idReg1(), size, true); bmi.immNRS = (unsigned)emitGetInsSC(id); emitDispImm(emitDecodeBitMaskImm(bmi, size), false); + emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); break; case IF_DI_1D: // DI_1D X........Nrrrrrr ssssss.....ddddd Rd imm(N,r,s) emitDispReg(encodingZRtoSP(id->idReg1()), size, true); bmi.immNRS = (unsigned)emitGetInsSC(id); emitDispImm(emitDecodeBitMaskImm(bmi, size), false); + emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); break; case IF_DI_2A: // DI_2A X.......shiiiiii iiiiiinnnnnddddd Rd Rn imm(i12,sh) diff --git a/src/coreclr/jit/emitarm64.h b/src/coreclr/jit/emitarm64.h index 8970c15b3c090..c43f85292a4dc 100644 --- a/src/coreclr/jit/emitarm64.h +++ b/src/coreclr/jit/emitarm64.h @@ -726,7 +726,8 @@ void emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t imm, - insOpts opt = INS_OPTS_NONE DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); + insOpts opt = INS_OPTS_NONE DEBUGARG(size_t targetHandle = 0) + DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); void emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl, insOpts opt = INS_OPTS_NONE); @@ -740,8 +741,13 @@ void emitIns_R_R(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, emitIns_R_R(ins, attr, reg1, reg2); } -void emitIns_R_I_I( - instruction ins, emitAttr attr, regNumber reg1, ssize_t imm1, ssize_t imm2, insOpts opt = INS_OPTS_NONE); +void emitIns_R_I_I(instruction ins, + emitAttr attr, + regNumber reg1, + ssize_t imm1, + ssize_t imm2, + insOpts opt = INS_OPTS_NONE DEBUGARG(size_t targetHandle = 0) + DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); void emitIns_R_R_I( instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, ssize_t imm, insOpts opt = INS_OPTS_NONE); diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 707c8fc25f7c3..bd5b2d0defe6a 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -3219,6 +3219,11 @@ void emitter::emitHandleMemOp(GenTreeIndir* indir, instrDesc* id, insFormat fmt, id->idAddr()->iiaFieldHnd = fldHnd; id->idInsFmt(emitMapFmtForIns(emitMapFmtAtoM(fmt), ins)); + +#ifdef DEBUG + id->idDebugOnlyInfo()->idFlags = GTF_ICON_STATIC_HDL; + id->idDebugOnlyInfo()->idMemCookie = reinterpret_cast(fldHnd); +#endif } else if ((memBase != nullptr) && memBase->IsCnsIntOrI() && memBase->isContained()) { @@ -3279,6 +3284,14 @@ void emitter::emitHandleMemOp(GenTreeIndir* indir, instrDesc* id, insFormat fmt, // disp must have already been set in the instrDesc constructor. assert(emitGetInsAmdAny(id) == indir->Offset()); // make sure "disp" is stored properly } + +#ifdef DEBUG + if ((memBase != nullptr) && memBase->IsIconHandle() && memBase->isContained()) + { + id->idDebugOnlyInfo()->idFlags = memBase->gtFlags; + id->idDebugOnlyInfo()->idMemCookie = memBase->AsIntCon()->gtTargetHandle; + } +#endif } // Takes care of storing all incoming register parameters @@ -4126,7 +4139,10 @@ void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg) * Add an instruction referencing a register and a constant. */ -void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t val DEBUGARG(GenTreeFlags gtFlags)) +void emitter::emitIns_R_I(instruction ins, + emitAttr attr, + regNumber reg, + ssize_t val DEBUGARG(size_t targetHandle) DEBUGARG(GenTreeFlags gtFlags)) { emitAttr size = EA_SIZE(attr); @@ -4259,7 +4275,11 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t id->idInsFmt(fmt); id->idReg1(reg); id->idCodeSize(sz); - INDEBUG(id->idDebugOnlyInfo()->idFlags = gtFlags); + +#ifdef DEBUG + id->idDebugOnlyInfo()->idFlags = gtFlags; + id->idDebugOnlyInfo()->idMemCookie = targetHandle; +#endif dispIns(id); emitCurIGsize += sz; @@ -9118,7 +9138,7 @@ void emitter::emitDispIns( { // (val < 0) printf("-0x%IX", -val); } - emitDispCommentForHandle(srcVal, id->idDebugOnlyInfo()->idFlags); + emitDispCommentForHandle(srcVal, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags); } break; @@ -9189,6 +9209,9 @@ void emitter::emitDispIns( } printf("%s, %s", emitRegName(id->idReg1(), attr), sstr); emitDispAddrMode(id); + + emitDispCommentForHandle(emitGetInsAmdAny(id), id->idDebugOnlyInfo()->idMemCookie, + id->idDebugOnlyInfo()->idFlags); break; case IF_RRW_ARD_CNS: diff --git a/src/coreclr/jit/emitxarch.h b/src/coreclr/jit/emitxarch.h index 754632bb1c089..c744e40dbd41e 100644 --- a/src/coreclr/jit/emitxarch.h +++ b/src/coreclr/jit/emitxarch.h @@ -330,7 +330,10 @@ void emitIns_C(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE fdlHnd, int void emitIns_A(instruction ins, emitAttr attr, GenTreeIndir* indir); -void emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t val DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); +void emitIns_R_I(instruction ins, + emitAttr attr, + regNumber reg, + ssize_t val DEBUGARG(size_t targetHandle = 0) DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY)); void emitIns_Mov(instruction ins, emitAttr attr, regNumber dstReg, regNumber srgReg, bool canSkip); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index da1bcd79595aa..52399aa6c1692 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1528,7 +1528,7 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod() critSect = info.compCompHnd->getMethodSync(info.compMethodHnd, (void**)&pCrit); noway_assert((!critSect) != (!pCrit)); - tree = gtNewIconEmbHndNode(critSect, pCrit, GTF_ICON_METHOD_HDL, info.compMethodHnd); + tree = gtNewIconEmbHndNode(critSect, pCrit, GTF_ICON_GLOBAL_PTR, info.compMethodHnd); } else { diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index f6a167a50e139..70384056e0709 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -6745,8 +6745,8 @@ GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenT GenTree* Compiler::gtNewIconEmbHndNode(void* value, void* pValue, GenTreeFlags iconFlags, void* compileTimeHandle) { - GenTree* iconNode; - GenTree* handleNode; + GenTreeIntCon* iconNode; + GenTree* handleNode; if (value != nullptr) { @@ -6779,7 +6779,13 @@ GenTree* Compiler::gtNewIconEmbHndNode(void* value, void* pValue, GenTreeFlags i handleNode->gtFlags |= GTF_IND_INVARIANT; } - iconNode->AsIntCon()->gtCompileTimeHandle = (size_t)compileTimeHandle; + iconNode->gtCompileTimeHandle = (size_t)compileTimeHandle; +#ifdef DEBUG + if (iconFlags == GTF_ICON_FTN_ADDR) + { + iconNode->gtTargetHandle = (size_t)compileTimeHandle; + } +#endif return handleNode; } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index b9ba82532a554..c0de433f8328f 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -3056,8 +3056,7 @@ struct GenTreeIntCon : public GenTreeIntConCommon FieldSeqNode* gtFieldSeq; #ifdef DEBUG - // If the value represents target address, holds the method handle to that target which is used - // to fetch target method name and display in the disassembled code. + // If the value represents target address (for a field or call), holds the handle of the field (or call). size_t gtTargetHandle = 0; #endif diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 316ea1670e4ed..5ddc2eed4f144 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1938,8 +1938,8 @@ GenTree* Compiler::impTokenToHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken, } // Generate the full lookup tree. May be null if we're abandoning an inline attempt. - GenTree* result = impLookupToTree(pResolvedToken, &embedInfo.lookup, gtTokenToIconFlags(pResolvedToken->token), - embedInfo.compileTimeHandle); + GenTreeFlags handleType = importParent ? GTF_ICON_CLASS_HDL : gtTokenToIconFlags(pResolvedToken->token); + GenTree* result = impLookupToTree(pResolvedToken, &embedInfo.lookup, handleType, embedInfo.compileTimeHandle); // If we have a result and it requires runtime lookup, wrap it in a runtime lookup node. if ((result != nullptr) && embedInfo.lookup.lookupKind.needsRuntimeLookup) @@ -8853,9 +8853,7 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT // Create the address node. GenTreeFlags handleKind = isBoxedStatic ? GTF_ICON_STATIC_BOX_PTR : GTF_ICON_STATIC_HDL; op1 = gtNewIconHandleNode((size_t)fldAddr, handleKind, innerFldSeq); -#ifdef DEBUG - op1->AsIntCon()->gtTargetHandle = op1->AsIntCon()->gtIconVal; -#endif + INDEBUG(op1->AsIntCon()->gtTargetHandle = reinterpret_cast(pResolvedToken->hField)); if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS) { diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index ec5d602d5eb64..d41ad4babb679 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2107,9 +2107,7 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call size_t addrValue = (size_t)call->gtEntryPoint.addr; GenTree* indirectCellAddress = comp->gtNewIconHandleNode(addrValue, GTF_ICON_FTN_ADDR); -#ifdef DEBUG - indirectCellAddress->AsIntCon()->gtTargetHandle = (size_t)call->gtCallMethHnd; -#endif + INDEBUG(indirectCellAddress->AsIntCon()->gtTargetHandle = (size_t)call->gtCallMethHnd); indirectCellAddress->SetRegNum(REG_R2R_INDIRECT_PARAM); #ifdef TARGET_ARM // Issue #xxxx : Don't attempt to CSE this constant on ARM32 @@ -5494,7 +5492,8 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac) { handleKind = GTF_ICON_STATIC_HDL; } - GenTree* addr = gtNewIconHandleNode((size_t)fldAddr, handleKind, fieldSeq); + GenTreeIntCon* addr = gtNewIconHandleNode((size_t)fldAddr, handleKind, fieldSeq); + INDEBUG(addr->gtTargetHandle = reinterpret_cast(symHnd)); // Translate GTF_FLD_INITCLASS to GTF_ICON_INITCLASS, if we need to. if (((tree->gtFlags & GTF_FLD_INITCLASS) != 0) && !isStaticReadOnlyInited) @@ -7933,9 +7932,7 @@ GenTree* Compiler::fgGetStubAddrArg(GenTreeCall* call) assert(call->gtCallMoreFlags & GTF_CALL_M_VIRTSTUB_REL_INDIRECT); ssize_t addr = ssize_t(call->gtStubCallStubAddr); stubAddrArg = gtNewIconHandleNode(addr, GTF_ICON_FTN_ADDR); -#ifdef DEBUG - stubAddrArg->AsIntCon()->gtTargetHandle = (size_t)call->gtCallMethHnd; -#endif + INDEBUG(stubAddrArg->AsIntCon()->gtTargetHandle = (size_t)call->gtCallMethHnd); } assert(stubAddrArg != nullptr); stubAddrArg->SetRegNum(virtualStubParamInfo->GetReg()); @@ -8822,7 +8819,8 @@ GenTree* Compiler::fgMorphLeaf(GenTree* tree) // target of a Delegate or a raw function pointer. bool isUnsafeFunctionPointer = !fptrValTree->gtFptrDelegateTarget; - CORINFO_CONST_LOOKUP addrInfo; + CORINFO_CONST_LOOKUP addrInfo; + CORINFO_METHOD_HANDLE funcHandle = fptrValTree->gtFptrMethod; #ifdef FEATURE_READYTORUN if (fptrValTree->gtEntryPoint.addr != nullptr) @@ -8832,7 +8830,7 @@ GenTree* Compiler::fgMorphLeaf(GenTree* tree) else #endif { - info.compCompHnd->getFunctionFixedEntryPoint(fptrValTree->gtFptrMethod, isUnsafeFunctionPointer, &addrInfo); + info.compCompHnd->getFunctionFixedEntryPoint(funcHandle, isUnsafeFunctionPointer, &addrInfo); } GenTree* indNode = nullptr; @@ -8851,6 +8849,7 @@ GenTree* Compiler::fgMorphLeaf(GenTree* tree) case IAT_PVALUE: indNode = gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)addrInfo.handle, GTF_ICON_FTN_ADDR, true); + INDEBUG(indNode->gtGetOp1()->AsIntCon()->gtTargetHandle = reinterpret_cast(funcHandle)); break; case IAT_VALUE: @@ -8859,6 +8858,7 @@ GenTree* Compiler::fgMorphLeaf(GenTree* tree) tree->SetOper(GT_CNS_INT); tree->AsIntConCommon()->SetIconValue(ssize_t(addrInfo.handle)); tree->gtFlags |= GTF_ICON_FTN_ADDR; + INDEBUG(tree->AsIntCon()->gtTargetHandle = reinterpret_cast(funcHandle)); break; default: