[llvm] [SandboxVec][BottomUpVec] Implement pack of scalars (PR #115549)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 14:37:48 PST 2024
================
@@ -108,6 +108,31 @@ class VecUtils {
}
return LowestI;
}
+ /// If all values in \p Bndl are of the same scalar type then return it,
+ /// otherwise return nullptr.
+ static Type *tryGetCommonScalarType(ArrayRef<Value *> Bndl) {
+ Value *V0 = Bndl[0];
+ Type *Ty0 = Utils::getExpectedType(V0);
+ Type *ScalarTy = VecUtils::getElementType(Ty0);
+ for (auto *V : drop_begin(Bndl)) {
+ Type *NTy = Utils::getExpectedType(V);
+ Type *NScalarTy = VecUtils::getElementType(NTy);
+ if (NScalarTy != ScalarTy)
+ return nullptr;
+ }
+ return ScalarTy;
+ }
+
+ /// Similar to tryGetCommonScalarType() but will assert that there is a common
+ /// type. So this is faster in release builds as it won't iterate through the
+ /// values.
+ static Type *getCommonScalarType(ArrayRef<Value *> Bndl) {
+ Value *V0 = Bndl[0];
+ Type *Ty0 = Utils::getExpectedType(V0);
+ Type *ScalarTy = VecUtils::getElementType(Ty0);
+ assert(tryGetCommonScalarType(Bndl) && "Expected common scalar type!");
+ return ScalarTy;
+ }
----------------
vporpo wrote:
`tryGetCommonScalarType(Bnd)` is expensive as it goes through the whole array so I want this to be enabled only as an assertion in the DEBUG build.
https://github.com/llvm/llvm-project/pull/115549
More information about the llvm-commits
mailing list