1 | //===- VecUtils.cpp -------------------------------------------------------===// |
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 | #include "llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h" |
10 | |
11 | namespace llvm::sandboxir { |
12 | |
13 | unsigned VecUtils::getFloorPowerOf2(unsigned Num) { |
14 | if (Num == 0) |
15 | return Num; |
16 | unsigned Mask = Num; |
17 | Mask >>= 1; |
18 | for (unsigned ShiftBy = 1; ShiftBy < sizeof(Num) * 8; ShiftBy <<= 1) |
19 | Mask |= Mask >> ShiftBy; |
20 | return Num & ~Mask; |
21 | } |
22 | |
23 | #ifndef NDEBUG |
24 | template <typename T> static void dumpImpl(ArrayRef<T *> Bndl) { |
25 | for (auto [Idx, V] : enumerate(Bndl)) |
26 | dbgs() << Idx << "." << *V << "\n" ; |
27 | } |
28 | void VecUtils::dump(ArrayRef<Value *> Bndl) { dumpImpl(Bndl); } |
29 | void VecUtils::dump(ArrayRef<Instruction *> Bndl) { dumpImpl(Bndl); } |
30 | #endif // NDEBUG |
31 | |
32 | } // namespace llvm::sandboxir |
33 | |