Skip to content

Commit

Permalink
[SandboxVec][VecUtils][NFC] Move functions to VecUtils.cpp and add a …
Browse files Browse the repository at this point in the history
…VecUtils::dump()
  • Loading branch information
vporpo committed Jan 17, 2025
1 parent 10fdd09 commit 128e2e4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ class VecUtils {
return ScalarTy;
}
/// \Returns the first integer power of 2 that is <= Num.
static unsigned 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;
}
static unsigned getFloorPowerOf2(unsigned Num);

#ifndef NDEBUG
/// Helper dump function for debugging.
LLVM_DUMP_METHOD static void dump(ArrayRef<Value *> Bndl);
LLVM_DUMP_METHOD static void dump(ArrayRef<Instruction *> Bndl);
#endif // NDEBUG
};

} // namespace llvm::sandboxir
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_llvm_component_library(LLVMVectorize
SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
SandboxVectorizer/Scheduler.cpp
SandboxVectorizer/SeedCollector.cpp
SandboxVectorizer/VecUtils.cpp
SLPVectorizer.cpp
Vectorize.cpp
VectorCombine.cpp
Expand Down
32 changes: 32 additions & 0 deletions llvm/lib/Transforms/Vectorize/SandboxVectorizer/VecUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- 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

0 comments on commit 128e2e4

Please sign in to comment.