aboutsummaryrefslogtreecommitdiffstats
path: root/ice40
diff options
context:
space:
mode:
Diffstat (limited to 'ice40')
-rw-r--r--ice40/arch.cc13
-rw-r--r--ice40/arch.h44
-rw-r--r--ice40/arch_pybindings.cc3
-rw-r--r--ice40/arch_pybindings.h12
-rw-r--r--ice40/archdefs.h20
5 files changed, 91 insertions, 1 deletions
diff --git a/ice40/arch.cc b/ice40/arch.cc
index e450e682..6fe77e4b 100644
--- a/ice40/arch.cc
+++ b/ice40/arch.cc
@@ -115,6 +115,19 @@ Arch::Arch(ArchArgs args) : args(args)
wire_to_net.resize(chip_info->wire_data.size());
pip_to_net.resize(chip_info->pip_data.size());
switches_locked.resize(chip_info->num_switches);
+
+ 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/ice40/arch.h b/ice40/arch.h
index fbf26e78..fd92d988 100644
--- a/ice40/arch.h
+++ b/ice40/arch.h
@@ -821,6 +821,47 @@ struct Arch : BaseCtx
// Perform placement validity checks, returning false on failure (all
// implemented in arch_place.cc)
+ // Whether this cell type can be placed at this BEL.
+ 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;
+ }
+
// Whether or not a given cell can be placed at a given Bel
// This is not intended for Bel type checks, but finer-grained constraints
// such as conflicting set/reset signals, etc
@@ -862,6 +903,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;
};
void ice40DelayFuzzerMain(Context *ctx);
diff --git a/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc
index 921956e8..76ce7590 100644
--- a/ice40/arch_pybindings.cc
+++ b/ice40/arch_pybindings.cc
@@ -75,6 +75,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>);
@@ -83,7 +85,6 @@ void arch_wrap_python(py::module &m)
WRAP_RANGE(m, Pip, conv_to_str<PipId>);
WRAP_RANGE(m, BelPin, wrap_context<BelPin>);
-
WRAP_MAP_UPTR(m, CellMap, "IdCellMap");
WRAP_MAP_UPTR(m, NetMap, "IdNetMap");
WRAP_MAP(m, HierarchyMap, wrap_context<HierarchicalCell &>, "HierarchyMap");
diff --git a/ice40/arch_pybindings.h b/ice40/arch_pybindings.h
index cf343976..dd3161ae 100644
--- a/ice40/arch_pybindings.h
+++ b/ice40/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/ice40/archdefs.h b/ice40/archdefs.h
index e95953f1..c0a6ac66 100644
--- a/ice40/archdefs.h
+++ b/ice40/archdefs.h
@@ -170,6 +170,15 @@ struct ArchCellInfo
};
};
+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; }
+};
+
NEXTPNR_NAMESPACE_END
namespace std {
@@ -213,4 +222,15 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX DecalId>
return seed;
}
};
+
+template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelBucketId>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelBucketId &bucket) const noexcept
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX IdString>()(bucket.name));
+ return seed;
+ }
+};
+
} // namespace std