Content-Length: 365592 | pFad | http://github.com/llvm/clangir/commit/1982513c1105bf09fdf63262fed4cae42ac48a6d

C4 [CIR] Backport VectorType verifier (#1590) · llvm/clangir@1982513 · GitHub
Skip to content

Commit 1982513

Browse files
authored
[CIR] Backport VectorType verifier (#1590)
Backport `VectorType::verify` implementation with test for invalid cases
1 parent f22115a commit 1982513

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ def CIR_VectorType : CIR_Type<"Vector", "vector",
391391
let assemblyFormat = [{
392392
`<` $elementType `x` $size `>`
393393
}];
394+
395+
let genVerifyDecl = 1;
394396
}
395397

396398
//===----------------------------------------------------------------------===//

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,23 @@ cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
410410
return llvm::NextPowerOf2(dataLayout.getTypeSizeInBits(*this));
411411
}
412412

413+
mlir::LogicalResult cir::VectorType::verify(
414+
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
415+
mlir::Type elementType, uint64_t size) {
416+
if (size == 0)
417+
return emitError() << "the number of vector elements must be non-zero";
418+
419+
// Check if it a valid FixedVectorType
420+
if (mlir::isa<cir::PointerType, cir::FP128Type>(elementType))
421+
return success();
422+
423+
// Check if it a valid VectorType
424+
if (mlir::isa<cir::IntType>(elementType) ||
425+
isAnyFloatingPointType(elementType))
426+
return success();
427+
428+
return emitError() << "unsupported element type for CIR vector";
429+
}
413430
// TODO(cir): Implement a way to cache the datalayout info calculated below.
414431

415432
llvm::TypeSize
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!s32i = !cir.int<s, 32>
4+
5+
module {
6+
7+
// expected-error @below {{the number of vector elements must be non-zero}}
8+
cir.global external @vec_a = #cir.zero : !cir.vector<!s32i x 0>
9+
10+
}

clang/test/CIR/IR/invalid-vector.cir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!s32i = !cir.int<s, 32>
4+
5+
module {
6+
7+
// expected-error @below {{unsupported element type for CIR vector}}
8+
cir.global external @vec_b = #cir.zero : !cir.vector<!cir.array<!s32i x 10> x 4>
9+
10+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/llvm/clangir/commit/1982513c1105bf09fdf63262fed4cae42ac48a6d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy