13#ifndef CIRCT_DIALECT_SYNTH_SYNTHOPS_H
14#define CIRCT_DIALECT_SYNTH_SYNTHOPS_H
19#include "mlir/IR/Attributes.h"
20#include "mlir/IR/Builders.h"
21#include "mlir/IR/BuiltinOps.h"
22#include "mlir/IR/BuiltinTypes.h"
23#include "mlir/IR/Dialect.h"
24#include "mlir/IR/Operation.h"
25#include "mlir/Interfaces/InferTypeOpInterface.h"
26#include "mlir/Interfaces/SideEffectInterfaces.h"
27#include "mlir/Rewrite/PatternApplicator.h"
30#include "circt/Dialect/Synth/Synth.h.inc"
32#include "llvm/ADT/PriorityQueue.h"
49 llvm::function_ref<
bool(mlir::Value, mlir::Operation *)> isOperandReady);
60 llvm::PointerIntPair<mlir::Value, 1, bool>
value;
105 llvm::function_ref<T(T, T)> combine) {
106 assert(!elements.empty() &&
"Cannot build tree from empty elements");
108 if (elements.size() == 1)
110 if (elements.size() == 2)
111 return combine(elements[0], elements[1]);
114 llvm::PriorityQueue<T, std::vector<T>, std::greater<T>> pq(elements.begin(),
118 while (pq.size() > 1) {
125 T combined = combine(e1, e2);
135 return x ^ (z | (x & y));
140 return (a & b) | (a & c) | (b & c);
149 std::swap(value.Zero, value.One);
155 auto allSet = a & b & c;
assert(baseType &&"element must be base type")
Helper class for delay-aware tree building.
ValueWithArrivalTime(mlir::Value value, int64_t arrivalTime, bool invert, size_t valueNumbering=0)
mlir::Value getValue() const
ValueWithArrivalTime & flipInversion()
size_t valueNumbering
Value numbering for deterministic ordering when arrival times are equal.
int64_t getArrivalTime() const
int64_t arrivalTime
The arrival time (delay) of this value in the circuit.
llvm::PointerIntPair< mlir::Value, 1, bool > value
The value and an optional inversion flag packed together.
bool operator>(const ValueWithArrivalTime &other) const
Comparison operator for priority queue.
llvm::APInt invertBooleanLogic(llvm::APInt value)
void populateVariadicXorInverterLoweringPatterns(mlir::RewritePatternSet &patterns)
LogicalResult topologicallySortGraphRegionBlocks(mlir::Operation *op, llvm::function_ref< bool(mlir::Value, mlir::Operation *)> isOperandReady)
This function performs a topological sort on the operations within each block of graph regions in the...
T buildBalancedTreeWithArrivalTimes(llvm::ArrayRef< T > elements, llvm::function_ref< T(T, T)> combine)
Build a balanced binary tree using a priority queue to greedily pair elements with earliest arrival t...
T evaluateDotLogic(const T &x, const T &y, const T &z)
Evaluate the Boolean function x ^ (z | (x & y)).
T evaluateMajorityLogic(const T &a, const T &b, const T &c)
T evaluateMuxLogic(const T &a, const T &b, const T &c)
bool isLogicNetworkOp(mlir::Operation *op)
T evaluateOneHotLogic(const T &a, const T &b, const T &c)
void populateVariadicAndInverterLoweringPatterns(mlir::RewritePatternSet &patterns)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.