brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 807ce31 Raw
56 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements helpers for KnownBits and DemandedBits unit tests.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_UNITTESTS_SUPPORT_KNOWNBITSTEST_H14#define LLVM_UNITTESTS_SUPPORT_KNOWNBITSTEST_H15 16#include "llvm/Support/KnownBits.h"17 18namespace {19 20using namespace llvm;21 22template <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);30    }31  }32}33 34template <typename FnTy>35void 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();41 42  if (Zero & One) {43    // Known has a conflict. No values will satisfy it.44    return;45  }46 47  for (unsigned N = 0; N < Max; ++N) {48    if ((N & Zero) == 0 && (~N & One) == 0)49      Fn(APInt(Bits, N));50  }51}52 53} // end anonymous namespace54 55#endif56