Skip to content

Commit

Permalink
[AIEX] Add mechanism to release resources from Scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnamtibrewala committed Oct 9, 2024
1 parent 34acf77 commit 74fa8be
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
62 changes: 62 additions & 0 deletions llvm/lib/Target/AIE/AIEHazardRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ FuncUnitWrapper &FuncUnitWrapper::operator|=(const FuncUnitWrapper &Other) {
return *this;
}

FuncUnitWrapper &FuncUnitWrapper::operator^=(const FuncUnitWrapper &Other) {
// XOR operation with the same FuncUnitWrapper will release resources.
Required ^= Other.Required;
Reserved ^= Other.Reserved;
Slots ^= Other.Slots;
MemoryBanks ^= Other.MemoryBanks;
return *this;
}

bool FuncUnitWrapper::conflict(const FuncUnitWrapper &Other) const {
if ((Required & Other.Required) != 0 || (Slots & Other.Slots) != 0 ||
(MemoryBanks & Other.MemoryBanks) != 0 ||
Expand Down Expand Up @@ -598,6 +607,18 @@ void AIEHazardRecognizer::emitInScoreboard(
TII->getMemoryCycles(SchedClass), DeltaCycles, FUDepthLimit);
}

void AIEHazardRecognizer::releaseFromScoreboard(
ResourceScoreboard<FuncUnitWrapper> &TheScoreboard, const MCInstrDesc &Desc,
MemoryBankBits MemoryBanks,
iterator_range<const MachineOperand *> MIOperands,
const MachineRegisterInfo &MRI, int DeltaCycles) const {
const unsigned SchedClass = TII->getSchedClass(Desc, MIOperands, MRI);
const SlotBits SlotSet =
getSlotSet(Desc, *TII->getFormatInterface(), IgnoreUnknownSlotSets);
releaseResources(TheScoreboard, ItinData, SchedClass, SlotSet, MemoryBanks,
TII->getMemoryCycles(SchedClass), DeltaCycles, FUDepthLimit);
}

void AIEHazardRecognizer::enterResources(
ResourceScoreboard<FuncUnitWrapper> &Scoreboard,
const InstrItineraryData *ItinData, unsigned SchedClass, SlotBits SlotSet,
Expand Down Expand Up @@ -639,6 +660,47 @@ void AIEHazardRecognizer::enterResources(
});
}

void AIEHazardRecognizer::releaseResources(
ResourceScoreboard<FuncUnitWrapper> &Scoreboard,
const InstrItineraryData *ItinData, unsigned SchedClass, SlotBits SlotSet,
MemoryBankBits MemoryBanks, SmallVector<int, 2> MemoryAccessCycles,
int DeltaCycles, std::optional<int> FUDepthLimit) {
assert(Scoreboard.isValidDelta(DeltaCycles));

// Remove slot usage
FuncUnitWrapper EmissionCycle(/*Req=*/0, /*Res=*/0, SlotSet);
Scoreboard[DeltaCycles] ^= EmissionCycle;

// Remove memory bank usage
if (!MemoryAccessCycles.empty()) {
FuncUnitWrapper MemoryBankAccessCycle(/*Req=*/0, /*Res=*/0, /*SlotSet=*/0,
MemoryBanks);
for (auto Cycles : MemoryAccessCycles) {
Scoreboard[DeltaCycles + Cycles - 1] ^= MemoryBankAccessCycle;
}
}

int Cycle = DeltaCycles;
Scoreboard[Cycle].IssueCount--;
for (const InstrStage &IS : ItinData->getStages(SchedClass)) {
if (FUDepthLimit && (Cycle - DeltaCycles) >= *FUDepthLimit) {
break;
}
const FuncUnitWrapper ThisCycle(IS);
for (unsigned int C = 0; C < IS.getCycles(); ++C) {
Scoreboard[Cycle + C] ^= ThisCycle;
}

// Advance the cycle to the next stage.
Cycle += IS.getNextCycles();
}

LLVM_DEBUG({
dbgs() << "Scoreboard after release resources:\n";
Scoreboard.dump();
});
}

unsigned AIEHazardRecognizer::getPipelineDepth() const { return PipelineDepth; }

unsigned AIEHazardRecognizer::getMaxLatency() const { return MaxLatency; }
Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/Target/AIE/AIEHazardRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class FuncUnitWrapper {
void dump() const;

FuncUnitWrapper &operator|=(const FuncUnitWrapper &Other);
FuncUnitWrapper &operator^=(const FuncUnitWrapper &Other);
bool conflict(const FuncUnitWrapper &Other) const;
};

Expand Down Expand Up @@ -152,6 +153,13 @@ class AIEHazardRecognizer : public ScheduleHazardRecognizer {
iterator_range<const MachineOperand *> MIOperands,
const MachineRegisterInfo &MRI, int DeltaCycles);

void releaseFromScoreboard(ResourceScoreboard<FuncUnitWrapper> &Scoreboard,
const MCInstrDesc &Desc,
MemoryBankBits MemoryBanks,
iterator_range<const MachineOperand *> MIOperands,
const MachineRegisterInfo &MRI,
int DeltaCycles) const;

/// Block all scoreboard resources at DeltaCycles
void blockCycleInScoreboard(int DeltaCycle);

Expand Down Expand Up @@ -233,6 +241,14 @@ class AIEHazardRecognizer : public ScheduleHazardRecognizer {
SmallVector<int, 2> MemoryAccessCycles,
int DeltaCycles, std::optional<int> FUDepthLimit);

static void releaseResources(ResourceScoreboard<FuncUnitWrapper> &Scoreboard,
const InstrItineraryData *ItinData,
unsigned SchedClass, SlotBits SlotSet,
MemoryBankBits MemoryBanks,
SmallVector<int, 2> MemoryAccessCycles,
int DeltaCycles,
std::optional<int> FUDepthLimit);

private:
ResourceScoreboard<FuncUnitWrapper> Scoreboard;
const AIEBaseInstrInfo *TII;
Expand Down

0 comments on commit 74fa8be

Please sign in to comment.