Skip to content

Commit 128e2e4

Browse files
committed
[SandboxVec][VecUtils][NFC] Move functions to VecUtils.cpp and add a VecUtils::dump()
1 parent 10fdd09 commit 128e2e4

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,13 @@ class VecUtils {
134134
return ScalarTy;
135135
}
136136
/// \Returns the first integer power of 2 that is <= Num.
137-
static unsigned getFloorPowerOf2(unsigned Num) {
138-
if (Num == 0)
139-
return Num;
140-
unsigned Mask = Num;
141-
Mask >>= 1;
142-
for (unsigned ShiftBy = 1; ShiftBy < sizeof(Num) * 8; ShiftBy <<= 1)
143-
Mask |= Mask >> ShiftBy;
144-
return Num & ~Mask;
145-
}
137+
static unsigned getFloorPowerOf2(unsigned Num);
138+
139+
#ifndef NDEBUG
140+
/// Helper dump function for debugging.
141+
LLVM_DUMP_METHOD static void dump(ArrayRef<Value *> Bndl);
142+
LLVM_DUMP_METHOD static void dump(ArrayRef<Instruction *> Bndl);
143+
#endif // NDEBUG
146144
};
147145

148146
} // namespace llvm::sandboxir

llvm/lib/Transforms/Vectorize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_llvm_component_library(LLVMVectorize
1313
SandboxVectorizer/SandboxVectorizerPassBuilder.cpp
1414
SandboxVectorizer/Scheduler.cpp
1515
SandboxVectorizer/SeedCollector.cpp
16+
SandboxVectorizer/VecUtils.cpp
1617
SLPVectorizer.cpp
1718
Vectorize.cpp
1819
VectorCombine.cpp
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

0 commit comments

Comments
 (0)