diff options
author | David Shah <dave@ds0.me> | 2021-02-02 16:55:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 16:55:13 +0000 |
commit | d1ef3ae1bac8f108b642c42c4fbfbdd4899c7641 (patch) | |
tree | 3657232a91e97f839cd9114f40aa0c565afc23d4 /ecp5 | |
parent | efc98c517eb1d2eb4a8ecc2ae82e770aaa1a0edd (diff) | |
parent | da74a425d23352d7cddf9d1c4b0b7c86dd567c40 (diff) | |
download | nextpnr-d1ef3ae1bac8f108b642c42c4fbfbdd4899c7641.tar.gz nextpnr-d1ef3ae1bac8f108b642c42c4fbfbdd4899c7641.tar.bz2 nextpnr-d1ef3ae1bac8f108b642c42c4fbfbdd4899c7641.zip |
Merge pull request #557 from litghost/refactor_placer_arch_api
RFC: Initial refactoring of placer API.
Diffstat (limited to 'ecp5')
-rw-r--r-- | ecp5/arch.cc | 13 | ||||
-rw-r--r-- | ecp5/arch.h | 43 | ||||
-rw-r--r-- | ecp5/arch_pybindings.cc | 2 | ||||
-rw-r--r-- | ecp5/arch_pybindings.h | 12 | ||||
-rw-r--r-- | ecp5/archdefs.h | 19 |
5 files changed, 89 insertions, 0 deletions
diff --git a/ecp5/arch.cc b/ecp5/arch.cc index 74a1b17f..25f95c53 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -115,6 +115,19 @@ Arch::Arch(ArchArgs args) : args(args) log_error("Unsupported package '%s' for '%s'.\n", args.package.c_str(), getChipName().c_str()); bel_to_cell.resize(chip_info->height * chip_info->width * max_loc_bels, nullptr); + + std::unordered_set<IdString> bel_types; + for (BelId bel : getBels()) { + bel_types.insert(getBelType(bel)); + } + + for (IdString bel_type : bel_types) { + cell_types.push_back(bel_type); + + BelBucketId bucket; + bucket.name = bel_type; + buckets.push_back(bucket); + } } // ----------------------------------------------------------------------- diff --git a/ecp5/arch.h b/ecp5/arch.h index 58373157..18a70fe8 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -950,6 +950,46 @@ struct Arch : BaseCtx // ------------------------------------------------- // Placement validity checks + bool isValidBelForCellType(IdString cell_type, BelId bel) const { return cell_type == getBelType(bel); } + + const std::vector<IdString> &getCellTypes() const { return cell_types; } + + std::vector<BelBucketId> getBelBuckets() const { return buckets; } + + IdString getBelBucketName(BelBucketId bucket) const { return bucket.name; } + + BelBucketId getBelBucketByName(IdString name) const + { + BelBucketId bucket; + bucket.name = name; + return bucket; + } + + BelBucketId getBelBucketForBel(BelId bel) const + { + BelBucketId bucket; + bucket.name = getBelType(bel); + return bucket; + } + + BelBucketId getBelBucketForCellType(IdString cell_type) const + { + BelBucketId bucket; + bucket.name = cell_type; + return bucket; + } + + std::vector<BelId> getBelsInBucket(BelBucketId bucket) const + { + std::vector<BelId> bels; + for (BelId bel : getBels()) { + if (getBelType(bel) == bucket.name) { + bels.push_back(bel); + } + } + return bels; + } + bool isValidBelForCell(CellInfo *cell, BelId bel) const; bool isBelLocationValid(BelId bel) const; @@ -1022,6 +1062,9 @@ struct Arch : BaseCtx static const std::vector<std::string> availablePlacers; static const std::string defaultRouter; static const std::vector<std::string> availableRouters; + + std::vector<IdString> cell_types; + std::vector<BelBucketId> buckets; }; NEXTPNR_NAMESPACE_END diff --git a/ecp5/arch_pybindings.cc b/ecp5/arch_pybindings.cc index 8618bec1..e1adbb46 100644 --- a/ecp5/arch_pybindings.cc +++ b/ecp5/arch_pybindings.cc @@ -59,6 +59,8 @@ void arch_wrap_python(py::module &m) typedef const PipRange UphillPipRange; typedef const PipRange DownhillPipRange; + typedef const std::vector<BelBucketId> &BelBucketRange; + typedef const std::vector<BelId> &BelRangeForBelBucket; #include "arch_pybindings_shared.h" WRAP_RANGE(m, Bel, conv_to_str<BelId>); diff --git a/ecp5/arch_pybindings.h b/ecp5/arch_pybindings.h index cf343976..dd3161ae 100644 --- a/ecp5/arch_pybindings.h +++ b/ecp5/arch_pybindings.h @@ -76,6 +76,18 @@ template <> struct string_converter<PipId> } }; +template <> struct string_converter<BelBucketId> +{ + BelBucketId from_str(Context *ctx, std::string name) { return ctx->getBelBucketByName(ctx->id(name)); } + + std::string to_str(Context *ctx, BelBucketId id) + { + if (id == BelBucketId()) + throw bad_wrap(); + return ctx->getBelBucketName(id).str(ctx); + } +}; + template <> struct string_converter<BelPin> { BelPin from_str(Context *ctx, std::string name) diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index 586c385f..3bc75ab4 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -126,6 +126,15 @@ struct PipId } }; +struct BelBucketId +{ + IdString name; + + bool operator==(const BelBucketId &other) const { return (name == other.name); } + bool operator!=(const BelBucketId &other) const { return (name != other.name); } + bool operator<(const BelBucketId &other) const { return name < other.name; } +}; + struct GroupId { enum : int8_t @@ -262,4 +271,14 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX DecalId> } }; +template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelBucketId> +{ + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelBucketId &partition) const noexcept + { + std::size_t seed = 0; + boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX IdString>()(partition.name)); + return seed; + } +}; + } // namespace std |