2017-04-26 18:39:58 +02:00
|
|
|
//===- llvm/Support/KnownBits.h - Stores known zeros/ones -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a class for representing known zeros and ones used by
|
|
|
|
// computeKnownBits.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SUPPORT_KNOWNBITS_H
|
|
|
|
#define LLVM_SUPPORT_KNOWNBITS_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2017-04-29 18:43:11 +02:00
|
|
|
// Struct for tracking the known zeros and ones of a value.
|
2017-04-26 18:39:58 +02:00
|
|
|
struct KnownBits {
|
|
|
|
APInt Zero;
|
|
|
|
APInt One;
|
|
|
|
|
|
|
|
// Default construct Zero and One.
|
|
|
|
KnownBits() {}
|
|
|
|
|
|
|
|
/// Create a known bits object of BitWidth bits initialized to unknown.
|
|
|
|
KnownBits(unsigned BitWidth) : Zero(BitWidth, 0), One(BitWidth, 0) {}
|
|
|
|
|
|
|
|
/// Get the bit width of this value.
|
|
|
|
unsigned getBitWidth() const {
|
|
|
|
assert(Zero.getBitWidth() == One.getBitWidth() &&
|
|
|
|
"Zero and One should have the same width!");
|
|
|
|
return Zero.getBitWidth();
|
|
|
|
}
|
2017-04-29 18:43:11 +02:00
|
|
|
|
|
|
|
/// Returns true if this value is known to be negative.
|
|
|
|
bool isNegative() const { return One.isSignBitSet(); }
|
|
|
|
|
|
|
|
/// Returns true if this value is known to be non-negative.
|
|
|
|
bool isNonNegative() const { return Zero.isSignBitSet(); }
|
|
|
|
|
|
|
|
/// Make this value negative.
|
|
|
|
void makeNegative() {
|
|
|
|
assert(!isNonNegative() && "Can't make a non-negative value negative");
|
|
|
|
One.setSignBit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Make this value negative.
|
|
|
|
void makeNonNegative() {
|
|
|
|
assert(!isNegative() && "Can't make a negative value non-negative");
|
|
|
|
Zero.setSignBit();
|
|
|
|
}
|
2017-04-26 18:39:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|