@@ -2784,7 +2784,29 @@ void DwarfDebug::emitDebugMacInfo() {
2784
2784
}
2785
2785
}
2786
2786
2787
- void DwarfDebug::encodeScratchAddrSpace (std::vector<uint8_t > &data) {
2787
+ // Given a number value, decide which UConst DWARF opcode
2788
+ // should be emitted for minimizing size.
2789
+ void DwarfDebug::emitNarrowestUConst (std::vector<uint8_t > &data1,
2790
+ uint64_t value) {
2791
+ if (value <= 31 ) {
2792
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_lit0 + value);
2793
+ } else if (value < 0xff ) {
2794
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const1u);
2795
+ write (data1, (uint8_t )(value));
2796
+ } else if (value < 0xffff ) {
2797
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const2u);
2798
+ write (data1, (uint16_t )(value));
2799
+ } else if (value < 0xffffffff ) {
2800
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
2801
+ write (data1, (uint32_t )(value));
2802
+ } else {
2803
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_const8u);
2804
+ write (data1, (uint64_t )(value));
2805
+ }
2806
+ }
2807
+
2808
+ void DwarfDebug::encodeScratchAddrSpace (std::vector<uint8_t > &data,
2809
+ uint64_t offset) {
2788
2810
uint32_t scratchBaseAddrEncoded = 0 ;
2789
2811
if (m_pModule->usesSlot1ScratchSpill ()) {
2790
2812
scratchBaseAddrEncoded =
@@ -2796,7 +2818,7 @@ void DwarfDebug::encodeScratchAddrSpace(std::vector<uint8_t> &data) {
2796
2818
}
2797
2819
2798
2820
write (data, (uint8_t )scratchBaseAddrEncoded);
2799
- writeULEB128 (data, 0 );
2821
+ writeULEB128 (data, offset );
2800
2822
write (data, (uint8_t )llvm::dwarf::DW_OP_plus);
2801
2823
}
2802
2824
@@ -2939,24 +2961,21 @@ uint32_t DwarfDebug::writeStackcallCIE() {
2939
2961
// The DW_CFA_def_cfa_expression instruction takes a single operand
2940
2962
// encoded as a DW_FORM_exprloc.
2941
2963
auto DWRegEncoded = GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF);
2942
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
2943
- write (data1, (uint32_t )(DWRegEncoded));
2944
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const2u);
2945
- write (data1, (uint16_t )(getBEFPSubReg () * 4 * 8 ));
2964
+ emitNarrowestUConst (data1, DWRegEncoded);
2965
+ emitNarrowestUConst (data1, getBEFPSubReg () * 4 * 8 );
2946
2966
write (data1, (uint8_t )DW_OP_INTEL_regval_bits);
2947
2967
write (data1, (uint8_t )32 );
2948
2968
2949
2969
if (EmitSettings.ScratchOffsetInOW ) {
2950
2970
// when scratch offset is in OW, be_fp has to be multiplied by 16
2951
2971
// to normalize and generate byte offset for complete address
2952
2972
// computation.
2953
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const1u);
2954
- write (data1, (uint8_t )16 );
2973
+ emitNarrowestUConst (data1, 16 );
2955
2974
write (data1, (uint8_t )llvm::dwarf::DW_OP_mul);
2956
2975
}
2957
2976
2958
2977
// indicate that the resulting address is on BE stack
2959
- encodeScratchAddrSpace (data1);
2978
+ encodeScratchAddrSpace (data1, 0 );
2960
2979
2961
2980
writeULEB128 (data, data1.size ());
2962
2981
for (auto item : data1)
@@ -3152,51 +3171,37 @@ void DwarfDebug::writeFDEStackCall(VISAModule *m) {
3152
3171
3153
3172
auto DWRegEncoded =
3154
3173
GetEncodedRegNum<RegisterNumbering::GRFBase>(specialGRF);
3155
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
3156
- write (data1, (uint32_t )(DWRegEncoded));
3157
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const2u);
3158
- write (data1, (uint16_t )(getBEFPSubReg () * 4 * 8 ));
3174
+ emitNarrowestUConst (data1, DWRegEncoded);
3175
+ emitNarrowestUConst (data1, getBEFPSubReg () * 4 * 8 );
3159
3176
write (data1, (uint8_t )DW_OP_INTEL_regval_bits);
3160
3177
write (data1, (uint8_t )32 );
3161
3178
3162
3179
if (EmitSettings.ScratchOffsetInOW ) {
3163
3180
// when scratch offset is in OW, be_fp has to be multiplied by 16
3164
3181
// to normalize and generate byte offset for complete address
3165
3182
// computation.
3166
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const1u);
3167
- write (data1, (uint8_t )16 );
3183
+ emitNarrowestUConst (data1, 16 );
3168
3184
write (data1, (uint8_t )llvm::dwarf::DW_OP_mul);
3169
3185
}
3170
3186
3171
- write (data1, (uint8_t )llvm::dwarf::DW_OP_constu);
3172
- writeULEB128 (data1, offset);
3173
- write (data1, (uint8_t )llvm::dwarf::DW_OP_plus);
3174
-
3175
3187
// indicate that the resulting address is on BE stack
3176
- encodeScratchAddrSpace (data1);
3188
+ encodeScratchAddrSpace (data1, offset );
3177
3189
3178
3190
if (deref) {
3179
- write (data1, (uint8_t )llvm::dwarf::DW_OP_deref);
3180
- // DW_OP_deref reads as many bytes as size of address on target machine.
3181
- // We set address size to 64 bits in CIE. However, this expression
3182
- // refers to a slot in scratch space which uses 32-bit addressing. So
3183
- // mask upper 32 bits read from VISA frame descriptor.
3184
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const4u);
3185
- write (data1, (uint32_t )0xffffffff );
3186
- write (data1, (uint8_t )llvm::dwarf::DW_OP_and);
3191
+ write (data1, (uint8_t )llvm::dwarf::DW_OP_deref_size);
3192
+ write (data1, (uint8_t )4 );
3187
3193
}
3188
3194
3189
3195
if (EmitSettings.ScratchOffsetInOW && normalizeResult) {
3190
3196
// since data stored in scratch space is also in oword units, normalize it
3191
- write (data1, (uint8_t )llvm::dwarf::DW_OP_const1u);
3192
- write (data1, (uint8_t )16 );
3197
+ emitNarrowestUConst (data1, 16 );
3193
3198
write (data1, (uint8_t )llvm::dwarf::DW_OP_mul);
3194
3199
}
3195
3200
3196
3201
if (deref) {
3197
3202
// DW_OP_deref earlier causes CFA to be put on top of dwarf stack.
3198
3203
// Indicate that the address space of CFA is scratch.
3199
- encodeScratchAddrSpace (data1);
3204
+ encodeScratchAddrSpace (data1, 0 );
3200
3205
}
3201
3206
3202
3207
writeULEB128 (data, data1.size ());
0 commit comments