Skip to content

Commit 95e8cae

Browse files
authored
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
1 parent 5efc1bb commit 95e8cae

15 files changed

+134
-61
lines changed

src/coreclr/jit/codegenarm64.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size,
21782178
{
21792179
if (emitter::emitIns_valid_imm_for_mov(imm, size))
21802180
{
2181-
GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm);
2181+
GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm, INS_OPTS_NONE DEBUGARG(targetHandle) DEBUGARG(gtFlags));
21822182
}
21832183
else
21842184
{
@@ -2224,7 +2224,9 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size,
22242224
imm16 = ~imm16;
22252225
}
22262226

2227-
GetEmitter()->emitIns_R_I_I(ins, size, reg, imm16, i, INS_OPTS_LSL);
2227+
GetEmitter()->emitIns_R_I_I(ins, size, reg, imm16, i,
2228+
INS_OPTS_LSL DEBUGARG(i == 0 ? targetHandle : 0)
2229+
DEBUGARG(i == 0 ? gtFlags : GTF_EMPTY));
22282230

22292231
// Once the initial movz/movn is emitted the remaining instructions will all use movk
22302232
ins = INS_movk;
@@ -2258,8 +2260,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
22582260
{
22592261
case GT_CNS_INT:
22602262
{
2261-
GenTreeIntConCommon* con = tree->AsIntConCommon();
2262-
ssize_t cnsVal = con->IconValue();
2263+
GenTreeIntCon* con = tree->AsIntCon();
2264+
ssize_t cnsVal = con->IconValue();
22632265

22642266
emitAttr attr = emitActualTypeSize(targetType);
22652267
// 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
22752277
}
22762278

22772279
instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal,
2278-
INS_FLAGS_DONT_CARE DEBUGARG(tree->AsIntCon()->gtTargetHandle)
2279-
DEBUGARG(tree->AsIntCon()->gtFlags));
2280+
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags));
22802281
regSet.verifyRegUsed(targetReg);
22812282
}
22822283
break;

src/coreclr/jit/codegenxarch.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size,
442442
}
443443
else
444444
{
445-
GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm DEBUGARG(gtFlags));
445+
GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags));
446446
}
447447
}
448448
regSet.verifyRegUsed(reg);
@@ -462,8 +462,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
462462
{
463463
// relocatable values tend to come down as a CNS_INT of native int type
464464
// so the line between these two opcodes is kind of blurry
465-
GenTreeIntConCommon* con = tree->AsIntConCommon();
466-
ssize_t cnsVal = con->IconValue();
465+
GenTreeIntCon* con = tree->AsIntCon();
466+
ssize_t cnsVal = con->IconValue();
467467

468468
emitAttr attr = emitActualTypeSize(targetType);
469469
// Currently this cannot be done for all handles due to
@@ -482,7 +482,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
482482
attr = EA_SET_FLG(attr, EA_BYREF_FLG);
483483
}
484484

485-
instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, INS_FLAGS_DONT_CARE DEBUGARG(0) DEBUGARG(tree->gtFlags));
485+
instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal,
486+
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags));
486487
regSet.verifyRegUsed(targetReg);
487488
}
488489
break;

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ class Compiler
22692269

22702270
GenTree* gtNewIndOfIconHandleNode(var_types indType, size_t value, GenTreeFlags iconFlags, bool isInvariant);
22712271

2272-
GenTree* gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields = nullptr);
2272+
GenTreeIntCon* gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields = nullptr);
22732273

22742274
GenTreeFlags gtTokenToIconFlags(unsigned token);
22752275

src/coreclr/jit/compiler.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,8 @@ inline GenTree* Compiler::gtNewLargeOperNode(genTreeOps oper, var_types type, Ge
902902
* that may need to be fixed up).
903903
*/
904904

