[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / Support / KnownBitsTest.h
blobbc291898814bd1e87995b05c3c9327c4278a2976
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 if (Known.hasConflict())
30 continue;
32 Fn(Known);
37 template <typename FnTy>
38 void ForeachNumInKnownBits(const KnownBits &Known, FnTy Fn) {
39 unsigned Bits = Known.getBitWidth();
40 unsigned Max = 1 << Bits;
41 for (unsigned N = 0; N < Max; ++N) {
42 APInt Num(Bits, N);
43 if ((Num & Known.Zero) != 0 || (~Num & Known.One) != 0)
44 continue;
46 Fn(Num);
50 } // end anonymous namespace
52 #endif