Skip to content

Commit c55211a

Browse files
author
Martien de Jong
committed
[AIE] Improved format availability check
1 parent dbb220a commit c55211a

File tree

9 files changed

+67
-3
lines changed

9 files changed

+67
-3
lines changed

llvm/lib/Target/AIE/AIEBundle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ template <class I> class Bundle {
9898
if (OccupiedSlots & ConflictBits) {
9999
return false;
100100
}
101-
SlotBits NewSlots = OccupiedSlots | SlotInfo->getSlotSet();
102-
return FormatInterface->getPacketFormats().getFormat(NewSlots);
101+
const SlotBits NewSlots = OccupiedSlots | SlotInfo->getSlotSet();
102+
return FormatInterface->isFormatAvailable(NewSlots);
103103
}
104104

105105
/// Add an instruction to the bundle

llvm/lib/Target/AIE/AIEHazardRecognizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool FuncUnitWrapper::conflict(const FuncUnitWrapper &Other) const {
139139
// This allows representing a blocked cycle (Slots = ~0) without knowing
140140
// the slot and format details.
141141
return Slots && Other.Slots &&
142-
!FormatInterface->getPacketFormats().getFormat(Slots | Other.Slots);
142+
!FormatInterface->isFormatAvailable(Slots | Other.Slots);
143143
}
144144

145145
namespace {

llvm/lib/Target/AIE/MCTargetDesc/AIE2MCFormats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const MCFormatDesc *AIE2MCFormats::getMCFormats() const {
3535

3636
const PacketFormats &AIE2MCFormats::getPacketFormats() const { return Formats; }
3737

38+
ArrayRef<bool> AIE2MCFormats::getIsFormatAvailable() const {
39+
return FormatAvailable;
40+
}
41+
3842
SmallVector<MCSlotKind, 2> AIE2MCFormats::getLoadSlotKinds() const {
3943
return {MCSlotKind::AIE2_SLOT_LDB, MCSlotKind::AIE2_SLOT_LDA};
4044
}

llvm/lib/Target/AIE/MCTargetDesc/AIEBaseMCFormats.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ bool AIEBaseMCFormats::isSupportedInstruction(unsigned int Opcode) const {
5858
return getFormatDescIndex(Opcode) ? true : false;
5959
}
6060

61+
bool AIEBaseMCFormats::isFormatAvailable(uint64_t SlotSet) const {
62+
ArrayRef<bool> IsFormatsAvailable = getIsFormatAvailable();
63+
return SlotSet < IsFormatsAvailable.size() && IsFormatsAvailable[SlotSet];
64+
}
65+
6166
const MCSlotKind AIEBaseMCFormats::getSlotKind(unsigned int Opcode) const {
6267
// First, we check that the instruction has a format defined.
6368
// Some KILLs instructions are still in the pipeline for example...

llvm/lib/Target/AIE/MCTargetDesc/AIEMCFormats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ const MCFormatDesc *AIEMCFormats::getMCFormats() const { return AIE::Formats; }
6262

6363
const PacketFormats &AIEMCFormats::getPacketFormats() const { return Formats; }
6464

65+
ArrayRef<bool> AIEMCFormats::getIsFormatAvailable() const {
66+
return FormatAvailable;
67+
}
68+
6569
} // end namespace llvm

llvm/lib/Target/AIE/MCTargetDesc/AIEMCFormats.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,15 @@ class AIEBaseMCFormats {
393393

394394
virtual const PacketFormats &getPacketFormats() const = 0;
395395

396+
virtual ArrayRef<bool> getIsFormatAvailable() const = 0;
397+
396398
// \return all Slots that correspond to the load instructions
397399
virtual SmallVector<MCSlotKind, 2> getLoadSlotKinds() const {
398400
llvm_unreachable("Target didn't implement getLoadSlotKinds()");
399401
}
400402

403+
bool isFormatAvailable(uint64_t SlotSet) const;
404+
401405
protected:
402406
/// Check if the Instruction is indeed into the Tables.
403407
void checkInstructionIsSupported(unsigned int Opcode) const;
@@ -411,6 +415,7 @@ class AIEMCFormats : public AIEBaseMCFormats {
411415
getFormatDescIndex(unsigned int Opcode) const override;
412416
const MCSlotInfo *getSlotInfo(const MCSlotKind Kind) const override;
413417
const MCFormatDesc *getMCFormats() const override;
418+
ArrayRef<bool> getIsFormatAvailable() const override;
414419
const PacketFormats &getPacketFormats() const override;
415420
};
416421

@@ -423,6 +428,7 @@ class AIE2MCFormats : public AIEBaseMCFormats {
423428
const MCSlotInfo *getSlotInfo(const MCSlotKind Kind) const override;
424429
const MCFormatDesc *getMCFormats() const override;
425430
const PacketFormats &getPacketFormats() const override;
431+
ArrayRef<bool> getIsFormatAvailable() const override;
426432
SmallVector<MCSlotKind, 2> getLoadSlotKinds() const override;
427433
};
428434

@@ -435,6 +441,7 @@ class AIE2PMCFormats : public AIEBaseMCFormats {
435441
const MCSlotInfo *getSlotInfo(const MCSlotKind Kind) const override;
436442
const MCFormatDesc *getMCFormats() const override;
437443
const PacketFormats &getPacketFormats() const override;
444+
ArrayRef<bool> getIsFormatAvailable() const override;
438445
SmallVector<MCSlotKind, 2> getLoadSlotKinds() const override;
439446
};
440447

llvm/lib/Target/AIE/MCTargetDesc/aie2p/AIE2PMCFormats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const PacketFormats &AIE2PMCFormats::getPacketFormats() const {
3737
return Formats;
3838
}
3939

40+
ArrayRef<bool> AIE2PMCFormats::getIsFormatAvailable() const {
41+
return FormatAvailable;
42+
}
43+
4044
SmallVector<MCSlotKind, 2> AIE2PMCFormats::getLoadSlotKinds() const {
4145
return {MCSlotKind::AIE2P_SLOT_LDB, MCSlotKind::AIE2P_SLOT_LDA};
4246
}

llvm/unittests/Target/AIE/BundleTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class MockMCFormats : public AIEBaseMCFormats {
9999
const MCFormatDesc *getMCFormats() const override {
100100
llvm_unreachable("Un-implemented");
101101
}
102+
ArrayRef<bool> getIsFormatAvailable() const override {
103+
llvm_unreachable("Un-implemented");
104+
}
102105
};
103106

104107
class MockTII : public AIEInstrInfo {

llvm/utils/TableGen/CodeGenFormat.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,43 @@ void CodeGenFormat::run(raw_ostream &o) {
240240
o << SlotData << FormatData
241241
<< "static const PacketFormats Formats {FormatData};\n\n";
242242

243+
// Create an O(1) function of available formats by ticking them in
244+
// a lookup table;
245+
uint64_t MaxSlotSet = 0;
246+
for (const TGInstrLayout *Packet : Packets) {
247+
MaxSlotSet = std::max(MaxSlotSet, Packet->getSlotSet());
248+
}
249+
const size_t Size = MaxSlotSet + 1;
250+
// Catering for 16 slots for now, just to check the logic.
251+
assert(Size <= 65536);
252+
std::vector<bool> LUT(Size, false);
253+
// First the trivial ones, without nops.
254+
for (const TGInstrLayout *Packet : Packets) {
255+
LUT[Packet->getSlotSet()] = true;
256+
}
257+
// Then the remaining ones
258+
for (uint64_t SlotSet = 0; SlotSet < Size; SlotSet++) {
259+
if (LUT[SlotSet]) {
260+
continue;
261+
}
262+
// We start with the largest packets, since they cover more.
263+
for (const TGInstrLayout *Packet : reverse(Packets)) {
264+
// If the packet clears all bits of SlotSet, it can hold all these
265+
// slots. Slots that are not present in SlotSet can be filled
266+
// with nops.
267+
if ((SlotSet & ~Packet->getSlotSet()) == 0) {
268+
LUT[SlotSet] = true;
269+
break;
270+
}
271+
}
272+
}
273+
o << "const size_t SlotSetSize = " << Size << ";\n";
274+
o << "static const bool FormatAvailable[SlotSetSize] = {\n";
275+
for (size_t Index = 0; Index < Size; Index++) {
276+
o << "\t/* " << Index << " */ " << LUT[Index] << ",\n";
277+
}
278+
o << "};\n";
279+
243280
o << "#endif // GET_FORMATS_PACKETS_TABLE\n\n";
244281
}
245282
}

0 commit comments

Comments
 (0)