-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Upstream initial support for fixed size VectorType #136488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d2c63cd
20050b6
151417e
aa484d1
a1e84f3
1ee2eb2
64ef173
4976855
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -652,7 +652,7 @@ BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | |
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Definitions | ||
// ArrayType Definitions | ||
//===----------------------------------------------------------------------===// | ||
|
||
llvm::TypeSize | ||
|
@@ -667,6 +667,41 @@ ArrayType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | |
return dataLayout.getTypeABIAlignment(getEltType()); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// VectorType Definitions | ||
//===----------------------------------------------------------------------===// | ||
|
||
llvm::TypeSize cir::VectorType::getTypeSizeInBits( | ||
const ::mlir::DataLayout &dataLayout, | ||
::mlir::DataLayoutEntryListRef params) const { | ||
return llvm::TypeSize::getFixed( | ||
getSize() * dataLayout.getTypeSizeInBits(getElementType())); | ||
} | ||
|
||
uint64_t | ||
cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | ||
::mlir::DataLayoutEntryListRef params) const { | ||
return llvm::NextPowerOf2(dataLayout.getTypeSizeInBits(*this)); | ||
} | ||
|
||
mlir::LogicalResult cir::VectorType::verify( | ||
llvm::function_ref<mlir::InFlightDiagnostic()> emitError, | ||
mlir::Type elementType, uint64_t size) { | ||
if (size == 0) | ||
return emitError() << "the number of vector elements must be non-zero"; | ||
|
||
// Check if it a valid FixedVectorType | ||
if (mlir::isa<cir::PointerType, cir::FP128Type>(elementType)) | ||
return success(); | ||
|
||
// Check if it a valid VectorType | ||
if (mlir::isa<cir::IntType>(elementType) || | ||
isAnyFloatingPointType(elementType)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this check in
So that's not necessarily compatible with On the other hand, I'd like to be able to create CIR vectors of other types like float8 without requiring that the LLVM dialect support them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmmmm maybe we should put our checks like it isa (Int, Index, Ptr, Float) 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My suggestion is to stay out of using LLVM dialect directly besides lowering, my reasons include:
|
||
return success(); | ||
|
||
return emitError() << "unsupported element type for CIR vector"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// PointerType Definitions | ||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll | ||
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG | ||
|
||
typedef int vi4 __attribute__((ext_vector_type(4))); | ||
typedef int vi3 __attribute__((ext_vector_type(3))); | ||
typedef int vi2 __attribute__((ext_vector_type(2))); | ||
typedef double vd2 __attribute__((ext_vector_type(2))); | ||
|
||
vi4 vec_a; | ||
// CIR: cir.global external @[[VEC_A:.*]] = #cir.zero : !cir.vector<4 x !s32i> | ||
|
||
// LLVM: @[[VEC_A:.*]] = dso_local global <4 x i32> zeroinitializer | ||
|
||
// OGCG: @[[VEC_A:.*]] = global <4 x i32> zeroinitializer | ||
|
||
vi3 vec_b; | ||
// CIR: cir.global external @[[VEC_B:.*]] = #cir.zero : !cir.vector<3 x !s32i> | ||
|
||
// LLVM: @[[VEC_B:.*]] = dso_local global <3 x i32> zeroinitializer | ||
|
||
// OGCG: @[[VEC_B:.*]] = global <3 x i32> zeroinitializer | ||
|
||
vi2 vec_c; | ||
// CIR: cir.global external @[[VEC_C:.*]] = #cir.zero : !cir.vector<2 x !s32i> | ||
|
||
// LLVM: @[[VEC_C:.*]] = dso_local global <2 x i32> zeroinitializer | ||
|
||
// OGCG: @[[VEC_C:.*]] = global <2 x i32> zeroinitializer | ||
|
||
vd2 d; | ||
|
||
// CIR: cir.global external @[[VEC_D:.*]] = #cir.zero : !cir.vector<2 x !cir.double> | ||
|
||
// LLVM: @[[VEC_D:.*]] = dso_local global <2 x double> zeroinitialize | ||
|
||
// OGCG: @[[VEC_D:.*]] = global <2 x double> zeroinitializer | ||
|
||
void foo() { | ||
vi4 a; | ||
vi3 b; | ||
vi2 c; | ||
vd2 d; | ||
} | ||
|
||
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"] | ||
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<3 x !s32i>, !cir.ptr<!cir.vector<3 x !s32i>>, ["b"] | ||
// CIR: %[[VEC_C:.*]] = cir.alloca !cir.vector<2 x !s32i>, !cir.ptr<!cir.vector<2 x !s32i>>, ["c"] | ||
// CIR: %[[VEC_D:.*]] = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["d"] | ||
|
||
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16 | ||
// LLVM: %[[VEC_B:.*]] = alloca <3 x i32>, i64 1, align 16 | ||
// LLVM: %[[VEC_C:.*]] = alloca <2 x i32>, i64 1, align 8 | ||
// LLVM: %[[VEC_D:.*]] = alloca <2 x double>, i64 1, align 16 | ||
|
||
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16 | ||
// OGCG: %[[VEC_B:.*]] = alloca <3 x i32>, align 16 | ||
// OGCG: %[[VEC_C:.*]] = alloca <2 x i32>, align 8 | ||
// OGCG: %[[VEC_D:.*]] = alloca <2 x double>, align 16 | ||
|
||
void foo2(vi4 p) {} | ||
|
||
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["p", init] | ||
// CIR: cir.store %{{.*}}, %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>> | ||
|
||
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16 | ||
// LLVM: store <4 x i32> %{{.*}}, ptr %[[VEC_A]], align 16 | ||
|
||
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16 | ||
// OGCG: store <4 x i32> %{{.*}}, ptr %[[VEC_A]], align 16 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll | ||
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG | ||
|
||
typedef int vi4 __attribute__((vector_size(16))); | ||
typedef double vd2 __attribute__((vector_size(16))); | ||
typedef long long vll2 __attribute__((vector_size(16))); | ||
|
||
vi4 vec_a; | ||
// CIR: cir.global external @[[VEC_A:.*]] = #cir.zero : !cir.vector<4 x !s32i> | ||
|
||
// LLVM: @[[VEC_A:.*]] = dso_local global <4 x i32> zeroinitializer | ||
|
||
// OGCG: @[[VEC_A:.*]] = global <4 x i32> zeroinitializer | ||
|
||
vd2 b; | ||
// CIR: cir.global external @[[VEC_B:.*]] = #cir.zero : !cir.vector<2 x !cir.double> | ||
|
||
// LLVM: @[[VEC_B:.*]] = dso_local global <2 x double> zeroinitialize | ||
|
||
// OGCG: @[[VEC_B:.*]] = global <2 x double> zeroinitializer | ||
|
||
vll2 c; | ||
// CIR: cir.global external @[[VEC_C:.*]] = #cir.zero : !cir.vector<2 x !s64i> | ||
|
||
// LLVM: @[[VEC_C:.*]] = dso_local global <2 x i64> zeroinitialize | ||
|
||
// OGCG: @[[VEC_C:.*]] = global <2 x i64> zeroinitializer | ||
|
||
void vec_int_test() { | ||
vi4 a; | ||
vd2 b; | ||
vll2 c; | ||
} | ||
|
||
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"] | ||
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["b"] | ||
// CIR: %[[VEC_C:.*]] = cir.alloca !cir.vector<2 x !s64i>, !cir.ptr<!cir.vector<2 x !s64i>>, ["c"] | ||
|
||
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16 | ||
// LLVM: %[[VEC_B:.*]] = alloca <2 x double>, i64 1, align 16 | ||
// LLVM: %[[VEC_C:.*]] = alloca <2 x i64>, i64 1, align 16 | ||
|
||
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16 | ||
// OGCG: %[[VEC_B:.*]] = alloca <2 x double>, align 16 | ||
// OGCG: %[[VEC_C:.*]] = alloca <2 x i64>, align 16 | ||
|
||
void foo2(vi4 p) {} | ||
|
||
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["p", init] | ||
// CIR: cir.store %{{.*}}, %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>> | ||
|
||
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16 | ||
// LLVM: store <4 x i32> %{{.*}}, ptr %[[VEC_A]], align 16 | ||
|
||
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16 | ||
// OGCG: store <4 x i32> %{{.*}}, ptr %[[VEC_A]], align 16 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: cir-opt %s -verify-diagnostics -split-input-file | ||
|
||
!s32i = !cir.int<s, 32> | ||
|
||
module { | ||
|
||
// expected-error @below {{the number of vector elements must be non-zero}} | ||
cir.global external @vec_a = #cir.zero : !cir.vector<0 x !s32i> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: cir-opt %s -verify-diagnostics -split-input-file | ||
|
||
!s32i = !cir.int<s, 32> | ||
|
||
module { | ||
|
||
// expected-error @below {{unsupported element type for CIR vector}} | ||
cir.global external @vec_b = #cir.zero : !cir.vector<4 x !cir.array<!s32i x 10>> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: cir-opt %s | FileCheck %s | ||
|
||
!s32i = !cir.int<s, 32> | ||
|
||
module { | ||
|
||
cir.global external @vec_a = #cir.zero : !cir.vector<4 x !s32i> | ||
// CHECK: cir.global external @vec_a = #cir.zero : !cir.vector<4 x !s32i> | ||
|
||
cir.global external @vec_b = #cir.zero : !cir.vector<3 x !s32i> | ||
// CHECK: cir.global external @vec_b = #cir.zero : !cir.vector<3 x !s32i> | ||
|
||
cir.global external @vec_c = #cir.zero : !cir.vector<2 x !s32i> | ||
// CHECK: cir.global external @vec_c = #cir.zero : !cir.vector<2 x !s32i> | ||
|
||
cir.func @vec_int_test() { | ||
%0 = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"] | ||
%1 = cir.alloca !cir.vector<3 x !s32i>, !cir.ptr<!cir.vector<3 x !s32i>>, ["b"] | ||
%2 = cir.alloca !cir.vector<2 x !s32i>, !cir.ptr<!cir.vector<2 x !s32i>>, ["c"] | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @vec_int_test() { | ||
// CHECK: %0 = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"] | ||
// CHECK: %1 = cir.alloca !cir.vector<3 x !s32i>, !cir.ptr<!cir.vector<3 x !s32i>>, ["b"] | ||
// CHECK: %2 = cir.alloca !cir.vector<2 x !s32i>, !cir.ptr<!cir.vector<2 x !s32i>>, ["c"] | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
cir.func @vec_double_test() { | ||
%0 = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["a"] | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @vec_double_test() { | ||
// CHECK: %0 = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["a"] | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.