19#ifndef BACKENDS_TOFINO_BF_P4C_PHV_PHV_SPEC_H_
20#define BACKENDS_TOFINO_BF_P4C_PHV_PHV_SPEC_H_
25#include "bf-p4c/phv/phv.h"
26#include "lib/bitvec.h"
28#include "lib/ordered_map.h"
46 enum ArchBlockType_t { PARSER, MAU, DEPARSER };
60 using AddressSpec = std::map<PHV::Type, RangeSpec>;
64 mutable bitvec physical_containers_i;
65 mutable std::map<PHV::Size, std::vector<bitvec>> mau_groups_i;
66 mutable bitvec ingress_only_containers_i;
67 mutable bitvec egress_only_containers_i;
68 mutable std::vector<bitvec> tagalong_collections_i;
69 mutable bitvec individually_assigned_containers_i;
80 std::map<PHV::Size, std::set<PHV::Type>> sizeToTypeMap;
86 std::map<PHV::Type, unsigned> types;
89 explicit MauGroupType(
unsigned n, std::map<PHV::Type, unsigned> t)
90 : numGroups(n), types(t) {}
96 void addType(
PHV::Type t,
unsigned n) { types.emplace(t, n); }
113 std::map<PHV::Size, std::vector<unsigned>> ingressOnlyMauGroupIds;
115 std::map<PHV::Size, std::vector<unsigned>> egressOnlyMauGroupIds;
117 std::map<PHV::Type, unsigned> tagalongCollectionSpec;
119 unsigned numTagalongCollections = 0;
121 std::map<PHV::Type, unsigned> deparserGroupSize;
123 std::map<PHV::Type, std::pair<unsigned, unsigned>> deparserGroupSpec;
125 unsigned numPovBits = 0;
135 const std::map<PHV::Size, unsigned> &numContainersPerGroup)
const;
151 const std::map<PHV::Size, std::set<PHV::Type>>
groupsToTypes()
const;
239 const std::map<
PHV::Size, std::vector<unsigned>> &gressOnlyMauGroupIds)
const;
251 const std::map<PHV::Size, std::vector<bitvec>> &
mauGroups()
const;
271 const std::map<PHV::Type, unsigned> getTagalongCollectionSpec()
const {
272 return tagalongCollectionSpec;
275 unsigned getNumTagalongCollections()
const {
return numTagalongCollections; }
297 virtual unsigned physicalAddress(
unsigned container_id, ArchBlockType_t interface)
const = 0;
309 ArchBlockType_t interface)
const;
312 void applyGlobalPragmas(
const std::vector<const IR::Annotation *> &global_pragmas)
const;
341 unsigned physicalAddress(
unsigned container_id, ArchBlockType_t )
const override;
346 return _physicalAddresses;
350 static AddressSpec _physicalAddresses;
379 unsigned physicalAddress(
unsigned container_id, ArchBlockType_t interface)
const override;
385 return _physicalMauAddresses;
386 case PhvSpec::PARSER:
387 return _physicalParserAddresses;
388 case PhvSpec::DEPARSER:
389 return _physicalDeparserAddresses;
391 BUG(
"Invalid interface");
396 static AddressSpec _physicalMauAddresses;
397 static AddressSpec _physicalParserAddresses;
398 static AddressSpec _physicalDeparserAddresses;
Definition phv_spec.h:353
AddressSpec & physicalAddressSpec(ArchBlockType_t interface) const override
Definition phv_spec.h:382
bitvec parserGroup(unsigned id) const override
Definition phv_spec.cpp:593
unsigned physicalAddress(unsigned container_id, ArchBlockType_t interface) const override
Definition phv_spec.cpp:686
bitvec parserExtractGroup(unsigned id) const override
Definition phv_spec.cpp:606
unsigned parserGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:608
unsigned mauGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:638
bool hasParserExtractGroups() const override
Definition phv_spec.cpp:604
unsigned deparserGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:677
const bitvec & individuallyAssignedContainers() const override
Definition phv_spec.cpp:682
Definition ordered_map.h:32
bitvec tagalongCollection(unsigned container_id) const
Definition phv_spec.cpp:266
void addType(PHV::Type t)
Definition phv_spec.cpp:31
virtual unsigned physicalAddress(unsigned container_id, ArchBlockType_t interface) const =0
const std::vector< PHV::Type > & containerTypes() const
Definition phv_spec.cpp:39
unsigned getNumPovBits() const
Definition phv_spec.h:285
std::set< PHV::Size > definedSizes
All sizes of containers supported by the device.
Definition phv_spec.h:74
virtual bitvec parserExtractGroup(unsigned id) const =0
const bitvec & physicalContainers() const
Definition phv_spec.cpp:150
bitvec deparserGroup(unsigned id) const
Definition phv_spec.cpp:301
std::map< PHV::Size, MauGroupType > mauGroupSpec
Definition phv_spec.h:107
PHV::Type idToContainerType(unsigned id) const
Definition phv_spec.cpp:53
void applyGlobalPragmas(const std::vector< const IR::Annotation * > &global_pragmas) const
apply global pragmas to cached info about available PHV containers
Definition phv_spec.cpp:717
bitvec filterContainerSet(const bitvec &set, PHV::Kind kind) const
Filters a set of containers for a single container kind or type.
Definition phv_spec.cpp:75
virtual const bitvec & individuallyAssignedContainers() const =0
unsigned getTagalongCollectionId(PHV::Container c) const
Definition phv_spec.cpp:239
unsigned containerTypeToId(PHV::Type type) const
Definition phv_spec.cpp:58
virtual bitvec parserGroup(unsigned id) const =0
const std::pair< int, int > deparserGroupNumAndSize(const PHV::Type t) const
Definition phv_spec.cpp:296
const std::set< PHV::Size > & containerSizes() const
Definition phv_spec.cpp:41
virtual AddressSpec & physicalAddressSpec(ArchBlockType_t interface) const =0
bitvec ingressOrEgressOnlyContainers(const std::map< PHV::Size, std::vector< unsigned > > &gressOnlyMauGroupIds) const
Definition phv_spec.cpp:211
unsigned getContainersPerGroup(const std::map< PHV::Size, unsigned > &numContainersPerGroup) const
Return the number of containers in an MAU group.
Definition phv_spec.cpp:325
std::set< PHV::Kind > definedKinds
All kinds of containers supported by the device.
Definition phv_spec.h:76
unsigned numContainersInGroup() const
Definition phv_spec.h:159
const std::map< PHV::Size, std::vector< bitvec > > & mauGroups() const
Definition phv_spec.cpp:179
const std::vector< bitvec > & tagalongCollections() const
Definition phv_spec.cpp:248
const std::pair< int, int > mauGroupNumAndSize(const PHV::Type t) const
Definition phv_spec.cpp:285
const std::map< PHV::Size, std::set< PHV::Type > > groupsToTypes() const
Definition phv_spec.cpp:47
virtual unsigned mauGroupId(const PHV::Container &c) const =0
const std::set< PHV::Kind > & containerKinds() const
Definition phv_spec.cpp:43
bitvec range(PHV::Type t, unsigned start, unsigned length) const
Definition phv_spec.cpp:143
unsigned containerToId(PHV::Container container) const
Definition phv_spec.cpp:70
virtual unsigned deparserGroupId(const PHV::Container &c) const =0
unsigned numContainerTypes() const
Definition phv_spec.cpp:51
virtual unsigned parserGroupId(const PHV::Container &c) const =0
bool hasContainerKind(PHV::Kind kind) const
Determines whether the device has the given kind of PHV container.
Definition phv_spec.cpp:45
std::optional< PHV::Container > physicalAddressToContainer(unsigned address, ArchBlockType_t interface) const
Definition phv_spec.cpp:345
const bitvec & egressOnly() const
Definition phv_spec.cpp:233
PHV::Container idToContainer(unsigned id) const
Definition phv_spec.cpp:60
cstring containerSetToString(const bitvec &set) const
Definition phv_spec.cpp:99
virtual bool hasParserExtractGroups() const =0
bitvec mauGroup(unsigned container_id) const
Definition phv_spec.cpp:160
std::vector< PHV::Type > definedTypes
All types of containers supported by the device.
Definition phv_spec.h:72
unsigned containersPerGroup
Definition phv_spec.h:111
const bitvec & ingressOnly() const
Definition phv_spec.cpp:227
Definition phv_spec.h:315
bool hasParserExtractGroups() const override
Definition phv_spec.cpp:452
bitvec parserGroup(unsigned id) const override
Definition phv_spec.cpp:450
unsigned mauGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:461
unsigned parserGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:456
unsigned deparserGroupId(const PHV::Container &c) const override
Definition phv_spec.cpp:481
const bitvec & individuallyAssignedContainers() const override
Definition phv_spec.cpp:486
bitvec parserExtractGroup(unsigned id) const override
Definition phv_spec.cpp:454
unsigned physicalAddress(unsigned container_id, ArchBlockType_t) const override
Definition phv_spec.cpp:494
AddressSpec & physicalAddressSpec(ArchBlockType_t) const override
Definition phv_spec.h:345
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Size
all possible PHV container sizes in BFN devices
Definition phv.h:110