[clang] [CIR] Upstream global initialization for VectorType (PR #137511)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 28 09:49:24 PDT 2025
================
@@ -299,6 +299,94 @@ void ConstArrayAttr::print(AsmPrinter &printer) const {
printer << ">";
}
+//===----------------------------------------------------------------------===//
+// CIR ConstVectorAttr
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::ConstVectorAttr::verify(
+ function_ref<::mlir::InFlightDiagnostic()> emitError, Type type,
+ ArrayAttr elts) {
+
+ if (!mlir::isa<cir::VectorType>(type)) {
+ return emitError() << "type of cir::ConstVectorAttr is not a "
+ "cir::VectorType: "
+ << type;
+ }
+
+ const auto vecType = mlir::cast<cir::VectorType>(type);
+
+ if (vecType.getSize() != elts.size()) {
+ return emitError()
+ << "number of constant elements should match vector size";
+ }
+
+ // Check if the types of the elements match
+ LogicalResult elementTypeCheck = success();
+ elts.walkImmediateSubElements(
+ [&](Attribute element) {
+ if (elementTypeCheck.failed()) {
+ // An earlier element didn't match
+ return;
+ }
+ auto typedElement = mlir::dyn_cast<TypedAttr>(element);
+ if (!typedElement ||
+ typedElement.getType() != vecType.getElementType()) {
+ elementTypeCheck = failure();
+ emitError() << "constant type should match vector element type";
+ }
+ },
+ [&](Type) {});
+
+ return elementTypeCheck;
+}
+
+Attribute cir::ConstVectorAttr::parse(AsmParser &parser, Type type) {
----------------
andykaylor wrote:
You should add a test in clang/test/CIR/IR to verify this parser.
https://github.com/llvm/llvm-project/pull/137511
More information about the cfe-commits
mailing list