23 Operation *op = v.getDefiningOp();
24 if (!op || depth == 5)
25 return KnownBits(v.getType().getIntOrFloatBitWidth());
28 if (
auto constant = dyn_cast<hw::ConstantOp>(op))
29 return KnownBits::makeConstant(constant.getValue());
32 if (
auto concatOp = dyn_cast<ConcatOp>(op)) {
34 for (
size_t i = 1, e = concatOp.getNumOperands(); i != e; ++i) {
36 unsigned width = otherBits.getBitWidth();
37 unsigned newWidth = result.getBitWidth() + width;
39 (result.Zero.zext(newWidth) << width) | otherBits.Zero.zext(newWidth);
41 (result.One.zext(newWidth) << width) | otherBits.One.zext(newWidth);
48 if (
auto extractOp = dyn_cast<ExtractOp>(op)) {
49 unsigned lowBit = extractOp.getLowBit();
50 unsigned width = extractOp.getType().getIntOrFloatBitWidth();
54 APInt inputZero = inputBits.Zero.lshr(lowBit);
55 APInt inputOne = inputBits.One.lshr(lowBit);
58 APInt knownZero = inputZero.trunc(width);
59 APInt knownOne = inputOne.trunc(width);
61 KnownBits result(width);
62 result.Zero = knownZero;
63 result.One = knownOne;
68 if (
auto andOp = dyn_cast<AndOp>(op)) {
70 for (
size_t i = 1, e = andOp.getNumOperands(); i != e; ++i)
76 if (
auto orOp = dyn_cast<OrOp>(op)) {
78 for (
size_t i = 1, e = orOp.getNumOperands(); i != e; ++i)
84 if (
auto xorOp = dyn_cast<XorOp>(op)) {
86 for (
size_t i = 1, e = xorOp.getNumOperands(); i != e; ++i) {
88 if (result.isUnknown())
96 if (
auto muxOp = dyn_cast<MuxOp>(op)) {
99 return lhs.intersectWith(rhs);
103 if (
auto shlOp = dyn_cast<ShlOp>(op)) {
106 auto res = KnownBits::shl(lhs, rhs);
111 if (
auto shrOp = dyn_cast<ShrUOp>(op)) {
114 auto res = KnownBits::lshr(lhs, rhs);
118 return KnownBits(v.getType().getIntOrFloatBitWidth());