diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -1434,17 +1434,30 @@ * * @see llvm::VectorType::get() */ -LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); +LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount, + LLVMBool Scalable); /** - * Obtain the number of elements in a vector type. + * Obtain the number of elements in a vector type. If the vector is scalable, + * then this is the minimum number of elements * * This only works on types that represent vectors. * - * @see llvm::VectorType::getNumElements() + * @see llvm::VectorType::getElementCount() + * @see llvm::ElementCount */ unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); +/** + * Return true if this vector is scalable + * + * This only works on types that represent vectors. + * + * @see llvm::VectorType::getElementCount() + * @see llvm::ElementCount + */ +LLVMBool LLVMGetVectorIsScalable(LLVMTypeRef VectorTy); + /** * @} */ diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -747,8 +747,10 @@ return wrap(PointerType::get(unwrap(ElementType), AddressSpace)); } -LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) { - return wrap(VectorType::get(unwrap(ElementType), ElementCount)); +LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount, + LLVMBool Scalable) { + return wrap(VectorType::get(unwrap(ElementType), + {ElementCount, static_cast(Scalable)})); } LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy) { @@ -773,7 +775,11 @@ } unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) { - return unwrap(VectorTy)->getNumElements(); + return unwrap(VectorTy)->getElementCount().Min; +} + +LLVMBool LLVMGetVectorIsScalable(LLVMTypeRef VectorTy) { + return unwrap(VectorTy)->getElementCount().Scalable; } /*--.. Operations on other types ...........................................--*/ diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c --- a/llvm/tools/llvm-c-test/debuginfo.c +++ b/llvm/tools/llvm-c-test/debuginfo.c @@ -92,11 +92,10 @@ LLVMAddNamedMetadataOperand(M, "FooType", LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy)); - LLVMTypeRef FooParamTys[] = { - LLVMInt64Type(), - LLVMInt64Type(), - LLVMVectorType(LLVMInt64Type(), 10), + LLVMInt64Type(), + LLVMInt64Type(), + LLVMVectorType(LLVMInt64Type(), 10, false), }; LLVMTypeRef FooFuncTy = LLVMFunctionType(LLVMInt64Type(), FooParamTys, 3, 0); LLVMValueRef FooFunction = LLVMAddFunction(M, "foo", FooFuncTy); diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -137,14 +137,11 @@ Clone(LLVMGetElementType(Src)), LLVMGetPointerAddressSpace(Src) ); - case LLVMScalableVectorTypeKind: - // FIXME: scalable vectors unsupported - break; case LLVMFixedVectorTypeKind: - return LLVMVectorType( - Clone(LLVMGetElementType(Src)), - LLVMGetVectorSize(Src) - ); + case LLVMScalableVectorTypeKind: + return LLVMVectorType(Clone(LLVMGetElementType(Src)), + LLVMGetVectorSize(Src), + LLVMGetVectorIsScalable(Src)); case LLVMMetadataTypeKind: return LLVMMetadataTypeInContext(Ctx); case LLVMX86_MMXTypeKind: