33 lines
1.0 KiB
C++
33 lines
1.0 KiB
C++
//===- VecUtils.cpp -------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h"
|
|
|
|
namespace llvm::sandboxir {
|
|
|
|
unsigned VecUtils::getFloorPowerOf2(unsigned Num) {
|
|
if (Num == 0)
|
|
return Num;
|
|
unsigned Mask = Num;
|
|
Mask >>= 1;
|
|
for (unsigned ShiftBy = 1; ShiftBy < sizeof(Num) * 8; ShiftBy <<= 1)
|
|
Mask |= Mask >> ShiftBy;
|
|
return Num & ~Mask;
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
template <typename T> static void dumpImpl(ArrayRef<T *> Bndl) {
|
|
for (auto [Idx, V] : enumerate(Bndl))
|
|
dbgs() << Idx << "." << *V << "\n";
|
|
}
|
|
void VecUtils::dump(ArrayRef<Value *> Bndl) { dumpImpl(Bndl); }
|
|
void VecUtils::dump(ArrayRef<Instruction *> Bndl) { dumpImpl(Bndl); }
|
|
#endif // NDEBUG
|
|
|
|
} // namespace llvm::sandboxir
|