@@ -2924,7 +2924,7 @@ uint32_t DwarfDebug::writeStackcallCIE() {
2924
2924
// return address register - uleb128
2925
2925
// set machine return register to one which is physically
2926
2926
// absent. later CFA instructions map this to a valid GRF.
2927
- writeULEB128 (data, RegisterNumbering::IP );
2927
+ writeULEB128 (data, GetEncodedRegNum< RegisterNumbering::GRFBase>(numGRFs) );
2928
2928
2929
2929
// initial instructions (array of ubyte)
2930
2930
// DW_OP_regx r125
@@ -2933,12 +2933,11 @@ uint32_t DwarfDebug::writeStackcallCIE() {
2933
2933
2934
2934
// The DW_CFA_def_cfa_expression instruction takes a single operand
2935
2935
// encoded as a DW_FORM_exprloc.
2936
- // We define DW_CFA_def_cfa_expression to point to caller's BE_SP.
2937
2936
auto DWRegEncoded = GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF);
2938
2937
write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
2939
2938
write (data1, (uint32_t )(DWRegEncoded));
2940
2939
write (data1, (uint8_t )llvm::dwarf::DW_OP_const2u);
2941
- write (data1, (uint16_t )(getBESPSubReg () * 4 * 8 ));
2940
+ write (data1, (uint16_t )(getBEFPSubReg () * 4 * 8 ));
2942
2941
write (data1, (uint8_t )DW_OP_INTEL_regval_bits);
2943
2942
write (data1, (uint8_t )32 );
2944
2943
@@ -2972,20 +2971,10 @@ uint32_t DwarfDebug::writeStackcallCIE() {
2972
2971
}
2973
2972
2974
2973
// move return address register to actual location
2975
- if (GetABIVersion () < 3 ) {
2976
- // DW_CFA_register IP specialGRF
2977
- write (data, (uint8_t )llvm::dwarf::DW_CFA_register);
2978
- writeULEB128 (data, RegisterNumbering::IP);
2979
- writeULEB128 (data,
2980
- GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF));
2981
- } else {
2982
- write (data, (uint8_t )llvm::dwarf::DW_CFA_expression);
2983
- writeULEB128 (data, RegisterNumbering::IP);
2984
- writeULEB128 (data, 6 );
2985
- write (data, (uint8_t )llvm::dwarf::DW_OP_const4u);
2986
- write (data, (uint32_t )getRetIPSubReg () * 4 );
2987
- write (data, (uint8_t )llvm::dwarf::DW_OP_plus);
2988
- }
2974
+ // DW_CFA_register numGRFs specialGRF
2975
+ write (data, (uint8_t )llvm::dwarf::DW_CFA_register);
2976
+ writeULEB128 (data, GetEncodedRegNum<RegisterNumbering::GRFBase>(numGRFs));
2977
+ writeULEB128 (data, GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF));
2989
2978
2990
2979
while ((lenSize + data.size ()) % ptrSize != 0 )
2991
2980
// Insert DW_CFA_nop
@@ -3114,6 +3103,7 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3114
3103
auto sortAsc = [](uint64_t a, uint64_t b) { return a < b; };
3115
3104
std::map<uint64_t , std::vector<uint8_t >, decltype (sortAsc)> cfaOps (sortAsc);
3116
3105
const auto &DbgInfo = *VisaDbgInfo;
3106
+ auto numGRFs = GetVISAModule ()->getNumGRFs ();
3117
3107
auto specialGRF = GetSpecialGRF ();
3118
3108
3119
3109
auto advanceLoc = [&loc](std::vector<uint8_t > &data, uint64_t newLoc) {
@@ -3134,25 +3124,33 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3134
3124
loc = newLoc;
3135
3125
};
3136
3126
3137
- // When useBEFP is true, expression refers to BEFP. Otherwise,
3138
- // expression refers to BESP.
3139
- auto writeOffBEStack = [specialGRF, this ](std::vector<uint8_t > &data,
3140
- bool useBEFP) {
3141
- // DW_OP_const4u 127
3142
- // DW_OP_const2u BE_FP_SubReg
3143
- // DW_OP_INTEL_regval_bits 32
3144
- // DW_OP_breg6
3127
+ // offset to read off be_fp
3128
+ // deref - decide whether or not to emit DW_OP_deref
3129
+ // normalizeResult - true when reading a value from scratch space that is a
3130
+ // scratch space address
3131
+ auto writeOffBEFP = [specialGRF, this ](std::vector<uint8_t > &data,
3132
+ uint32_t offset, bool deref,
3133
+ bool normalizeResult) {
3134
+ // DW_OP_const1u 12
3135
+ // DW_OP_regx 125
3136
+ // DW_OP_const2u 96
3137
+ // DW_OP_const1u 32
3138
+ // DW_OP_INTEL_push_bit_piece_stack
3139
+ // DW_OP_const1u 16
3140
+ // DW_OP_mul
3141
+ // DW_OP_constu <memory offset>
3145
3142
// DW_OP_plus
3146
-
3143
+ // DW_OP_constu 0x900000000000000
3144
+ // DW_OP_or
3145
+ // DW_OP_deref
3147
3146
std::vector<uint8_t > data1;
3148
3147
3149
3148
auto DWRegEncoded =
3150
3149
GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF);
3151
3150
write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
3152
3151
write (data1, (uint32_t )(DWRegEncoded));
3153
3152
write (data1, (uint8_t )llvm::dwarf::DW_OP_const2u);
3154
- write (data1,
3155
- (uint16_t )((useBEFP ? getBEFPSubReg () : getBESPSubReg ()) * 4 * 8 ));
3153
+ write (data1, (uint16_t )(getBEFPSubReg () * 4 * 8 ));
3156
3154
write (data1, (uint8_t )DW_OP_INTEL_regval_bits);
3157
3155
write (data1, (uint8_t )32 );
3158
3156
@@ -3165,20 +3163,49 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3165
3163
write (data1, (uint8_t )llvm::dwarf::DW_OP_mul);
3166
3164
}
3167
3165
3166
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_constu);
3167
+ writeULEB128 (data1, offset);
3168
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_plus);
3169
+
3168
3170
// indicate that the resulting address is on BE stack
3169
3171
encodeScratchAddrSpace (data1);
3170
3172
3173
+ if (deref) {
3174
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_deref);
3175
+ // DW_OP_deref reads as many bytes as size of address on target machine.
3176
+ // We set address size to 64 bits in CIE. However, this expression
3177
+ // refers to a slot in scratch space which uses 32-bit addressing. So
3178
+ // mask upper 32 bits read from VISA frame descriptor.
3179
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
3180
+ write (data1, (uint32_t )0xffffffff );
3181
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_and);
3182
+ }
3183
+
3184
+ if (EmitSettings.ScratchOffsetInOW && normalizeResult) {
3185
+ // since data stored in scratch space is also in oword units, normalize it
3186
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const1u);
3187
+ write (data1, (uint8_t )16 );
3188
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_mul);
3189
+ }
3190
+
3191
+ if (deref) {
3192
+ // DW_OP_deref earlier causes CFA to be put on top of dwarf stack.
3193
+ // Indicate that the address space of CFA is scratch.
3194
+ encodeScratchAddrSpace (data1);
3195
+ }
3196
+
3171
3197
writeULEB128 (data, data1.size ());
3172
3198
for (auto item : data1)
3173
3199
write (data, (uint8_t )item);
3174
3200
};
3175
3201
3176
- auto writeLR = [this , writeOffBEStack](
3177
- std::vector< uint8_t > &data ,
3178
- const DbgDecoder::LiveIntervalGenISA &lr , bool useBEFP ) {
3202
+ auto writeLR = [this , writeOffBEFP](std::vector< uint8_t > &data,
3203
+ const DbgDecoder::LiveIntervalGenISA &lr ,
3204
+ bool deref , bool normalizeResult ) {
3179
3205
if (lr.var .physicalType ==
3180
3206
DbgDecoder::VarAlloc::PhysicalVarType::PhyTypeMemory) {
3181
- writeOffBEStack (data, useBEFP);
3207
+ writeOffBEFP (data, (uint32_t )lr.var .mapping .m .memoryOffset , deref,
3208
+ normalizeResult);
3182
3209
3183
3210
IGC_ASSERT_MESSAGE (!lr.var .mapping .m .isBaseOffBEFP ,
3184
3211
" Expecting location offset from BE_FP" );
@@ -3193,23 +3220,6 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3193
3220
writeULEB128 (data, srcReg);
3194
3221
};
3195
3222
3196
- // Caller has written DW_CFA_expression and a register. Here, we
3197
- // emit offset off CFA where the register is stored. For eg,
3198
- // DW_CFA_expression: r143 (DW_OP_const4u: 0; DW_OP_plus)
3199
- //
3200
- // means that r127 is stored at [CFA + 0]
3201
- auto writeCFAExpr = [](std::vector<uint8_t > &data, uint32_t offset) {
3202
- std::vector<uint8_t > data1;
3203
-
3204
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
3205
- write (data1, (uint32_t )offset);
3206
- write (data1, (uint8_t )llvm::dwarf::DW_OP_plus);
3207
-
3208
- writeULEB128 (data, data1.size ());
3209
- for (auto item : data1)
3210
- write (data, (uint8_t )item);
3211
- };
3212
-
3213
3223
auto ptrSize = Asm->GetPointerSize ();
3214
3224
const auto &CFI = DbgInfo.getCFI ();
3215
3225
// Emit CIE
@@ -3248,15 +3258,15 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3248
3258
// map out CFA to an offset on be stack
3249
3259
write (cfaOps[item.start ],
3250
3260
(uint8_t )llvm::dwarf::DW_CFA_def_cfa_expression);
3251
- writeLR (cfaOps[item.start ], item, true );
3261
+ writeLR (cfaOps[item.start ], item, true , true );
3252
3262
}
3253
3263
3254
3264
// describe r125 is at [r125.3]:ud
3255
3265
auto ip = callerFP.front ().start ;
3256
3266
write (cfaOps[ip], (uint8_t )llvm::dwarf::DW_CFA_expression);
3257
3267
writeULEB128 (cfaOps[ip],
3258
3268
GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF));
3259
- writeCFAExpr (cfaOps[ip], 0 );
3269
+ writeOffBEFP (cfaOps[ip], 0 , false , false );
3260
3270
writeSameValue (cfaOps[callerFP.back ().end + MovGenInstSizeInBytes],
3261
3271
GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF));
3262
3272
}
@@ -3267,8 +3277,9 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3267
3277
for (auto &item : retAddr) {
3268
3278
// start live-range
3269
3279
write (cfaOps[item.start ], (uint8_t )llvm::dwarf::DW_CFA_expression);
3270
- writeULEB128 (cfaOps[item.start ], RegisterNumbering::IP);
3271
- writeCFAExpr (cfaOps[item.start ], getRetIPSubReg () * 4 );
3280
+ writeULEB128 (cfaOps[item.start ],
3281
+ GetEncodedRegNum<RegisterNumbering::GRFBase>(numGRFs));
3282
+ writeLR (cfaOps[item.start ], item, false , false );
3272
3283
3273
3284
// end live-range
3274
3285
// VISA emits following:
@@ -3287,14 +3298,20 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3287
3298
// offset 656 should we read ret %ip from r125 directly. This is achieved
3288
3299
// by taking offset 640 reported by VISA debug info and adding 16 to it
3289
3300
// which is size of the mov instruction.
3290
- writeSameValue (cfaOps[item.end + MovGenInstSizeInBytes],
3291
- RegisterNumbering::IP);
3301
+ write (cfaOps[item.end + MovGenInstSizeInBytes],
3302
+ (uint8_t )llvm::dwarf::DW_CFA_register);
3303
+ writeULEB128 (cfaOps[item.end + MovGenInstSizeInBytes],
3304
+ GetEncodedRegNum<RegisterNumbering::GRFBase>(numGRFs));
3305
+ writeULEB128 (
3306
+ cfaOps[item.end + MovGenInstSizeInBytes],
3307
+ GetEncodedRegNum<RegisterNumbering::GRFBase>(GetSpecialGRF ()));
3292
3308
}
3293
3309
} else {
3294
3310
if (m->GetType () == VISAModule::ObjectType::KERNEL) {
3295
3311
// set return location to be undefined in top frame
3296
3312
write (cfaOps[0 ], (uint8_t )llvm::dwarf::DW_CFA_undefined);
3297
- writeULEB128 (cfaOps[0 ], RegisterNumbering::IP);
3313
+ writeULEB128 (cfaOps[0 ],
3314
+ GetEncodedRegNum<RegisterNumbering::GRFBase>(numGRFs));
3298
3315
}
3299
3316
}
3300
3317
@@ -3313,8 +3330,8 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3313
3330
(uint8_t )llvm::dwarf::DW_CFA_expression);
3314
3331
writeULEB128 (cfaOps[item.genIPOffset ],
3315
3332
GetEncodedRegNum<RegisterNumbering::GRFBase>(regNum));
3316
- writeCFAExpr (cfaOps[item.genIPOffset ],
3317
- ( uint32_t ) item.data [idx].dst .m .memoryOffset );
3333
+ writeOffBEFP (cfaOps[item.genIPOffset ],
3334
+ item.data [idx].dst .m .memoryOffset , false , false );
3318
3335
calleeSaveRegsSaved.insert (regNum);
3319
3336
} else {
3320
3337
// already saved, so no need to emit same save again
0 commit comments