Skip to content

Commit b258ba0

Browse files
author
Simon Moll
committed
[VP][wip] Prepare VPBuilder for scalable vector types
1 parent 6288f33 commit b258ba0

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

llvm/include/llvm/IR/VPBuilder.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class VPBuilder {
2020
// Explicit vector length parameter
2121
Value * ExplicitVectorLength;
2222
// Compile-time vector length
23-
int StaticVectorLength;
23+
ElementCount StaticVectorLength;
2424

2525
// get a valid mask/evl argument for the current predication contet
2626
Value& RequestPred();
@@ -31,7 +31,7 @@ class VPBuilder {
3131
: Builder(_builder)
3232
, Mask(nullptr)
3333
, ExplicitVectorLength(nullptr)
34-
, StaticVectorLength(-1)
34+
, StaticVectorLength(0, false)
3535
{}
3636

3737
Module & getModule() const;
@@ -41,9 +41,23 @@ class VPBuilder {
4141
VectorType& getVectorType(Type &ElementTy);
4242

4343
// Predication context tracker
44-
VPBuilder& setMask(Value * _Mask) { Mask = _Mask; return *this; }
45-
VPBuilder& setEVL(Value * _ExplicitVectorLength) { ExplicitVectorLength = _ExplicitVectorLength; return *this; }
46-
VPBuilder& setStaticVL(int VLen) { StaticVectorLength = VLen; return *this; }
44+
VPBuilder &setMask(Value *_Mask) {
45+
Mask = _Mask;
46+
return *this;
47+
}
48+
VPBuilder &setEVL(Value *_ExplicitVectorLength) {
49+
ExplicitVectorLength = _ExplicitVectorLength;
50+
return *this;
51+
}
52+
VPBuilder &setStaticVL(unsigned FixedVL) {
53+
StaticVectorLength = ElementCount(FixedVL, false);
54+
return *this;
55+
}
56+
VPBuilder &setStaticVL(ElementCount ScalableVL) {
57+
assert(false && "TODO implement vscale handling");
58+
StaticVectorLength = ScalableVL;
59+
return *this;
60+
}
4761

4862
// Create a map-vectorized copy of the instruction \p Inst with the underlying IRBuilder instance.
4963
// This operation may return nullptr if the instruction could not be vectorized.

llvm/lib/IR/VPBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Value &VPBuilder::RequestEVL() {
3030
if (ExplicitVectorLength)
3131
return *ExplicitVectorLength;
3232

33+
assert(!StaticVectorLength.Scalable && "TODO vscale lowering");
3334
auto *intTy = Builder.getInt32Ty();
34-
return *ConstantInt::get(intTy, StaticVectorLength);
35+
return *ConstantInt::get(intTy, StaticVectorLength.Min);
3536
}
3637

3738
Value *VPBuilder::CreateVectorCopy(Instruction &Inst, ValArray VecOpArray) {
@@ -164,7 +165,7 @@ Value &VPBuilder::CreateGather(Value &PointerVec, MaybeAlign AlignOpt) {
164165
auto &PointerVecTy = cast<VectorType>(*PointerVec.getType());
165166
auto &ElemTy = *cast<PointerType>(*PointerVecTy.getElementType())
166167
.getPointerElementType();
167-
auto &VecTy = *VectorType::get(&ElemTy, PointerVecTy.getNumElements());
168+
auto &VecTy = *VectorType::get(&ElemTy, PointerVecTy.getElementCount());
168169
auto *GatherFunc = Intrinsic::getDeclaration(
169170
&getModule(), Intrinsic::vp_gather, {&VecTy, &PointerVecTy});
170171

0 commit comments

Comments
 (0)