Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / Support / KnownBitsTest.h
blob807ce31381efbf4e37e9e4a53594a52042c53dc7
1 //===- llvm/unittest/Support/KnownBitsTest.h - KnownBits tests ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements helpers for KnownBits and DemandedBits unit tests.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_UNITTESTS_SUPPORT_KNOWNBITSTEST_H
14 #define LLVM_UNITTESTS_SUPPORT_KNOWNBITSTEST_H
16 #include "llvm/Support/KnownBits.h"
18 namespace {
20 using namespace llvm;
22 template <typename FnTy> void ForeachKnownBits(unsigned Bits, FnTy Fn) {
23 unsigned Max = 1 << Bits;
24 KnownBits Known(Bits);
25 for (unsigned Zero = 0; Zero < Max; ++Zero) {
26 for (unsigned One = 0; One < Max; ++One) {
27 Known.Zero = Zero;
28 Known.One = One;
29 Fn(Known);
34 template <typename FnTy>
35 void ForeachNumInKnownBits(const KnownBits &Known, FnTy Fn) {
36 unsigned Bits = Known.getBitWidth();
37 assert(Bits < 32);
38 unsigned Max = 1u << Bits;
39 unsigned Zero = Known.Zero.getZExtValue();
40 unsigned One = Known.One.getZExtValue();
42 if (Zero & One) {
43 // Known has a conflict. No values will satisfy it.
44 return;
47 for (unsigned N = 0; N < Max; ++N) {
48 if ((N & Zero) == 0 && (~N & One) == 0)
49 Fn(APInt(Bits, N));
53 } // end anonymous namespace
55 #endif