Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions mlir/include/mlir/IR/VectorTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===- VectorTypes.h - MLIR Vector Types ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_DIALECT_VECTOR_IR_VECTORTYPES_H_
#define MLIR_DIALECT_VECTOR_IR_VECTORTYPES_H_

#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Types.h"

namespace mlir {
namespace vector {

/// A vector type containing at least one scalable dimension.
class ScalableVectorType : public VectorType {
public:
using VectorType::VectorType;

static bool classof(Type type) {
auto vecTy = llvm::dyn_cast<VectorType>(type);
if (!vecTy)
return false;
return vecTy.isScalable();
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need something akin to resolveTypeID? I saw that @joker-eph added those for ops in #87170 but I'm not sure if the same thing applies to types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem to only be required for operations for now I believe. Worst case they could probably be easy to make available using using VectorType::resolveTypeID;


/// A vector type with no scalable dimensions.
class FixedVectorType : public VectorType {
public:
using VectorType::VectorType;
static bool classof(Type type) {
auto vecTy = llvm::dyn_cast<VectorType>(type);
if (!vecTy)
return false;
return !vecTy.isScalable();
}
};

} // namespace vector
} // namespace mlir

#endif // MLIR_DIALECT_VECTOR_IR_VECTORTYPES_H_
6 changes: 4 additions & 2 deletions mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/IR/VectorTypes.h"
#include "mlir/Support/LogicalResult.h"

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
Expand Down Expand Up @@ -224,8 +226,8 @@ LogicalResult arith::ConstantOp::verify() {
// Note, we could relax this for vectors with 1 scalable dim, e.g.:
// * arith.constant dense<[[3, 3], [1, 1]]> : vector<2 x [2] x i32>
// However, this would most likely require updating the lowerings to LLVM.
auto vecType = dyn_cast<VectorType>(type);
if (vecType && vecType.isScalable() && !isa<SplatElementsAttr>(getValue()))
if (isa<vector::ScalableVectorType>(type) &&
!isa<SplatElementsAttr>(getValue()))
return emitOpError(
"intializing scalable vectors with elements attribute is not supported"
" unless it's a vector splat");
Expand Down