Skip to content

Commit

Permalink
[AIEX] Create dependency between lock instr and fixed instr for SWP p…
Browse files Browse the repository at this point in the history
…rologue merging
  • Loading branch information
niwinanto committed Mar 11, 2025
1 parent f867667 commit 37ecc39
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
17 changes: 15 additions & 2 deletions llvm/lib/Target/AIE/AIEBaseSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,21 @@ class EmitFixedSUnits : public ScheduleDAGMutation {
DAG->getSUnit(&*getBundleStart(FixedDepMI->getIterator()));
assert(FixedDepSU && "Fixed Bundle has no corresponding SU.");
SDep Dep(&FreeSU, SDep::Artificial);
Dep.setLatency(
AIE::maxLatency(&MI, *TII, *ItinData, /*IncludeStages=*/true));
auto Latency =
AIE::maxLatency(&MI, *TII, *ItinData, /*IncludeStages=*/true);
if (TII->isLock(MI.getOpcode())) {
Dep.setLatency(std::max(
TII->getCoreResumeCycleAfterLock() -
*TII->getFirstMemoryCycle(FixedDepMI->getDesc().SchedClass) + 1,
Latency));
} else if (TII->isLock(FixedDepMI->getOpcode())) {
Dep.setLatency(
std::max(*TII->getLastMemoryCycle(MI.getDesc().SchedClass) -
TII->getCoreStallCycleAfterLock() + 1,
Latency));
} else {
Dep.setLatency(Latency);
}
FixedDepSU->addPred(Dep, /*Required=*/true);
}

Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/Target/AIE/AIEMaxLatencyFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ static bool overlap(const MachineOperand &SrcOp, const MachineOperand &DstOp,
/// Check whether Dst depends on Src
static bool depends(const MachineInstr &Src, const MachineInstr &Dst,
const TargetRegisterInfo *TRI) {

const AIEBaseInstrInfo *const TII = static_cast<const AIEBaseInstrInfo *>(
Src.getMF()->getSubtarget().getInstrInfo());
// Detect dependency between lock and ld/st intructions.
if ((TII->isLock(Src.getOpcode()) && (Dst.mayLoadOrStore())) ||
(TII->isLock(Dst.getOpcode()) && (Src.mayLoadOrStore()))) {
return true;
}
// We don't try anything clever in terms of alias analysis
// The memory latency is accounted for by maxLatency() and any
// possible dependence will be corrected for by its scheduled cycle.
Expand Down Expand Up @@ -126,15 +134,14 @@ InstrAndCycle findEarliestRef(const MachineInstr &SrcMI,
ArrayRef<MachineBundle> Bundles, int Prune) {
const TargetRegisterInfo *TRI =
SrcMI.getMF()->getSubtarget().getRegisterInfo();

int Cycle = 0;
for (const auto &Bundle : Bundles) {
if (Cycle >= Prune) {
LLVM_DEBUG(dbgs() << " prune at " << Cycle << "\n");
return {/*MI=*/nullptr, Cycle};
}
for (MachineInstr *DstMI : Bundle.getInstrs()) {
LLVM_DEBUG(dbgs() << " " << *DstMI);
LLVM_DEBUG(dbgs() << " " << *DstMI);
if (depends(SrcMI, *DstMI, TRI)) {
LLVM_DEBUG(dbgs() << " depends in cycle=" << Cycle << "\n");
return {DstMI, Cycle};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,15 @@ body: |
; CHECK-NEXT: successors: %bb.1(0x80000000)
; CHECK-NEXT: liveins: $p0, $p1, $r0, $r18
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: ACQ_mLockId_imm 49, killed renamable $r18
; CHECK-NEXT: NOP
; CHECK-NEXT: $lc = ADD_NC $r0, -7
; CHECK-NEXT: $ls = MOVXM_lng_cg %bb.2
; CHECK-NEXT: $le = MOVXM_lng_cg <mcsymbol .L_LEnd0>
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
; CHECK-NEXT: BUNDLE implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit-def $p0, implicit killed $p0, implicit $m0, implicit killed $r18 {
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
; CHECK-NEXT: ACQ_mLockId_imm 49, killed renamable $r18
; CHECK-NEXT: }
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
; CHECK-NEXT: BUNDLE implicit-def $r1, implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit-def $p0, implicit killed $p0, implicit $m0 {
; CHECK-NEXT: $r1 = MOVA_lda_cg 0
; CHECK-NEXT: $x6, $p0 = VLDB_UNPACK_S16_S8_ag_pstm_nrm killed $p0, $m0
Expand Down

0 comments on commit 37ecc39

Please sign in to comment.