30 LogicalValue(
const LogicalValue &) =
default;
31 LogicalValue(LogicalValue &&) =
default;
32 LogicalValue &operator=(
const LogicalValue &) =
default;
33 LogicalValue &operator=(LogicalValue &&) =
default;
35 LogicalValue(
int kind,
const LogicalValue &v) : LogicalValue{v} {
39 LogicalValue(
int kind, LogicalValue &&v) : LogicalValue{std::move(v)} {
43 LogicalValue(
int kind,
bool truth) : word_(Represent(
kind, truth)) {}
45 LogicalValue(
int kind,
const Word &w) : word_(
kind, w) {}
50 static LogicalValue
Zero(
int kind) {
return LogicalValue{
kind,
false}; }
52 void print(llvm::raw_ostream &os)
const;
54#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
55 LLVM_DUMP_METHOD
void dump()
const;
60 bool IsNull()
const {
return word_.IsNull(); }
63 int kind()
const {
return word_.kind(); }
65 int bits()
const {
return bits(
kind()); }
66 static constexpr int bits(
int kind) {
return Word::bits(
kind); }
74 Word word()
const {
return word_; }
76 bool IsCanonical()
const {
78 return word_ == canonicalFalse(
kind) || word_ == canonicalTrue(
kind);
85 return !IsTrue() && that.IsTrue();
87 bool operator<=(
const LogicalValue &that)
const {
return !IsTrue(); }
88 bool operator==(
const LogicalValue &that)
const {
89 return IsTrue() == that.IsTrue();
91 bool operator!=(
const LogicalValue &that)
const {
92 return IsTrue() != that.IsTrue();
95 bool operator>=(
const LogicalValue &that)
const {
return IsTrue(); }
97 bool operator>(
const LogicalValue &that)
const {
98 return IsTrue() && !that.IsTrue();
101 bool IsTrue()
const {
return !word_.IsZero(); }
103 LogicalValue NOT()
const {
104 return FromWord(word_.IEOR(canonicalTrue(
kind())));
107 LogicalValue AND(
const LogicalValue &that)
const {
108 return FromWord(word_.IAND(that.word()));
111 LogicalValue OR(
const LogicalValue &that)
const {
112 return FromWord(word_.IOR(that.word()));
115 LogicalValue EQV(
const LogicalValue &that)
const {
return NEQV(that).NOT(); }
117 LogicalValue NEQV(
const LogicalValue &that)
const {
118 return FromWord(word_.IEOR(that.word()));
121 static LogicalValue FromRawBytes(
122 int kind,
const void *raw, std::size_t expectedSize) {
123 Word w{Word::FromRawBytes(
kind, raw, expectedSize)};
124 return LogicalValue{w.kind(), w};
127 void StoreRawBytes(
void *dst,
size_t size,
bool *changed =
nullptr)
const {
128 word_.StoreRawBytes(dst, size, changed);
132 static Word canonicalTrue(
int kind) {
return Word{
kind, 1}; }
134 static Word canonicalFalse(
int kind) {
return Word{
kind, 0}; }
136 static Word Represent(
int kind,
bool x) {
137 return x ? canonicalTrue(
kind) : canonicalFalse(
kind);
140 static LogicalValue FromWord(
const Word &w) {
146 static LogicalValue FromWord(Word &&w) {
148 v.word_ = std::move(w);