10#include "mlir/IR/Value.h"
11#include "llvm/ADT/SmallVector.h"
12#include "llvm/Support/raw_ostream.h"
37 using Uses = std::bitset<4>;
75 return std::make_pair(
value,
Use(llvm::countr_zero(
uses.to_ulong())));
117 Use &flippedUse)
const;
120 void print(llvm::raw_ostream &os,
121 llvm::function_ref<
void(Value)> printValue = {})
const;
144 return llvm::any_of(
andTerms, [](
auto term) {
return term.isFalse(); });
184 bool addTerms(ArrayRef<AndTerm> terms);
192 evaluate(llvm::function_ref<std::optional<bool>(Value,
bool)> evaluateTerm);
195 void print(llvm::raw_ostream &os,
196 llvm::function_ref<
void(Value)> printValue = {})
const;
206 explicit DNF(
bool value) {
224 !
orTerms[0].andTerms[0].value &&
227 explicit operator bool()
const {
return !
isNull(); }
235 return orTerms[0].getSingleTerm();
277 evaluate(llvm::function_ref<std::optional<bool>(Value,
bool)> evaluateTerm);
280 void print(llvm::raw_ostream &os,
281 llvm::function_ref<
void(Value)> printValue = {})
const;
assert(baseType &&"element must be base type")
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
An individual term of an AND expression in a DNF.
static constexpr Uses PastUses
The set of past uses.
bool hasAllUses(Uses u) const
Check if this term has all of the specified uses of the term's value.
void removeUses(Uses u)
Remove multiple uses.
Use
An integer indicating one use of the value in this term.
@ NotPast
The inverted past value !@x.
@ NotId
The inverted value !x.
@ Not
The bit that indicates inversion.
bool isTrue() const
Check if this term is trivially true.
static AndTerm past(Value value)
Create a term with a past value.
AndTerm(Value value, Uses uses)
Create a term with a value and a set of uses.
bool operator==(const AndTerm other) const
bool hasAnyUses(Uses u) const
Check if this term has any of the specified uses of the term's value.
std::optional< std::pair< Value, AndTerm::Use > > getSingleTerm() const
If this AND term has a single use, return it.
bool hasUse(Use u) const
Check if this term has a specific use of the term's value.
static AndTerm negEdge(Value value)
Create a term representing a negedge on a value.
bool operator>=(const AndTerm other) const
static constexpr Uses PosEdgeUses
The set of uses that indicates a posedge.
std::bitset< 4 > Uses
The set of uses of this value as a bit mask.
void addUse(Use u)
Add a single use.
static AndTerm posEdge(Value value)
Create a term representing a posedge on a value.
Uses uses
The different uses of this value.
bool isSubsetOf(const AndTerm &other) const
Check if this term is a subset of another term.
unsigned isSubsetOfModuloSingleFlip(const AndTerm &other, Use &flippedUse) const
Check if this term is a subset of another term modulo a single flipped term.
unsigned getNumUses() const
Get the number of uses.
bool operator!=(const AndTerm other) const
bool operator>(const AndTerm other) const
void removeUse(Use u)
Remove a single use.
bool operator<(const AndTerm other) const
bool operator<=(const AndTerm other) const
static constexpr Uses NegEdgeUses
The set of uses that indicates a negedge.
int compare(const AndTerm other) const
Compare against another term.
bool isFalse() const
Check if this term is trivially false.
AndTerm()
Create a null term.
void addUses(Uses u)
Add multiple uses.
void print(llvm::raw_ostream &os, llvm::function_ref< void(Value)> printValue={}) const
Print this term to os, using the given callback to print the value.
static AndTerm id(Value value)
Create a term with a plain value.
static constexpr Uses IdUses
The set of present uses.
DNF operator~() const
Compute the boolean NOT of this DNF.
SmallVector< OrTerm, 1 > OrTerms
bool operator<=(const DNF &other) const
bool operator!=(const DNF &other) const
bool operator>(const DNF &other) const
DNF()
Construct a null DNF.
bool operator==(const DNF &other) const
DNF operator&(const DNF &other) const
Compute the boolean AND of this and another DNF.
std::optional< bool > evaluate(llvm::function_ref< std::optional< bool >(Value, bool)> evaluateTerm)
Try to evaluate this DNF to a constant true or false value.
DNF operator|(const DNF &other) const
Compute the boolean OR of this and another DNF.
DNF(bool value)
Construct a constant true or false.
DNF & operator|=(const DNF &other)
DNF(AndTerm value)
Construct a DNF with a given AND term inside a single OR term.
void print(llvm::raw_ostream &os, llvm::function_ref< void(Value)> printValue={}) const
Print this DNF to os, using the given callback to print the value.
DNF(OrTerms terms)
Construct a DNF with a multiple OR terms. The terms must be sorted.
bool operator>=(const DNF &other) const
int compare(const DNF &other) const
Compare against another DNF.
bool contains(const OrTerm &orTerm) const
Check if this DNF contains a specific OR term.
DNF & operator&=(const DNF &other)
void printWithValues(llvm::raw_ostream &os) const
Print this DNF to os, followed by a list of the concrete values used.
void optimize()
Removes redundant terms as follows:
DNF operator^(const DNF &other) const
Compute the boolean XOR of this and another DNF.
DNF & operator^=(const DNF &other)
static DNF withPastValue(Value value)
Construct a DNF with a single opaque past Value.
DNF(Value value)
Construct a DNF with a single opaque Value.
bool operator<(const DNF &other) const
bool isTrue() const
Check whether this DNF is trivially true.
std::optional< std::pair< Value, AndTerm::Use > > getSingleTerm() const
If this DNF consists of a single term, return it.
bool isNull() const
Check whether this DNF is null.
bool isFalse() const
Check whether this DNF is trivially false.
bool isSortedAndUnique() const
Check that all terms in the DNF are sorted.
DNF(OrTerm value)
Construct a DNF with a given OR term.
An individual term of an OR expression in a DNF.
bool operator==(const OrTerm &other) const
bool operator>=(const OrTerm &other) const
llvm::hash_code flipInvariantHash() const
Return a hash code for this term that is invariant to inversion of individual terms.
void print(llvm::raw_ostream &os, llvm::function_ref< void(Value)> printValue={}) const
Print this term to os, using the given callback to print the value.
bool isSubsetOfModuloSingleFlip(const OrTerm &other, unsigned &flippedIdx, AndTerm::Use &flippedUse) const
Check if this term is a subset of another term modulo a single flipped term.
bool contains(const AndTerm &andTerm) const
Check if this OR term contains a specific AND term.
bool isTrue() const
Check if this term is trivially true.
OrTerm(AndTerm singleTerm)
Create a term with a single element.
SmallVector< AndTerm, 1 > AndTerms
bool isFalse() const
Check if this term is trivially false.
std::optional< std::pair< Value, AndTerm::Use > > getSingleTerm() const
If this OR term consists of a single term, return it.
std::optional< bool > evaluate(llvm::function_ref< std::optional< bool >(Value, bool)> evaluateTerm)
Try to evaluate this term to a constant true or false value.
OrTerm(AndTerms andTerms)
Create a term with multiple elements. The terms must be sorted.
OrTerm()
Create a constant true term.
bool isSubsetOf(const OrTerm &other) const
Check if this term is a subset of another term.
bool operator>(const OrTerm &other) const
bool addTerm(AndTerm term)
Add an AndTerm.
bool operator<=(const OrTerm &other) const
int compare(const OrTerm &other) const
Compare against another term.
bool operator<(const OrTerm &other) const
bool isSortedAndUnique() const
Check that all terms in this OrTerm are sorted.
bool operator!=(const OrTerm &other) const
bool addTerms(ArrayRef< AndTerm > terms)
Add multiple AndTerms.