905-
inline GenTree* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields)
905+
inline GenTreeIntCon* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags, FieldSeqNode* fields)
906906
{
907-
GenTree* node;
908907
assert((flags & (GTF_ICON_HDL_MASK | GTF_ICON_FIELD_OFF)) != 0);
909908

910909
// Interpret "fields == NULL" as "not a field."
@@ -913,6 +912,7 @@ inline GenTree* Compiler::gtNewIconHandleNode(size_t value, GenTreeFlags flags,
913912
fields = FieldSeqStore::NotAField();
914913
}
915914

915+
GenTreeIntCon* node;
916916
#if defined(LATE_DISASM)
917917
node = new (this, LargeOpOpcode()) GenTreeIntCon(TYP_I_IMPL, value, fields DEBUGARG(/*largeNode*/ true));
918918
#else
@@ -1370,6 +1370,7 @@ inline void GenTree::SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate)
13701370
{
13711371
case GT_CNS_INT:
13721372
AsIntCon()->gtFieldSeq = FieldSeqStore::NotAField();
1373+
INDEBUG(AsIntCon()->gtTargetHandle = 0);
13731374
break;
13741375
#if defined(TARGET_ARM)
13751376
case GT_MUL_LONG:

src/coreclr/jit/emit.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,25 +4045,48 @@ void emitter::emitRecomputeIGoffsets()
40454045
//
40464046
// Arguments:
40474047
// handle - a constant value to display a comment for
4048+
// cookie - the cookie stored with the handle
40484049
// flags - a flag that the describes the handle
40494050
//
4050-
void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag)
4051+
void emitter::emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlags flag)
40514052
{
40524053
#ifdef DEBUG
4053-
if (handle == 0)
4054-
{
4055-
return;
4056-
}
4057-
40584054
#ifdef TARGET_XARCH
40594055
const char* commentPrefix = " ;";
40604056
#else
40614057
const char* commentPrefix = " //";
40624058
#endif
40634059

40644060
flag &= GTF_ICON_HDL_MASK;
4065-
const char* str = nullptr;
40664061

4062+
if (cookie != 0)
4063+
{
4064+
if (flag == GTF_ICON_FTN_ADDR)
4065+
{
4066+
const char* className = nullptr;
4067+
const char* methName =
4068+
emitComp->eeGetMethodName(reinterpret_cast<CORINFO_METHOD_HANDLE>(cookie), &className);
4069+
printf("%s code for %s:%s", commentPrefix, className, methName);
4070+
return;
4071+
}
4072+
4073+
if ((flag == GTF_ICON_STATIC_HDL) || (flag == GTF_ICON_STATIC_BOX_PTR))
4074+
{
4075+
const char* className = nullptr;
4076+
const char* fieldName =
4077+
emitComp->eeGetFieldName(reinterpret_cast<CORINFO_FIELD_HANDLE>(cookie), &className);
4078+
printf("%s %s for %s%s%s", commentPrefix, flag == GTF_ICON_STATIC_HDL ? "data" : "box", className,
4079+
className != nullptr ? ":" : "", fieldName);
4080+
return;
4081+
}
4082+
}
4083+
4084+
if (handle == 0)
4085+
{
4086+
return;
4087+
}
4088+
4089+
const char* str = nullptr;
40674090
if (flag == GTF_ICON_STR_HDL)
40684091
{
40694092
const WCHAR* wstr = emitComp->eeGetCPString(handle);
@@ -4103,8 +4126,6 @@ void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag)
41034126
{
41044127
str = emitComp->eeGetClassName(reinterpret_cast<CORINFO_CLASS_HANDLE>(handle));
41054128
}
4106-
#ifndef TARGET_XARCH
4107-
// These are less useful for xarch:
41084129
else if (flag == GTF_ICON_CONST_PTR)
41094130
{
41104131
str = "const ptr";
@@ -4133,11 +4154,6 @@ void emitter::emitDispCommentForHandle(size_t handle, GenTreeFlags flag)
41334154
{
41344155
str = "token handle";
41354156
}
4136-
else
4137-
{
4138-
str = "unknown";
4139-
}
4140-
#endif // TARGET_XARCH
41414157

41424158
if (str != nullptr)
41434159
{

src/coreclr/jit/emit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class emitter
523523

524524
void emitRecomputeIGoffsets();
525525

526-
void emitDispCommentForHandle(size_t handle, GenTreeFlags flags);
526+
void emitDispCommentForHandle(size_t handle, size_t cookie, GenTreeFlags flags);
527527

528528
/************************************************************************/
529529
/* The following describes a single instruction */
@@ -554,7 +554,7 @@ class emitter
554554

555555
#endif // TARGET_XARCH
556556

557-
#ifdef DEBUG // This information is used in DEBUG builds to display the method name for call instructions
557+
#ifdef DEBUG // This information is used in DEBUG builds for additional diagnostics
558558

559559
struct instrDesc;
560560

src/coreclr/jit/emitarm64.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,7 +3740,8 @@ void emitter::emitIns_R_I(instruction ins,
37403740
emitAttr attr,
37413741
regNumber reg,
37423742
ssize_t imm,
3743-
insOpts opt /* = INS_OPTS_NONE */ DEBUGARG(GenTreeFlags gtFlags))
3743+
insOpts opt /* = INS_OPTS_NONE */
3744+
DEBUGARG(size_t targetHandle /* = 0 */) DEBUGARG(GenTreeFlags gtFlags /* = GTF_EMPTY */))
37443745
{
37453746
emitAttr size = EA_SIZE(attr);
37463747
emitAttr elemsize = EA_UNKNOWN;
@@ -3990,7 +3991,11 @@ void emitter::emitIns_R_I(instruction ins,
39903991
id->idInsOpt(opt);
39913992

39923993
id->idReg1(reg);
3993-
INDEBUG(id->idDebugOnlyInfo()->idFlags = gtFlags);
3994+
3995+
#ifdef DEBUG
3996+
id->idDebugOnlyInfo()->idMemCookie = targetHandle;
3997+
id->idDebugOnlyInfo()->idFlags = gtFlags;
3998+
#endif
39943999

39954000
dispIns(id);
39964001
appendToCurIG(id);
@@ -4927,8 +4932,13 @@ void emitter::emitIns_R_R(
49274932
* Add an instruction referencing a register and two constants.
49284933
*/
49294934

4930-
void emitter::emitIns_R_I_I(
4931-
instruction ins, emitAttr attr, regNumber reg, ssize_t imm1, ssize_t imm2, insOpts opt /* = INS_OPTS_NONE */)
4935+
void emitter::emitIns_R_I_I(instruction ins,
4936+
emitAttr attr,
4937+
regNumber reg,
4938+
ssize_t imm1,
4939+
ssize_t imm2,
4940+
insOpts opt /* = INS_OPTS_NONE */
4941+
DEBUGARG(size_t targetHandle /* = 0 */) DEBUGARG(GenTreeFlags gtFlags /* = 0 */))
49324942
{
49334943
emitAttr size = EA_SIZE(attr);
49344944
insFormat fmt = IF_NONE;
@@ -5015,6 +5025,11 @@ void emitter::emitIns_R_I_I(
50155025

50165026
id->idReg1(reg);
50175027

5028+
#ifdef DEBUG
5029+
id->idDebugOnlyInfo()->idFlags = gtFlags;
5030+
id->idDebugOnlyInfo()->idMemCookie = targetHandle;
5031+
#endif
5032+
50185033
dispIns(id);
50195034
appendToCurIG(id);
50205035
}
@@ -12487,7 +12502,7 @@ void emitter::emitDispIns(
1248712502
}
1248812503
else
1248912504
{
12490-
emitDispCommentForHandle(id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
12505+
emitDispCommentForHandle(id->idDebugOnlyInfo()->idMemCookie, 0, id->idDebugOnlyInfo()->idFlags);
1249112506
}
1249212507
break;
1249312508

@@ -12623,6 +12638,7 @@ void emitter::emitDispIns(
1262312638
case IF_DI_1A: // DI_1A X.......shiiiiii iiiiiinnnnn..... Rn imm(i12,sh)
1262412639
emitDispReg(id->idReg1(), size, true);
1262512640
emitDispImmOptsLSL12(emitGetInsSC(id), id->idInsOpt());
12641+
emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
1262612642
break;
1262712643

1262812644
case IF_DI_1B: // DI_1B X........hwiiiii iiiiiiiiiiiddddd Rd imm(i16,hw)
@@ -12641,18 +12657,21 @@ void emitter::emitDispIns(
1264112657
emitDispImm(hwi.immHW * 16, false);
1264212658
}
1264312659
}
12660+
emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
1264412661
break;
1264512662

1264612663
case IF_DI_1C: // DI_1C X........Nrrrrrr ssssssnnnnn..... Rn imm(N,r,s)
1264712664
emitDispReg(id->idReg1(), size, true);
1264812665
bmi.immNRS = (unsigned)emitGetInsSC(id);
1264912666
emitDispImm(emitDecodeBitMaskImm(bmi, size), false);
12667+
emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
1265012668
break;
1265112669

1265212670
case IF_DI_1D: // DI_1D X........Nrrrrrr ssssss.....ddddd Rd imm(N,r,s)
1265312671
emitDispReg(encodingZRtoSP(id->idReg1()), size, true);
1265412672
bmi.immNRS = (unsigned)emitGetInsSC(id);
1265512673
emitDispImm(emitDecodeBitMaskImm(bmi, size), false);
12674+
emitDispCommentForHandle(0, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
1265612675
break;
1265712676

1265812677
case IF_DI_2A: // DI_2A X.......shiiiiii iiiiiinnnnnddddd Rd Rn imm(i12,sh)

src/coreclr/jit/emitarm64.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ void emitIns_R_I(instruction ins,
726726
emitAttr attr,
727727
regNumber reg,
728728
ssize_t imm,
729-
insOpts opt = INS_OPTS_NONE DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY));
729+
insOpts opt = INS_OPTS_NONE DEBUGARG(size_t targetHandle = 0)
730+
DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY));
730731

731732
void emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl, insOpts opt = INS_OPTS_NONE);
732733

@@ -740,8 +741,13 @@ void emitIns_R_R(instruction ins, emitAttr attr, regNumber reg1, regNumber reg2,
740741
emitIns_R_R(ins, attr, reg1, reg2);
741742
}
742743

743-
void emitIns_R_I_I(
744-
instruction ins, emitAttr attr, regNumber reg1, ssize_t imm1, ssize_t imm2, insOpts opt = INS_OPTS_NONE);
744+
void emitIns_R_I_I(instruction ins,
745+
emitAttr attr,
746+
regNumber reg1,
747+
ssize_t imm1,
748+
ssize_t imm2,
749+
insOpts opt = INS_OPTS_NONE DEBUGARG(size_t targetHandle = 0)
750+
DEBUGARG(GenTreeFlags gtFlags = GTF_EMPTY));
745751

746752
void emitIns_R_R_I(
747753
instruction ins, emitAttr attr, regNumber reg1, regNumber reg2, ssize_t imm, insOpts opt = INS_OPTS_NONE);

src/coreclr/jit/emitxarch.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,11 @@ void emitter::emitHandleMemOp(GenTreeIndir* indir, instrDesc* id, insFormat fmt,
32193219

32203220
id->idAddr()->iiaFieldHnd = fldHnd;
32213221
id->idInsFmt(emitMapFmtForIns(emitMapFmtAtoM(fmt), ins));
3222+
3223+
#ifdef DEBUG
3224+
id->idDebugOnlyInfo()->idFlags = GTF_ICON_STATIC_HDL;
3225+
id->idDebugOnlyInfo()->idMemCookie = reinterpret_cast<size_t>(fldHnd);
3226+
#endif
32223227
}
32233228
else if ((memBase != nullptr) && memBase->IsCnsIntOrI() && memBase->isContained())
32243229
{
@@ -3279,6 +3284,14 @@ void emitter::emitHandleMemOp(GenTreeIndir* indir, instrDesc* id, insFormat fmt,
32793284
// disp must have already been set in the instrDesc constructor.
32803285
assert(emitGetInsAmdAny(id) == indir->Offset()); // make sure "disp" is stored properly
32813286
}
3287+
3288+
#ifdef DEBUG
3289+
if ((memBase != nullptr) && memBase->IsIconHandle() && memBase->isContained())
3290+
{
3291+
id->idDebugOnlyInfo()->idFlags = memBase->gtFlags;
3292+
id->idDebugOnlyInfo()->idMemCookie = memBase->AsIntCon()->gtTargetHandle;
3293+
}
3294+
#endif
32823295
}
32833296

32843297
// Takes care of storing all incoming register parameters
@@ -4126,7 +4139,10 @@ void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg)
41264139
* Add an instruction referencing a register and a constant.
41274140
*/
41284141

4129-
void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t val DEBUGARG(GenTreeFlags gtFlags))
4142+
void emitter::emitIns_R_I(instruction ins,
4143+
emitAttr attr,
4144+
regNumber reg,
4145+
ssize_t val DEBUGARG(size_t targetHandle) DEBUGARG(GenTreeFlags gtFlags))
41304146
{
41314147
emitAttr size = EA_SIZE(attr);
41324148

@@ -4259,7 +4275,11 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t
42594275
id->idInsFmt(fmt);
42604276
id->idReg1(reg);
42614277
id->idCodeSize(sz);
4262-
INDEBUG(id->idDebugOnlyInfo()->idFlags = gtFlags);
4278+
4279+
#ifdef DEBUG
4280+
id->idDebugOnlyInfo()->idFlags = gtFlags;
4281+
id->idDebugOnlyInfo()->idMemCookie = targetHandle;
4282+
#endif
42634283

42644284
dispIns(id);
42654285
emitCurIGsize += sz;
@@ -9118,7 +9138,7 @@ void emitter::emitDispIns(
91189138
{ // (val < 0)
91199139
printf("-0x%IX", -val);
91209140
}
9121-
emitDispCommentForHandle(srcVal, id->idDebugOnlyInfo()->idFlags);
9141+
emitDispCommentForHandle(srcVal, id->idDebugOnlyInfo()->idMemCookie, id->idDebugOnlyInfo()->idFlags);
91229142
}
91239143
break;
91249144

@@ -9189,6 +9209,9 @@ void emitter::emitDispIns(
91899209
}
91909210
printf("%s, %s", emitRegName(id->idReg1(), attr), sstr);
91919211
emitDispAddrMode(id);
9212+
9213+
emitDispCommentForHandle(emitGetInsAmdAny(id), id->idDebugOnlyInfo()->idMemCookie,
9214+
id->idDebugOnlyInfo()->idFlags);
91929215
break;
91939216

91949217
case IF_RRW_ARD_CNS:

0 commit comments

Comments
 (0)