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 @@ -1444,9 +1444,21 @@ LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); /** - * Obtain the number of elements in a vector type. + * Create a vector type that contains a defined type and has a scalable + * number of elements. + * + * The created type will exist in the context thats its element type + * exists in. + * + * @see llvm::ScalableVectorType::get() + */ +LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType, + unsigned ElementCount); + +/** + * Obtain the (possibly scalable) number of elements in a vector type. * - * This only works on types that represent vectors. + * This only works on types that represent vectors (fixed or scalable). * * @see llvm::VectorType::getNumElements() */ 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 @@ -759,6 +759,11 @@ return wrap(FixedVectorType::get(unwrap(ElementType), ElementCount)); } +LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType, + unsigned ElementCount) { + return wrap(ScalableVectorType::get(unwrap(ElementType), ElementCount)); +} + LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy) { auto *Ty = unwrap(WrappedTy); if (auto *PTy = dyn_cast(Ty)) diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll --- a/llvm/test/Bindings/llvm-c/echo.ll +++ b/llvm/test/Bindings/llvm-c/echo.ll @@ -174,6 +174,19 @@ ret i32 %p } +define i32 @scalablevectorops(i32, ) { + %a = insertelement undef, i32 %0, i32 0 + %b = insertelement %a, i32 %0, i32 2 + %c = shufflevector %b, undef, zeroinitializer + %e = add %a, %1 + %f = mul %e, %b + %g = xor %f, %e + %h = or %g, %e + %i = lshr %h, undef + %j = extractelement %i, i32 3 + ret i32 %j +} + declare void @personalityFn() define void @exn() personality void ()* @personalityFn { 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 @@ -139,14 +139,14 @@ Clone(LLVMGetElementType(Src)), LLVMGetPointerAddressSpace(Src) ); - case LLVMScalableVectorTypeKind: - // FIXME: scalable vectors unsupported - break; case LLVMVectorTypeKind: return LLVMVectorType( Clone(LLVMGetElementType(Src)), LLVMGetVectorSize(Src) ); + case LLVMScalableVectorTypeKind: + return LLVMScalableVectorType(Clone(LLVMGetElementType(Src)), + LLVMGetVectorSize(Src)); case LLVMMetadataTypeKind: return LLVMMetadataTypeInContext(Ctx); case LLVMX86_MMXTypeKind: