1 //===- llvm/unittest/Support/KnownBitsTest.h - KnownBits tests ------------===//
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
7 //===----------------------------------------------------------------------===//
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"
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
) {
34 template <typename FnTy
>
35 void ForeachNumInKnownBits(const KnownBits
&Known
, FnTy Fn
) {
36 unsigned Bits
= Known
.getBitWidth();
38 unsigned Max
= 1u << Bits
;
39 unsigned Zero
= Known
.Zero
.getZExtValue();
40 unsigned One
= Known
.One
.getZExtValue();
43 // Known has a conflict. No values will satisfy it.
47 for (unsigned N
= 0; N
< Max
; ++N
) {
48 if ((N
& Zero
) == 0 && (~N
& One
) == 0)
53 } // end anonymous namespace