[PATCH] D89816: C API: support scalable vectors
Craig Disselkoen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 20 12:27:38 PDT 2020
cdisselkoen created this revision.
cdisselkoen added reviewers: CodaFi, efriedma.
Herald added a reviewer: deadalnix.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
cdisselkoen requested review of this revision.
This adds support for scalable vector types in the C API and in
llvm-c-test, and also adds a test to ensure that llvm-c-test can properly
roundtrip operations involving scalable vectors.
While creating this diff, I discovered that the C API cannot properly roundtrip
_constant expressions_ involving shufflevector / scalable vectors, but that
seems to be a separate enough issue that I plan to address it in a future diff
(unless reviewers feel it should be addressed here).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89816
Files:
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
llvm/test/Bindings/llvm-c/echo.ll
llvm/tools/llvm-c-test/echo.cpp
Index: llvm/tools/llvm-c-test/echo.cpp
===================================================================
--- llvm/tools/llvm-c-test/echo.cpp
+++ 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:
Index: llvm/test/Bindings/llvm-c/echo.ll
===================================================================
--- llvm/test/Bindings/llvm-c/echo.ll
+++ llvm/test/Bindings/llvm-c/echo.ll
@@ -174,6 +174,19 @@
ret i32 %p
}
+define i32 @scalablevectorops(i32, <vscale x 4 x i32>) {
+ %a = insertelement <vscale x 4 x i32> undef, i32 %0, i32 0
+ %b = insertelement <vscale x 4 x i32> %a, i32 %0, i32 2
+ %c = shufflevector <vscale x 4 x i32> %b, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
+ %e = add <vscale x 4 x i32> %a, %1
+ %f = mul <vscale x 4 x i32> %e, %b
+ %g = xor <vscale x 4 x i32> %f, %e
+ %h = or <vscale x 4 x i32> %g, %e
+ %i = lshr <vscale x 4 x i32> %h, undef
+ %j = extractelement <vscale x 4 x i32> %i, i32 3
+ ret i32 %j
+}
+
declare void @personalityFn()
define void @exn() personality void ()* @personalityFn {
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ 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<Type>(WrappedTy);
if (auto *PTy = dyn_cast<PointerType>(Ty))
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ 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()
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89816.299440.patch
Type: text/x-patch
Size: 3243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201020/664065a8/attachment.bin>
More information about the llvm-commits
mailing list