Skip to content

Commit 1f9aa29

Browse files
[AIEX][NFC] Allow passing separate opcodes for loop setup start and end in ZOLSupport
Also make adding the physical register def operand to the instruction optional.
1 parent c608e92 commit 1f9aa29

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

llvm/lib/Target/AIE/AIE2InstrInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,8 @@ AIE2InstrInfo::getZOLSupport() const {
14461446
Result.LoopStartOpcode = AIE2::LoopStart;
14471447
Result.LoopEndOpcode = AIE2::PseudoLoopEnd;
14481448
Result.SetLoopCountOpcode = AIE2::ADD_NC;
1449-
Result.SetAddressOpcode = AIE2::MOVXM_lng_cg;
1449+
Result.SetLoopStartOpcode = AIE2::MOVXM_lng_cg;
1450+
Result.SetLoopEndOpcode = AIE2::MOVXM_lng_cg;
14501451
// We need at 112 bytes distance from the loop setup to the loop end label,
14511452
// which requires 7 bundles of 16 bytes.
14521453
Result.LoopSetupDistance = 7;

llvm/lib/Target/AIE/AIEBaseHardwareLoops.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,17 @@ void AIEBaseHardwareLoops::expandLoopStart(LowOverheadLoop &LoLoop) {
413413
TII->get(LoweringData->SetLoopCountOpcode), LoweringData->LCRegister)
414414
.addReg(Start->getOperand(0).getReg())
415415
.addImm(Start->getOperand(1).getImm());
416-
417-
BuildMI(*MBB, Start, Start->getDebugLoc(),
418-
TII->get(LoweringData->SetAddressOpcode), LoweringData->LSRegister)
419-
.addMBB(LoLoop.LoopEnd->getOperand(1).getMBB());
420-
MachineInstrBuilder MIB;
421-
MIB = BuildMI(*MBB, Start, Start->getDebugLoc(),
422-
TII->get(LoweringData->SetAddressOpcode),
423-
LoweringData->LERegister)
424-
.addSym(LoLoop.LoopEnd->getOperand(0).getMCSymbol());
425-
MachineInstr *MI = MIB.getInstr();
426-
MI->getOperand(1).ChangeToMCSymbol(
427-
LoLoop.LoopEnd->getOperand(0).getMCSymbol());
416+
auto LoopStart = BuildMI(*MBB, Start, Start->getDebugLoc(),
417+
TII->get(LoweringData->SetLoopStartOpcode));
418+
if (LoweringData->LSRegister)
419+
LoopStart.addDef(*LoweringData->LSRegister);
420+
LoopStart.addMBB(LoLoop.LoopEnd->getOperand(1).getMBB());
421+
422+
auto LoopEnd = BuildMI(*MBB, Start, Start->getDebugLoc(),
423+
TII->get(LoweringData->SetLoopEndOpcode));
424+
if (LoweringData->LERegister)
425+
LoopEnd.addDef(*LoweringData->LERegister);
426+
LoopEnd.addSym(LoLoop.LoopEnd->getOperand(0).getMCSymbol());
428427

429428
LoLoop.remove(LoLoop.Start);
430429
}

llvm/lib/Target/AIE/AIEBaseInstrInfo.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,14 @@ bool AIEBaseInstrInfo::isZeroOverheadLoopSetupInstr(
361361
}
362362

363363
return isZOLTripCountDef(MI) ||
364-
(MI.getOpcode() == ZOLSupport->SetAddressOpcode &&
365-
(MI.getOperand(0).getReg() == ZOLSupport->LSRegister ||
366-
MI.getOperand(0).getReg() == ZOLSupport->LERegister));
364+
((MI.getOpcode() == ZOLSupport->SetLoopStartOpcode ||
365+
MI.getOpcode() == ZOLSupport->SetLoopEndOpcode) &&
366+
((!ZOLSupport->LSRegister.has_value() &&
367+
!ZOLSupport->LERegister.has_value()) ||
368+
(ZOLSupport->LSRegister.has_value() &&
369+
MI.getOperand(0).getReg() == *ZOLSupport->LSRegister) ||
370+
(ZOLSupport->LERegister.has_value() &&
371+
MI.getOperand(0).getReg() == *ZOLSupport->LERegister)));
367372
}
368373

369374
void AIEBaseInstrInfo::adjustTripCount(MachineInstr &MI, int Adjustment) const {

llvm/lib/Target/AIE/AIEBaseInstrInfo.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ struct AIEBaseInstrInfo : public TargetInstrInfo {
5252
unsigned SetLoopCountOpcode;
5353
Register LCRegister;
5454

55-
// SetAddress takes an address and writes it to a loop register
56-
unsigned SetAddressOpcode;
57-
Register LSRegister;
58-
Register LERegister;
55+
// SetLoop{Start,End} takes an address and writes it to a loop register
56+
unsigned SetLoopStartOpcode;
57+
unsigned SetLoopEndOpcode;
58+
std::optional<Register> LSRegister;
59+
std::optional<Register> LERegister;
5960
// The distance between setup and the start of the loop, in units
6061
// of bundles.
6162
unsigned LoopSetupDistance;

llvm/lib/Target/AIE/aie2p/AIE2PInstrInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,8 @@ AIE2PInstrInfo::getZOLSupport() const {
17811781
Result.LoopStartOpcode = AIE2P::LoopStart;
17821782
Result.LoopEndOpcode = AIE2P::PseudoLoopEnd;
17831783
Result.SetLoopCountOpcode = AIE2P::ADD_NC_mv_add_ri;
1784-
Result.SetAddressOpcode = AIE2P::MOVXM;
1784+
Result.SetLoopStartOpcode = AIE2P::MOVXM;
1785+
Result.SetLoopEndOpcode = AIE2P::MOVXM;
17851786
// We need at 112 bytes distance from the loop setup to the loop end label,
17861787
// which requires 7 bundles of 16 bytes.
17871788
Result.LoopSetupDistance = 7;

0 commit comments

Comments
 (0)