17#ifndef CIRCT_SCHEDULING_PROBLEMS_H
18#define CIRCT_SCHEDULING_PROBLEMS_H
23#include "mlir/IR/BuiltinAttributes.h"
24#include "llvm/ADT/DenseMap.h"
25#include "llvm/ADT/SetVector.h"
77 static constexpr auto name =
"Problem";
112 std::string
str()
const {
return attr.str(); }
134 std::string
str()
const {
return attr.str(); }
153 llvm::DenseMap<Operation *, llvm::SmallSetVector<Operation *, 4>>;
155 template <
typename T>
157 template <
typename T>
159 template <
typename T>
161 template <
typename T>
163 template <
typename T>
264 std::optional<SmallVector<ResourceType>>
293 std::optional<unsigned>
getEndTime(Operation *op);
324 llvm::SmallVector<std::pair<std::string, std::string>, 2>;
351 virtual LogicalResult
check();
353 virtual LogicalResult
verify();
361 static constexpr auto name =
"CyclicProblem";
398 virtual LogicalResult
verify()
override;
414 static constexpr auto name =
"ChainingProblem";
461 virtual LogicalResult
checkDelays(OperatorType opr);
471 virtual LogicalResult
check()
override;
472 virtual LogicalResult
verify()
override;
488 static constexpr auto name =
"SharedOperatorsProblem";
501 return limit.lookup(rsrc);
509 virtual LogicalResult
checkLatency(Operation *op)
override;
514 virtual LogicalResult
verify()
override;
531 static constexpr auto name =
"ModuloProblem";
541 virtual LogicalResult
verify()
override;
560 static constexpr auto name =
"ChainingCyclicProblem";
568 LogicalResult
check()
override;
569 LogicalResult
verify()
override;
This class models the accumulation of physical propagation delays on combinational paths along SSA de...
LogicalResult verify() override
Return success if the computed solution is valid.
LogicalResult checkDefUse(Dependence dep)
LogicalResult check() override
Return success if the constructed scheduling problem is valid.
static constexpr auto name
ChainingCyclicProblem()=default
This class models the accumulation of physical propagation delays on combinational paths along SSA de...
ChainingProblem()=default
std::optional< float > getOutgoingDelay(OperatorType opr)
The outgoing delay denotes the propagation time from either the operand inputs (combinational operato...
void setStartTimeInCycle(Operation *op, float time)
void setIncomingDelay(OperatorType opr, float delay)
OperationProperty< float > startTimeInCycle
virtual LogicalResult check() override
Return success if the constructed scheduling problem is valid.
virtual LogicalResult verifyPrecedenceInCycle(Dependence dep)
If dep is an SSA edge and its source operation finishes in the same time step as the destination oper...
std::optional< float > getIncomingDelay(OperatorType opr)
The incoming delay denotes the propagation time from the operand inputs to either the result outputs ...
OperatorTypeProperty< float > incomingDelay
static constexpr auto name
void setOutgoingDelay(OperatorType opr, float delay)
void clearStartTimeInCycle()
virtual LogicalResult verify() override
Return success if the computed solution is valid.
OperatorTypeProperty< float > outgoingDelay
virtual LogicalResult verifyStartTimeInCycle(Operation *op)
op has a non-negative start time in its cycle.
virtual LogicalResult checkDelays(OperatorType opr)
Incoming/outgoing delays are set for opr and non-negative.
std::optional< float > getStartTimeInCycle(Operation *op)
Computed by the scheduler, this start time is relative to the beginning of the cycle that op starts i...
This class models a cyclic scheduling problem.
void setDistance(Dependence dep, unsigned val)
virtual LogicalResult verifyInitiationInterval()
This problem has a non-zero II.
virtual PropertyStringVector getProperties() override
virtual LogicalResult verifyPrecedence(Dependence dep) override
dep's source operation is available before dep's destination operation starts (dep's distance iterati...
std::optional< unsigned > getDistance(Dependence dep)
The distance determines whether a dependence has to be satisfied in the same iteration (distance=0 or...
void setInitiationInterval(unsigned val)
InstanceProperty< unsigned > initiationInterval
static constexpr auto name
virtual LogicalResult verify() override
Return success if the computed solution is valid.
DependenceProperty< unsigned > distance
std::optional< unsigned > getInitiationInterval()
The initiation interval (II) is the number of time steps between subsequent iterations,...
This class models the modulo scheduling problem as the composition of the cyclic problem and the reso...
virtual LogicalResult verify() override
Return success if the computed solution is valid.
static constexpr auto name
virtual LogicalResult verifyUtilization(ResourceType rsrc) override
opr is not oversubscribed in any congruence class modulo II.
This class models the most basic scheduling problem.
void setLatency(OperatorType opr, unsigned val)
llvm::DenseMap< Operation *, llvm::SmallSetVector< Operation *, 4 > > AuxDependenceMap
void insertResourceType(ResourceType rsrc)
Include rsrc in this scheduling problem.
llvm::SetVector< Operation * > OperationSet
llvm::SetVector< OperatorType > OperatorTypeSet
virtual LogicalResult verify()
Return success if the computed solution is valid.
StringAttr rsrcLibraryName
StringAttr getInstanceName()
virtual LogicalResult check()
Return success if the constructed scheduling problem is valid.
std::optional< unsigned > getLatency(OperatorType opr)
The latency is the number of cycles opr needs to compute its result.
virtual PropertyStringVector getProperties()
void insertOperation(Operation *op)
Include op in this scheduling problem.
llvm::iterator_range< detail::DependenceIterator > DependenceRange
bool hasOperation(Operation *op)
Return true if op is part of this problem.
StringAttr getLibraryName()
std::optional< SmallVector< ResourceType > > getLinkedResourceTypes(Operation *op)
The linked resource type provides the available resources for op.
LogicalResult insertDependence(Dependence dep)
Include dep in the scheduling problem.
std::optional< unsigned > getEndTime(Operation *op)
Returns the end time for op, as computed by the scheduler.
OperationProperty< OperatorType > linkedOperatorType
OperationProperty< unsigned > startTime
void setLinkedResourceTypes(Operation *op, SmallVector< ResourceType > rsrc)
StringAttr getRsrcLibraryName()
void setRsrcLibraryName(StringAttr name)
std::optional< T > InstanceProperty
std::optional< OperatorType > getLinkedOperatorType(Operation *op)
The linked operator type provides the runtime characteristics for op.
ResourceTypeSet resourceTypes
void setStartTime(Operation *op, unsigned val)
OperatorTypeProperty< unsigned > latency
const ResourceTypeSet & getResourceTypes()
Return the set of resource types.
SmallDenseMap< Operation *, StringAttr > operationNames
llvm::DenseMap< Operation *, std::optional< T > > OperationProperty
static constexpr auto name
virtual ~Problem()=default
void setContainingOp(Operation *op)
Set the operation containing this problem, e.g. to emit diagnostics.
const OperationSet & getOperations()
Return the set of operations.
OperatorType getOrInsertOperatorType(StringRef name)
Retrieves the operator type identified by the client-specific name.
AuxDependenceMap auxDependences
std::optional< unsigned > getStartTime(Operation *op)
Return the start time for op, as computed by the scheduler.
llvm::DenseMap< OperatorType, std::optional< T > > OperatorTypeProperty
void setInstanceName(StringAttr name)
OperatorTypeSet operatorTypes
llvm::SmallVector< std::pair< std::string, std::string >, 2 > PropertyStringVector
virtual LogicalResult verifyStartTime(Operation *op)
op has a start time.
virtual LogicalResult checkLinkedOperatorType(Operation *op)
op is linked to a registered operator type.
llvm::DenseMap< Dependence, std::optional< T > > DependenceProperty
DependenceRange getDependences(Operation *op)
Return a range object to transparently iterate over op's incoming 1) implicit def-use dependences (ba...
llvm::SetVector< ResourceType > ResourceTypeSet
OperationProperty< SmallVector< ResourceType > > linkedResourceTypes
bool hasOperatorType(OperatorType opr)
Return true if opr is part of this problem.
virtual LogicalResult verifyPrecedence(Dependence dep)
dep's source operation is available before dep's destination operation starts.
void setLibraryName(StringAttr name)
void setLinkedOperatorType(Operation *op, OperatorType opr)
Operation * getContainingOp()
Return the operation containing this problem, e.g. to emit diagnostics.
void insertOperatorType(OperatorType opr)
Include opr in this scheduling problem.
llvm::DenseMap< ResourceType, std::optional< T > > ResourceTypeProperty
void setOperationName(Operation *op, StringAttr name)
ResourceType getOrInsertResourceType(StringRef name)
Retrieves the resource type identified by the client-specific name.
StringAttr getOperationName(Operation *op)
virtual LogicalResult checkLatency(Operation *op)
op has a latency.
Problem(Operation *containingOp)
Construct an empty scheduling problem.
bool hasResourceType(ResourceType rsrc)
Return true if rsrc is part of this problem.
const OperatorTypeSet & getOperatorTypes()
Return the set of operator types.
This class models a resource-constrained scheduling problem.
SharedOperatorsProblem()=default
virtual LogicalResult verifyUtilization(ResourceType rsrc)
rsrc is not oversubscribed in any time step.
void setLimit(ResourceType rsrc, unsigned val)
virtual LogicalResult verify() override
Return success if the computed solution is valid.
static constexpr auto name
virtual LogicalResult checkLatency(Operation *op) override
If op is limited, it has a non-zero latency.
ResourceTypeProperty< unsigned > limit
std::optional< unsigned > getLimit(ResourceType rsrc)
The limit is the maximum number of operations using rsrc that are available in the target hardware.
An iterator to transparently surface an operation's def-use dependences from the SSA subgraph (induce...
A wrapper class to uniformly handle def-use and auxiliary dependence edges.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Operator types are distinguished by name (chosen by the client).
mlir::StringAttr getAttr() const
static OperatorType get(mlir::MLIRContext *ctx, llvm::StringRef name)
mlir::StringRef getValue() const
OperatorType(mlir::StringAttr attr)
friend bool operator==(const OperatorType &lhs, const OperatorType &rhs)
Resource types are distinguished by name (chosen by the client).
mlir::StringRef getValue() const
ResourceType(mlir::StringAttr attr)
static ResourceType get(mlir::MLIRContext *ctx, llvm::StringRef name)
friend bool operator==(const ResourceType &lhs, const ResourceType &rhs)
mlir::StringAttr getAttr() const
bool operator!=(const ResourceType &rhs) const
static circt::scheduling::Problem::OperatorType getTombstoneKey()
static bool isEqual(const circt::scheduling::Problem::OperatorType &lhs, const circt::scheduling::Problem::OperatorType &rhs)
static circt::scheduling::Problem::OperatorType getEmptyKey()
static unsigned getHashValue(const circt::scheduling::Problem::OperatorType &val)
static bool isEqual(const circt::scheduling::Problem::ResourceType &lhs, const circt::scheduling::Problem::ResourceType &rhs)
static unsigned getHashValue(const circt::scheduling::Problem::ResourceType &val)
static circt::scheduling::Problem::ResourceType getTombstoneKey()
static circt::scheduling::Problem::ResourceType getEmptyKey()