Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | List of all members
circt::llhd::OrTerm Struct Reference

An individual term of an OR expression in a DNF. More...

#include <DNF.h>

Collaboration diagram for circt::llhd::OrTerm:
Collaboration graph
[legend]

Public Types

using AndTerms = SmallVector< AndTerm, 1 >
 

Public Member Functions

 OrTerm ()
 Create a constant true term.
 
 OrTerm (AndTerm singleTerm)
 Create a term with a single element.
 
 OrTerm (AndTerms andTerms)
 Create a term with multiple elements. The terms must be sorted.
 
bool isTrue () const
 Check if this term is trivially true.
 
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.
 
bool contains (const AndTerm &andTerm) const
 Check if this OR term contains a specific AND term.
 
int compare (const OrTerm &other) const
 Compare against another term.
 
bool operator== (const OrTerm &other) const
 
bool operator!= (const OrTerm &other) const
 
bool operator< (const OrTerm &other) const
 
bool operator> (const OrTerm &other) const
 
bool operator<= (const OrTerm &other) const
 
bool operator>= (const OrTerm &other) const
 
bool isSubsetOf (const OrTerm &other) const
 Check if this term is a subset of another term.
 
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.
 
llvm::hash_code flipInvariantHash () const
 Return a hash code for this term that is invariant to inversion of individual terms.
 
bool addTerm (AndTerm term)
 Add an AndTerm.
 
bool addTerms (ArrayRef< AndTerm > terms)
 Add multiple AndTerms.
 
bool isSortedAndUnique () const
 Check that all terms in this OrTerm are sorted.
 
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.
 
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.
 

Public Attributes

AndTerms andTerms
 

Detailed Description

An individual term of an OR expression in a DNF.

Consists of multiple terms AND-ed together. A true value is represented as an empty list of AND terms, since the neutral element of the AND operation is true.

Definition at line 127 of file DNF.h.

Member Typedef Documentation

◆ AndTerms

using circt::llhd::OrTerm::AndTerms = SmallVector<AndTerm, 1>

Definition at line 128 of file DNF.h.

Constructor & Destructor Documentation

◆ OrTerm() [1/3]

circt::llhd::OrTerm::OrTerm ( )
inline

Create a constant true term.

Definition at line 132 of file DNF.h.

◆ OrTerm() [2/3]

circt::llhd::OrTerm::OrTerm ( AndTerm  singleTerm)
inline

Create a term with a single element.

Definition at line 134 of file DNF.h.

References andTerms.

◆ OrTerm() [3/3]

circt::llhd::OrTerm::OrTerm ( AndTerms  andTerms)
inline

Create a term with multiple elements. The terms must be sorted.

Definition at line 136 of file DNF.h.

References assert(), and isSortedAndUnique().

Member Function Documentation

◆ addTerm()

bool OrTerm::addTerm ( AndTerm  term)

Add an AndTerm.

Returns false if adding the AndTerm has made this OrTerm trivially false.

Definition at line 245 of file DNF.cpp.

References andTerms, compareValueOnly(), circt::llhd::AndTerm::uses, and circt::llhd::AndTerm::value.

Referenced by addTerms().

◆ addTerms()

bool OrTerm::addTerms ( ArrayRef< AndTerm terms)

Add multiple AndTerms.

Returns false if adding the terms has made this OrTerm trivially false.

Definition at line 258 of file DNF.cpp.

References addTerm().

◆ compare()

int OrTerm::compare ( const OrTerm other) const

Compare against another term.

Definition at line 150 of file DNF.cpp.

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), and circt::llhd::DNF::operator|().

◆ contains()

bool OrTerm::contains ( const AndTerm andTerm) const

Check if this OR term contains a specific AND term.

Definition at line 145 of file DNF.cpp.

References andTerms.

◆ evaluate()

std::optional< bool > OrTerm::evaluate ( llvm::function_ref< std::optional< bool >(Value, bool)>  evaluateTerm)

Try to evaluate this term to a constant true or false value.

Definition at line 275 of file DNF.cpp.

References andTerms, circt::llhd::AndTerm::Not, and circt::llhd::AndTerm::Past.

◆ flipInvariantHash()

llvm::hash_code OrTerm::flipInvariantHash ( ) const

Return a hash code for this term that is invariant to inversion of individual terms.

Definition at line 230 of file DNF.cpp.

References andTerms, circt::llhd::AndTerm::uses, and circt::llhd::AndTerm::value.

◆ getSingleTerm()

std::optional< std::pair< Value, AndTerm::Use > > circt::llhd::OrTerm::getSingleTerm ( ) const
inline

If this OR term consists of a single term, return it.

Definition at line 147 of file DNF.h.

References andTerms.

◆ isFalse()

bool circt::llhd::OrTerm::isFalse ( ) const
inline

Check if this term is trivially false.

Definition at line 143 of file DNF.h.

References andTerms.

◆ isSortedAndUnique()

bool OrTerm::isSortedAndUnique ( ) const

Check that all terms in this OrTerm are sorted.

This is an invariant we want to check in builds with asserts enabled.

Definition at line 265 of file DNF.cpp.

References andTerms.

Referenced by OrTerm().

◆ isSubsetOf()

bool OrTerm::isSubsetOf ( const OrTerm other) const

Check if this term is a subset of another term.

a & b & c is considered a subset of a & b.

Definition at line 203 of file DNF.cpp.

References andTerms.

◆ isSubsetOfModuloSingleFlip()

bool OrTerm::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.

If it is, flippedIdx and flippedUse are set to indicate the flipped term. a & b & c is considered a subset of !a & b with a single flipped term a.

Definition at line 163 of file DNF.cpp.

References andTerms.

◆ isTrue()

bool circt::llhd::OrTerm::isTrue ( ) const
inline

Check if this term is trivially true.

Definition at line 141 of file DNF.h.

References andTerms.

Referenced by print().

◆ operator!=()

bool circt::llhd::OrTerm::operator!= ( const OrTerm other) const
inline

Definition at line 158 of file DNF.h.

References compare().

◆ operator<()

bool circt::llhd::OrTerm::operator< ( const OrTerm other) const
inline

Definition at line 159 of file DNF.h.

References compare().

◆ operator<=()

bool circt::llhd::OrTerm::operator<= ( const OrTerm other) const
inline

Definition at line 161 of file DNF.h.

References compare().

◆ operator==()

bool circt::llhd::OrTerm::operator== ( const OrTerm other) const
inline

Definition at line 157 of file DNF.h.

References compare().

◆ operator>()

bool circt::llhd::OrTerm::operator> ( const OrTerm other) const
inline

Definition at line 160 of file DNF.h.

References compare().

◆ operator>=()

bool circt::llhd::OrTerm::operator>= ( const OrTerm other) const
inline

Definition at line 162 of file DNF.h.

References compare().

◆ print()

void OrTerm::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.

Definition at line 299 of file DNF.cpp.

References andTerms, and isTrue().

Member Data Documentation

◆ andTerms

AndTerms circt::llhd::OrTerm::andTerms

The documentation for this struct was generated from the following files: