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 | Static Public Member Functions | Public Attributes | List of all members
circt::llhd::DNF Struct Reference

#include <DNF.h>

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

Public Types

using OrTerms = SmallVector< OrTerm, 1 >
 

Public Member Functions

 DNF ()
 Construct a null DNF.
 
 DNF (bool value)
 Construct a constant true or false.
 
 DNF (Value value)
 Construct a DNF with a single opaque Value.
 
 DNF (AndTerm value)
 Construct a DNF with a given AND term inside a single OR term.
 
 DNF (OrTerm value)
 Construct a DNF with a given OR term.
 
 DNF (OrTerms terms)
 Construct a DNF with a multiple OR terms. The terms must be sorted.
 
bool isNull () const
 Check whether this DNF is null.
 
 operator bool () const
 
bool isFalse () const
 Check whether this DNF is trivially false.
 
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 contains (const OrTerm &orTerm) const
 Check if this DNF contains a specific OR term.
 
bool contains (const AndTerm &andTerm) const
 Check if this DNF contains a specific AND term.
 
int compare (const DNF &other) const
 Compare against another DNF.
 
bool operator== (const DNF &other) const
 
bool operator!= (const DNF &other) const
 
bool operator< (const DNF &other) const
 
bool operator> (const DNF &other) const
 
bool operator>= (const DNF &other) const
 
bool operator<= (const DNF &other) const
 
DNF operator| (const DNF &other) const
 Compute the boolean OR of this and another DNF.
 
DNF operator& (const DNF &other) const
 Compute the boolean AND of this and another DNF.
 
DNF operator^ (const DNF &other) const
 Compute the boolean XOR of this and another DNF.
 
DNF operator~ () const
 Compute the boolean NOT of this DNF.
 
DNFoperator|= (const DNF &other)
 
DNFoperator&= (const DNF &other)
 
DNFoperator^= (const DNF &other)
 
DNFnegate ()
 
bool isSortedAndUnique () const
 Check that all terms in the DNF are sorted.
 
void optimize ()
 Removes redundant terms as follows:
 
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.
 
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.
 
void printWithValues (llvm::raw_ostream &os) const
 Print this DNF to os, followed by a list of the concrete values used.
 

Static Public Member Functions

static DNF withPastValue (Value value)
 Construct a DNF with a single opaque past Value.
 

Public Attributes

OrTerms orTerms
 

Detailed Description

Definition at line 199 of file DNF.h.

Member Typedef Documentation

◆ OrTerms

using circt::llhd::DNF::OrTerms = SmallVector<OrTerm, 1>

Definition at line 200 of file DNF.h.

Constructor & Destructor Documentation

◆ DNF() [1/6]

circt::llhd::DNF::DNF ( )
inline

Construct a null DNF.

Definition at line 204 of file DNF.h.

Referenced by operator&(), operator^(), operator|(), operator~(), and withPastValue().

◆ DNF() [2/6]

circt::llhd::DNF::DNF ( bool  value)
inlineexplicit

Construct a constant true or false.

Definition at line 206 of file DNF.h.

References orTerms.

◆ DNF() [3/6]

circt::llhd::DNF::DNF ( Value  value)
inlineexplicit

Construct a DNF with a single opaque Value.

Definition at line 211 of file DNF.h.

◆ DNF() [4/6]

circt::llhd::DNF::DNF ( AndTerm  value)
inlineexplicit

Construct a DNF with a given AND term inside a single OR term.

Definition at line 213 of file DNF.h.

◆ DNF() [5/6]

circt::llhd::DNF::DNF ( OrTerm  value)
inlineexplicit

Construct a DNF with a given OR term.

Definition at line 215 of file DNF.h.

References orTerms.

◆ DNF() [6/6]

circt::llhd::DNF::DNF ( OrTerms  terms)
inlineexplicit

Construct a DNF with a multiple OR terms. The terms must be sorted.

Definition at line 217 of file DNF.h.

References assert(), and isSortedAndUnique().

Member Function Documentation

◆ compare()

int DNF::compare ( const DNF other) const

Compare against another DNF.

Definition at line 336 of file DNF.cpp.

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ contains() [1/2]

bool DNF::contains ( const AndTerm andTerm) const

Check if this DNF contains a specific AND term.

Definition at line 329 of file DNF.cpp.

References orTerms.

◆ contains() [2/2]

bool DNF::contains ( const OrTerm orTerm) const

Check if this DNF contains a specific OR term.

Definition at line 324 of file DNF.cpp.

References orTerms.

◆ evaluate()

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

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

Definition at line 449 of file DNF.cpp.

References orTerms.

◆ getSingleTerm()

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

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

Definition at line 233 of file DNF.h.

References isNull(), and orTerms.

◆ isFalse()

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

Check whether this DNF is trivially false.

Definition at line 229 of file DNF.h.

References orTerms.

Referenced by operator&(), operator^(), operator|(), operator~(), and print().

◆ isNull()

bool circt::llhd::DNF::isNull ( ) const
inline

Check whether this DNF is null.

Definition at line 222 of file DNF.h.

References circt::llhd::AndTerm::Id, and orTerms.

Referenced by getSingleTerm(), operator bool(), operator&(), operator^(), operator|(), operator~(), and print().

◆ isSortedAndUnique()

bool DNF::isSortedAndUnique ( ) const

Check that all terms in the DNF are sorted.

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

Definition at line 349 of file DNF.cpp.

References orTerms.

Referenced by DNF().

◆ isTrue()

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

Check whether this DNF is trivially true.

Definition at line 231 of file DNF.h.

References orTerms.

Referenced by operator&(), operator^(), operator|(), operator~(), and print().

◆ negate()

DNF & circt::llhd::DNF::negate ( )
inline

Definition at line 264 of file DNF.h.

◆ operator bool()

circt::llhd::DNF::operator bool ( ) const
inlineexplicit

Definition at line 227 of file DNF.h.

References isNull().

◆ operator!=()

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

Definition at line 246 of file DNF.h.

References compare().

◆ operator&()

DNF DNF::operator& ( const DNF other) const

Compute the boolean AND of this and another DNF.

Definition at line 574 of file DNF.cpp.

References assert(), DNF(), insertUniqued(), isFalse(), isNull(), isTrue(), and orTerms.

◆ operator&=()

DNF & circt::llhd::DNF::operator&= ( const DNF other)
inline

Definition at line 262 of file DNF.h.

◆ operator<()

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

Definition at line 247 of file DNF.h.

References compare().

◆ operator<=()

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

Definition at line 250 of file DNF.h.

References compare().

◆ operator==()

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

Definition at line 245 of file DNF.h.

References compare().

◆ operator>()

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

Definition at line 248 of file DNF.h.

References compare().

◆ operator>=()

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

Definition at line 249 of file DNF.h.

References compare().

◆ operator^()

DNF DNF::operator^ ( const DNF other) const

Compute the boolean XOR of this and another DNF.

Definition at line 612 of file DNF.cpp.

References DNF(), isFalse(), isNull(), and isTrue().

◆ operator^=()

DNF & circt::llhd::DNF::operator^= ( const DNF other)
inline

Definition at line 263 of file DNF.h.

◆ operator|()

DNF DNF::operator| ( const DNF other) const

Compute the boolean OR of this and another DNF.

Definition at line 521 of file DNF.cpp.

References circt::llhd::OrTerm::compare(), DNF(), isFalse(), isNull(), isTrue(), and orTerms.

◆ operator|=()

DNF & circt::llhd::DNF::operator|= ( const DNF other)
inline

Definition at line 261 of file DNF.h.

◆ operator~()

DNF DNF::operator~ ( ) const

Compute the boolean NOT of this DNF.

Definition at line 640 of file DNF.cpp.

References assert(), DNF(), isFalse(), isNull(), isTrue(), circt::llhd::AndTerm::Not, and orTerms.

◆ optimize()

void DNF::optimize ( )

Removes redundant terms as follows:

  • a&x | !a&x -> x (eliminate complements)
  • a&x | x -> x (eliminate supersets)

Definition at line 359 of file DNF.cpp.

References circt::llhd::AndTerm::Id, circt::llhd::AndTerm::NotId, circt::llhd::AndTerm::NotPast, orTerms, and circt::llhd::AndTerm::Past.

◆ print()

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

Definition at line 466 of file DNF.cpp.

References isFalse(), isNull(), isTrue(), and orTerms.

Referenced by printWithValues().

◆ printWithValues()

void DNF::printWithValues ( llvm::raw_ostream &  os) const

Print this DNF to os, followed by a list of the concrete values used.

Definition at line 495 of file DNF.cpp.

References print().

Referenced by circt::llhd::operator<<().

◆ withPastValue()

static DNF circt::llhd::DNF::withPastValue ( Value  value)
inlinestatic

Construct a DNF with a single opaque past Value.

Definition at line 219 of file DNF.h.

References DNF(), and circt::llhd::AndTerm::past().

Member Data Documentation

◆ orTerms

OrTerms circt::llhd::DNF::orTerms

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