nextpnr: Use templates to specify range types

Signed-off-by: D. Shah <dave@ds0.me>
This commit is contained in:
D. Shah 2021-02-03 12:10:53 +00:00
parent 8f76af40db
commit cfa9a9daec
2 changed files with 67 additions and 18 deletions

View File

@ -1006,7 +1006,10 @@ struct BaseCtx
void archInfoToAttributes(); void archInfoToAttributes();
void attributesToArchInfo(); void attributesToArchInfo();
};
template <typename R> struct ArchBase : BaseCtx
{
// -------------------------------------------------------------- // --------------------------------------------------------------
// Arch API base // Arch API base
@ -1018,6 +1021,7 @@ struct BaseCtx
virtual char getNameDelimiter() const { return ' '; } virtual char getNameDelimiter() const { return ' '; }
// Bel methods // Bel methods
virtual typename R::AllBelsRange getBels() const = 0;
virtual BelId getBelByName(IdStringList name) const = 0; virtual BelId getBelByName(IdStringList name) const = 0;
virtual IdStringList getBelName(BelId bel) const = 0; virtual IdStringList getBelName(BelId bel) const = 0;
virtual uint32_t getBelChecksum(BelId bel) const { return uint32_t(std::hash<BelId>()(bel)); } virtual uint32_t getBelChecksum(BelId bel) const { return uint32_t(std::hash<BelId>()(bel)); }
@ -1025,19 +1029,26 @@ struct BaseCtx
virtual void unbindBel(BelId bel) = 0; virtual void unbindBel(BelId bel) = 0;
virtual Loc getBelLocation(BelId bel) const = 0; virtual Loc getBelLocation(BelId bel) const = 0;
virtual BelId getBelByLocation(Loc loc) const = 0; virtual BelId getBelByLocation(Loc loc) const = 0;
virtual typename R::TileBelsRange getBelsByTile(int x, int y) const = 0;
virtual bool getBelGlobalBuf(BelId bel) const { return false; } virtual bool getBelGlobalBuf(BelId bel) const { return false; }
virtual bool checkBelAvail(BelId bel) const = 0; virtual bool checkBelAvail(BelId bel) const = 0;
virtual CellInfo *getBoundBelCell(BelId bel) const = 0; virtual CellInfo *getBoundBelCell(BelId bel) const = 0;
virtual CellInfo *getConflictingBelCell(BelId bel) const = 0; virtual CellInfo *getConflictingBelCell(BelId bel) const = 0;
virtual IdString getBelType(BelId bel) const = 0; virtual IdString getBelType(BelId bel) const = 0;
virtual typename R::BelAttrsRange getBelAttrs(BelId bel) const = 0;
virtual WireId getBelPinWire(BelId bel, IdString pin) const = 0; virtual WireId getBelPinWire(BelId bel, IdString pin) const = 0;
virtual PortType getBelPinType(BelId bel, IdString pin) const = 0; virtual PortType getBelPinType(BelId bel, IdString pin) const = 0;
// Wire methods // Wire methods
virtual typename R::AllWiresRange getWires() const = 0;
virtual WireId getWireByName(IdStringList name) const = 0; virtual WireId getWireByName(IdStringList name) const = 0;
virtual IdStringList getWireName(WireId wire) const = 0; virtual IdStringList getWireName(WireId wire) const = 0;
virtual IdString getWireType(WireId wire) const { return IdString(); } virtual IdString getWireType(WireId wire) const { return IdString(); }
virtual typename R::WireAttrsRange getWireAttrs(WireId) const = 0;
virtual uint32_t getWireChecksum(WireId wire) const { return uint32_t(std::hash<WireId>()(wire)); } virtual uint32_t getWireChecksum(WireId wire) const { return uint32_t(std::hash<WireId>()(wire)); }
virtual typename R::DownhillPipRange getPipsDownhill(WireId wire) const = 0;
virtual typename R::UphillPipRange getPipsUphill(WireId wire) const = 0;
virtual typename R::WireBelPinRange getWireBelPins(WireId wire) const = 0;
virtual void bindWire(WireId wire, NetInfo *net, PlaceStrength strength) = 0; virtual void bindWire(WireId wire, NetInfo *net, PlaceStrength strength) = 0;
virtual void unbindWire(WireId wire) = 0; virtual void unbindWire(WireId wire) = 0;
virtual bool checkWireAvail(WireId wire) const = 0; virtual bool checkWireAvail(WireId wire) const = 0;
@ -1047,9 +1058,11 @@ struct BaseCtx
virtual DelayInfo getWireDelay(WireId wire) const = 0; virtual DelayInfo getWireDelay(WireId wire) const = 0;
// Pip methods // Pip methods
virtual typename R::AllPipsRange getPips() const = 0;
virtual PipId getPipByName(IdStringList name) const = 0; virtual PipId getPipByName(IdStringList name) const = 0;
virtual IdStringList getPipName(PipId pip) const = 0; virtual IdStringList getPipName(PipId pip) const = 0;
virtual IdString getPipType(PipId pip) const { return IdString(); } virtual IdString getPipType(PipId pip) const { return IdString(); }
virtual typename R::PipAttrsRange getPipAttrs(PipId) const = 0;
virtual uint32_t getPipChecksum(PipId pip) const { return uint32_t(std::hash<PipId>()(pip)); } virtual uint32_t getPipChecksum(PipId pip) const { return uint32_t(std::hash<PipId>()(pip)); }
virtual void bindPip(PipId pip, NetInfo *net, PlaceStrength strength) = 0; virtual void bindPip(PipId pip, NetInfo *net, PlaceStrength strength) = 0;
virtual void unbindPip(PipId pip) = 0; virtual void unbindPip(PipId pip) = 0;
@ -1067,6 +1080,11 @@ struct BaseCtx
virtual IdStringList getGroupName(GroupId group) const = 0; virtual IdStringList getGroupName(GroupId group) const = 0;
virtual delay_t estimateDelay(WireId src, WireId dst) const = 0; virtual delay_t estimateDelay(WireId src, WireId dst) const = 0;
virtual ArcBounds getRouteBoundingBox(WireId src, WireId dst) const = 0; virtual ArcBounds getRouteBoundingBox(WireId src, WireId dst) const = 0;
virtual typename R::AllGroupsRange getGroups() const = 0;
virtual typename R::GroupBelsRange getGroupBels(GroupId group) const = 0;
virtual typename R::GroupWiresRange getGroupWires(GroupId group) const = 0;
virtual typename R::GroupPipsRange getGroupPips(GroupId group) const = 0;
virtual typename R::GroupGroupsRange getGroupGroups(GroupId group) const = 0;
// Delay methods // Delay methods
virtual delay_t predictDelay(const NetInfo *net_info, const PortRef &sink) const = 0; virtual delay_t predictDelay(const NetInfo *net_info, const PortRef &sink) const = 0;
@ -1108,6 +1126,9 @@ struct BaseCtx
virtual BelBucketId getBelBucketForCellType(IdString cell_type) const = 0; virtual BelBucketId getBelBucketForCellType(IdString cell_type) const = 0;
virtual bool isValidBelForCell(CellInfo *cell, BelId bel) const { return true; } virtual bool isValidBelForCell(CellInfo *cell, BelId bel) const { return true; }
virtual bool isBelLocationValid(BelId bel) const { return true; } virtual bool isBelLocationValid(BelId bel) const { return true; }
virtual typename R::CellTypeRange getCellTypes() const = 0;
virtual typename R::BelBucketRange getBelBuckets() const = 0;
virtual typename R::BucketBelRange getBelsInBucket(BelBucketId bucket) const = 0;
// Flow methods // Flow methods
virtual bool pack() = 0; virtual bool pack() = 0;

View File

@ -435,7 +435,35 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX DelayKey>
} // namespace std } // namespace std
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
struct Arch : BaseCtx struct ArchRanges
{
// Bels
using AllBelsRange = BelRange;
using TileBelsRange = BelRange;
using BelAttrsRange = std::vector<std::pair<IdString, std::string>>;
using BelPinsRange = std::vector<IdString>;
// Wires
using AllWiresRange = WireRange;
using DownhillPipRange = PipRange;
using UphillPipRange = PipRange;
using WireBelPinRange = BelPinRange;
using WireAttrsRange = std::vector<std::pair<IdString, std::string>>;
// Pips
using AllPipsRange = AllPipRange;
using PipAttrsRange = std::vector<std::pair<IdString, std::string>>;
// Groups
using AllGroupsRange = std::vector<GroupId>;
using GroupBelsRange = std::vector<BelId>;
using GroupWiresRange = std::vector<WireId>;
using GroupPipsRange = std::vector<PipId>;
using GroupGroupsRange = std::vector<GroupId>;
// Placement validity
using CellTypeRange = const std::vector<IdString> &;
using BelBucketRange = std::vector<BelBucketId>;
using BucketBelRange = std::vector<BelId>;
};
struct Arch : ArchBase<ArchRanges>
{ {
const ChipInfoPOD *chip_info; const ChipInfoPOD *chip_info;
const PackageInfoPOD *package_info; const PackageInfoPOD *package_info;
@ -532,7 +560,7 @@ struct Arch : BaseCtx
} }
BelId getBelByLocation(Loc loc) const override; BelId getBelByLocation(Loc loc) const override;
BelRange getBelsByTile(int x, int y) const; BelRange getBelsByTile(int x, int y) const override;
bool getBelGlobalBuf(BelId bel) const override { return getBelType(bel) == id_DCCA; } bool getBelGlobalBuf(BelId bel) const override { return getBelType(bel) == id_DCCA; }
@ -554,7 +582,7 @@ struct Arch : BaseCtx
return bel_to_cell[get_bel_flat_index(bel)]; return bel_to_cell[get_bel_flat_index(bel)];
} }
BelRange getBels() const BelRange getBels() const override
{ {
BelRange range; BelRange range;
range.b.cursor_tile = 0; range.b.cursor_tile = 0;
@ -575,7 +603,7 @@ struct Arch : BaseCtx
return id; return id;
} }
std::vector<std::pair<IdString, std::string>> getBelAttrs(BelId) const std::vector<std::pair<IdString, std::string>> getBelAttrs(BelId) const override
{ {
std::vector<std::pair<IdString, std::string>> ret; std::vector<std::pair<IdString, std::string>> ret;
return ret; return ret;
@ -583,7 +611,7 @@ struct Arch : BaseCtx
WireId getBelPinWire(BelId bel, IdString pin) const override; WireId getBelPinWire(BelId bel, IdString pin) const override;
BelPinRange getWireBelPins(WireId wire) const BelPinRange getWireBelPins(WireId wire) const override
{ {
BelPinRange range; BelPinRange range;
NPNR_ASSERT(wire != WireId()); NPNR_ASSERT(wire != WireId());
@ -616,7 +644,7 @@ struct Arch : BaseCtx
return id; return id;
} }
std::vector<std::pair<IdString, std::string>> getWireAttrs(WireId) const; std::vector<std::pair<IdString, std::string>> getWireAttrs(WireId) const override;
uint32_t getWireChecksum(WireId wire) const override { return wire.index; } uint32_t getWireChecksum(WireId wire) const override { return wire.index; }
@ -673,7 +701,7 @@ struct Arch : BaseCtx
return delay; return delay;
} }
WireRange getWires() const WireRange getWires() const override
{ {
WireRange range; WireRange range;
range.b.cursor_tile = 0; range.b.cursor_tile = 0;
@ -771,7 +799,7 @@ struct Arch : BaseCtx
return pip_to_net.at(pip); return pip_to_net.at(pip);
} }
AllPipRange getPips() const AllPipRange getPips() const override
{ {
AllPipRange range; AllPipRange range;
range.b.cursor_tile = 0; range.b.cursor_tile = 0;
@ -819,7 +847,7 @@ struct Arch : BaseCtx
return delay; return delay;
} }
PipRange getPipsDownhill(WireId wire) const PipRange getPipsDownhill(WireId wire) const override
{ {
PipRange range; PipRange range;
NPNR_ASSERT(wire != WireId()); NPNR_ASSERT(wire != WireId());
@ -830,7 +858,7 @@ struct Arch : BaseCtx
return range; return range;
} }
PipRange getPipsUphill(WireId wire) const PipRange getPipsUphill(WireId wire) const override
{ {
PipRange range; PipRange range;
NPNR_ASSERT(wire != WireId()); NPNR_ASSERT(wire != WireId());
@ -880,11 +908,11 @@ struct Arch : BaseCtx
GroupId getGroupByName(IdStringList name) const override; GroupId getGroupByName(IdStringList name) const override;
IdStringList getGroupName(GroupId group) const override; IdStringList getGroupName(GroupId group) const override;
std::vector<GroupId> getGroups() const; std::vector<GroupId> getGroups() const override;
std::vector<BelId> getGroupBels(GroupId group) const; std::vector<BelId> getGroupBels(GroupId group) const override;
std::vector<WireId> getGroupWires(GroupId group) const; std::vector<WireId> getGroupWires(GroupId group) const override;
std::vector<PipId> getGroupPips(GroupId group) const; std::vector<PipId> getGroupPips(GroupId group) const override;
std::vector<GroupId> getGroupGroups(GroupId group) const; std::vector<GroupId> getGroupGroups(GroupId group) const override;
// ------------------------------------------------- // -------------------------------------------------
@ -938,9 +966,9 @@ struct Arch : BaseCtx
// ------------------------------------------------- // -------------------------------------------------
// Placement validity checks // Placement validity checks
const std::vector<IdString> &getCellTypes() const { return cell_types; } const std::vector<IdString> &getCellTypes() const override { return cell_types; }
std::vector<BelBucketId> getBelBuckets() const { return buckets; } std::vector<BelBucketId> getBelBuckets() const override { return buckets; }
IdString getBelBucketName(BelBucketId bucket) const override { return bucket.name; } IdString getBelBucketName(BelBucketId bucket) const override { return bucket.name; }
@ -965,7 +993,7 @@ struct Arch : BaseCtx
return bucket; return bucket;
} }
std::vector<BelId> getBelsInBucket(BelBucketId bucket) const std::vector<BelId> getBelsInBucket(BelBucketId bucket) const override
{ {
std::vector<BelId> bels; std::vector<BelId> bels;
for (BelId bel : getBels()) { for (BelId bel : getBels()) {