@@ -964,6 +964,32 @@ static void updateDefinedRegisters(MachineInstr &MI, LiveRegUnits &Units,
964
964
Units.addReg (MOP.getReg ());
965
965
}
966
966
967
+ // / This function will add a new entry into the debugValueSubstitutions table
968
+ // / when two instruction have been merged into a new one represented by \p
969
+ // / MergedInstr.
970
+ static void addDebugSubstitutionsToTable (MachineFunction *MF,
971
+ unsigned InstrNumToSet,
972
+ MachineInstr &OriginalInstr,
973
+ MachineInstr &MergedInstr) {
974
+
975
+ // Figure out the Operand Index of the destination register of the
976
+ // OriginalInstr in the new MergedInstr.
977
+ auto Reg = OriginalInstr.getOperand (0 ).getReg ();
978
+ unsigned OperandNo = 0 ;
979
+ bool RegFound = false ;
980
+ for (const auto Op : MergedInstr.operands ()) {
981
+ if (Op.getReg () == Reg) {
982
+ RegFound = true ;
983
+ break ;
984
+ }
985
+ OperandNo++;
986
+ }
987
+
988
+ if (RegFound)
989
+ MF->makeDebugValueSubstitution ({OriginalInstr.peekDebugInstrNum (), 0 },
990
+ {InstrNumToSet, OperandNo});
991
+ }
992
+
967
993
MachineBasicBlock::iterator
968
994
AArch64LoadStoreOpt::mergePairedInsns (MachineBasicBlock::iterator I,
969
995
MachineBasicBlock::iterator Paired,
@@ -1226,6 +1252,79 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
1226
1252
.addImm (0 )
1227
1253
.addImm (31 );
1228
1254
(void )MIBSXTW;
1255
+
1256
+ // In the case of a sign-extend, where we have something like:
1257
+ // debugValueSubstitutions:[]
1258
+ // $w1 = LDRWui $x0, 1, debug-instr-number 1
1259
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
1260
+ // $x0 = LDRSWui $x0, 0, debug-instr-number 2
1261
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
1262
+
1263
+ // It will be converted to:
1264
+ // debugValueSubstitutions:[]
1265
+ // $w0, $w1 = LDPWi $x0, 0
1266
+ // $w0 = KILL $w0, implicit-def $x0
1267
+ // $x0 = SBFMXri $x0, 0, 31
1268
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
1269
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
1270
+
1271
+ // We want the final result to look like:
1272
+ // debugValueSubstitutions:
1273
+ // - { srcinst: 1, srcop: 0, dstinst: 4, dstop: 1, subreg: 0 }
1274
+ // - { srcinst: 2, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
1275
+ // $w0, $w1 = LDPWi $x0, 0, debug-instr-number 4
1276
+ // $w0 = KILL $w0, implicit-def $x0
1277
+ // $x0 = SBFMXri $x0, 0, 31, debug-instr-number 3
1278
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
1279
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
1280
+
1281
+ // $x0 is where the final value is stored, so the sign extend (SBFMXri)
1282
+ // instruction contains the final value we care about we give it a new
1283
+ // debug-instr-number 3. Whereas, $w1 contains the final value that we care
1284
+ // about, therefore the LDP instruction is also given a new
1285
+ // debug-instr-number 4. We have to add these subsitutions to the
1286
+ // debugValueSubstitutions table. However, we also have to ensure that the
1287
+ // OpIndex that pointed to debug-instr-number 1 gets updated to 1, because
1288
+ // $w1 is the second operand of the LDP instruction.
1289
+
1290
+ if (I->peekDebugInstrNum ()) {
1291
+ // If I is the instruction which got sign extended and has a
1292
+ // debug-instr-number, give the SBFMXri instruction a new
1293
+ // debug-instr-number, and update the debugValueSubstitutions table with
1294
+ // the new debug-instr-number and OpIndex pair. Otherwise, give the Merged
1295
+ // instruction a new debug-instr-number, and update the
1296
+ // debugValueSubstitutions table with the new debug-instr-number and
1297
+ // OpIndex pair.
1298
+ unsigned NewInstrNum;
1299
+ if (DstRegX == I->getOperand (0 ).getReg ()) {
1300
+ NewInstrNum = MIBSXTW->getDebugInstrNum ();
1301
+ addDebugSubstitutionsToTable (MBB->getParent (), NewInstrNum, *I,
1302
+ *MIBSXTW);
1303
+ } else {
1304
+ NewInstrNum = MIB->getDebugInstrNum ();
1305
+ addDebugSubstitutionsToTable (MBB->getParent (), NewInstrNum, *I, *MIB);
1306
+ }
1307
+ }
1308
+ if (Paired->peekDebugInstrNum ()) {
1309
+ // If Paired is the instruction which got sign extended and has a
1310
+ // debug-instr-number, give the SBFMXri instruction a new
1311
+ // debug-instr-number, and update the debugValueSubstitutions table with
1312
+ // the new debug-instr-number and OpIndex pair. Otherwise, give the Merged
1313
+ // instruction a new debug-instr-number, and update the
1314
+ // debugValueSubstitutions table with the new debug-instr-number and
1315
+ // OpIndex pair.
1316
+ unsigned NewInstrNum;
1317
+ if (DstRegX == Paired->getOperand (0 ).getReg ()) {
1318
+ NewInstrNum = MIBSXTW->getDebugInstrNum ();
1319
+ addDebugSubstitutionsToTable (MBB->getParent (), NewInstrNum, *Paired,
1320
+ *MIBSXTW);
1321
+ } else {
1322
+ NewInstrNum = MIB->getDebugInstrNum ();
1323
+ addDebugSubstitutionsToTable (MBB->getParent (), NewInstrNum, *Paired,
1324
+ *MIB);
1325
+ }
1326
+ }
1327
+
1229
1328
LLVM_DEBUG (dbgs () << " Extend operand:\n " );
1230
1329
LLVM_DEBUG (((MachineInstr *)MIBSXTW)->print (dbgs ()));
1231
1330
} else if (Opc == AArch64::LDR_ZXI || Opc == AArch64::STR_ZXI) {
@@ -1239,6 +1338,45 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
1239
1338
MOp1.setReg (AArch64::Q0 + (MOp1.getReg () - AArch64::Z0));
1240
1339
LLVM_DEBUG (((MachineInstr *)MIB)->print (dbgs ()));
1241
1340
} else {
1341
+
1342
+ // In the case that the merge doesn't result in a sign-extend, if we have
1343
+ // something like:
1344
+ // debugValueSubstitutions:[]
1345
+ // $x1 = LDRXui $x0, 1, debug-instr-number 1
1346
+ // DBG_INSTR_REF !13, dbg-instr-ref(1, 0), debug-location !11
1347
+ // $x0 = LDRXui killed $x0, 0, debug-instr-number 2
1348
+ // DBG_INSTR_REF !14, dbg-instr-ref(2, 0), debug-location !11
1349
+
1350
+ // It will be converted to:
1351
+ // debugValueSubstitutions: []
1352
+ // $x0, $x1 = LDPXi $x0, 0
1353
+ // DBG_INSTR_REF !12, dbg-instr-ref(1, 0), debug-location !14
1354
+ // DBG_INSTR_REF !13, dbg-instr-ref(2, 0), debug-location !14
1355
+
1356
+ // We want the final result to look like:
1357
+ // debugValueSubstitutions:
1358
+ // - { srcinst: 1, srcop: 0, dstinst: 3, dstop: 1, subreg: 0 }
1359
+ // - { srcinst: 2, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
1360
+ // $x0, $x1 = LDPXi $x0, 0, debug-instr-number 3
1361
+ // DBG_INSTR_REF !12, dbg-instr-ref(1, 0), debug-location !14
1362
+ // DBG_INSTR_REF !12, dbg-instr-ref(2, 0), debug-location !14
1363
+
1364
+ // Here all that needs to be done is, that the LDP instruction needs to be
1365
+ // updated with a new debug-instr-number, we then need to add entries into
1366
+ // the debugSubstitutions table to map the old instr-refs to the new ones.
1367
+
1368
+ // Assign new DebugInstrNum to the Paired instruction.
1369
+ if (I->peekDebugInstrNum ()) {
1370
+ unsigned NewDebugInstrNum = MIB->getDebugInstrNum ();
1371
+ addDebugSubstitutionsToTable (MBB->getParent (), NewDebugInstrNum, *I,
1372
+ *MIB);
1373
+ }
1374
+ if (Paired->peekDebugInstrNum ()) {
1375
+ unsigned NewDebugInstrNum = MIB->getDebugInstrNum ();
1376
+ addDebugSubstitutionsToTable (MBB->getParent (), NewDebugInstrNum, *Paired,
1377
+ *MIB);
1378
+ }
1379
+
1242
1380
LLVM_DEBUG (((MachineInstr *)MIB)->print (dbgs ()));
1243
1381
}
1244
1382
LLVM_DEBUG (dbgs () << " \n " );
0 commit comments