Skip to content

Commit e9b67d1

Browse files
delete scalable vec type
1 parent 44cfa13 commit e9b67d1

File tree

13 files changed

+29
-236
lines changed

13 files changed

+29
-236
lines changed

mlir/docs/Dialects/LLVM.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,7 @@ multiple of some fixed size in case of _scalable_ vectors, and the element type.
327327
Vectors cannot be nested and only 1D vectors are supported. Scalable vectors are
328328
still considered 1D.
329329

330-
The LLVM dialect uses built-in vector types for _fixed_-size vectors of built-in
331-
types, and provides additional types for scalable vectors of any types
332-
(`LLVMScalableVectorType`):
333-
334-
```
335-
llvm-vec-type ::= `!llvm.vec<` (`?` `x`)? integer-literal `x` type `>`
336-
```
337-
338-
Note that the sets of element types supported by built-in and LLVM dialect
339-
vector types are mutually exclusive, e.g., the built-in vector type does not
340-
accept `!llvm.ptr` and the LLVM dialect fixed-width vector type does not
341-
accept `i32`.
330+
The LLVM dialect uses built-in vector type.
342331

343332
The following functions are provided to operate on any kind of the vector types
344333
compatible with the LLVM dialect:
@@ -358,8 +347,8 @@ compatible with the LLVM dialect:
358347

359348
```mlir
360349
vector<42 x i32> // Vector of 42 32-bit integers.
361-
!llvm.vec<42 x ptr> // Vector of 42 pointers.
362-
!llvm.vec<? x 4 x i32> // Scalable vector of 32-bit integers with
350+
vector<42 x !llvm.ptr> // Vector of 42 pointers.
351+
vector<[4] x i32> // Scalable vector of 32-bit integers with
363352
// size divisible by 4.
364353
!llvm.array<2 x vector<2 x i32>> // Array of 2 vectors of 2 32-bit integers.
365354
!llvm.array<2 x vec<2 x ptr>> // Array of 2 vectors of 2 pointers.

mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -289,38 +289,6 @@ def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [
289289
];
290290
}
291291

292-
//===----------------------------------------------------------------------===//
293-
// LLVMScalableVectorType
294-
//===----------------------------------------------------------------------===//
295-
296-
def LLVMScalableVectorType : LLVMType<"LLVMScalableVector", "vec"> {
297-
let summary = "LLVM scalable vector type";
298-
let description = [{
299-
LLVM dialect scalable vector type, represents a sequence of elements of
300-
unknown length that is known to be divisible by some constant. These
301-
elements can be processed as one in SIMD context.
302-
}];
303-
304-
let typeName = "llvm.scalable_vec";
305-
306-
let parameters = (ins "Type":$elementType, "unsigned":$minNumElements);
307-
let assemblyFormat = [{
308-
`<` `?` `x` $minNumElements `x` ` ` custom<PrettyLLVMType>($elementType) `>`
309-
}];
310-
311-
let genVerifyDecl = 1;
312-
313-
let builders = [
314-
TypeBuilderWithInferredContext<(ins "Type":$elementType,
315-
"unsigned":$minNumElements)>
316-
];
317-
318-
let extraClassDeclaration = [{
319-
/// Checks if the given type can be used in a vector type.
320-
static bool isValidElementType(Type type);
321-
}];
322-
}
323-
324292
//===----------------------------------------------------------------------===//
325293
// LLVMTargetExtType
326294
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,6 @@ GEPIndicesAdaptor<ValueRange> GEPOp::getIndices() {
684684
static Type extractVectorElementType(Type type) {
685685
if (auto vectorType = llvm::dyn_cast<VectorType>(type))
686686
return vectorType.getElementType();
687-
if (auto scalableVectorType = llvm::dyn_cast<LLVMScalableVectorType>(type))
688-
return scalableVectorType.getElementType();
689687
return type;
690688
}
691689

@@ -723,10 +721,9 @@ static void destructureIndices(Type currType, ArrayRef<GEPArg> indices,
723721
continue;
724722

725723
currType = TypeSwitch<Type, Type>(currType)
726-
.Case<VectorType, LLVMScalableVectorType, LLVMArrayType>(
727-
[](auto containerType) {
728-
return containerType.getElementType();
729-
})
724+
.Case<VectorType, LLVMArrayType>([](auto containerType) {
725+
return containerType.getElementType();
726+
})
730727
.Case([&](LLVMStructType structType) -> Type {
731728
int64_t memberIndex = rawConstantIndices.back();
732729
if (memberIndex >= 0 && static_cast<size_t>(memberIndex) <
@@ -835,7 +832,7 @@ verifyStructIndices(Type baseGEPType, unsigned indexPos,
835832
return verifyStructIndices(elementTypes[gepIndex], indexPos + 1,
836833
indices, emitOpError);
837834
})
838-
.Case<VectorType, LLVMScalableVectorType, LLVMArrayType>(
835+
.Case<VectorType, LLVMArrayType>(
839836
[&](auto containerType) -> LogicalResult {
840837
return verifyStructIndices(containerType.getElementType(),
841838
indexPos + 1, indices, emitOpError);
@@ -3113,16 +3110,12 @@ static int64_t getNumElements(Type t) {
31133110
if (auto arrayType = dyn_cast<LLVM::LLVMArrayType>(t))
31143111
return arrayType.getNumElements() *
31153112
getNumElements(arrayType.getElementType());
3116-
assert(!isa<LLVM::LLVMScalableVectorType>(t) &&
3117-
"number of elements of a scalable vector type is unknown");
31183113
return 1;
31193114
}
31203115

31213116
/// Check if the given type is a scalable vector type or a vector/array type
31223117
/// that contains a nested scalable vector type.
31233118
static bool hasScalableVectorType(Type t) {
3124-
if (isa<LLVM::LLVMScalableVectorType>(t))
3125-
return true;
31263119
if (auto vecType = dyn_cast<VectorType>(t)) {
31273120
if (vecType.isScalable())
31283121
return true;
@@ -3458,7 +3451,7 @@ LogicalResult LLVM::BitcastOp::verify() {
34583451
if (!resultType)
34593452
return success();
34603453

3461-
auto isVector = llvm::IsaPred<VectorType, LLVMScalableVectorType>;
3454+
auto isVector = llvm::IsaPred<VectorType>;
34623455

34633456
// Due to bitcast requiring both operands to be of the same size, it is not
34643457
// possible for only one of the two to be a pointer of vectors.

mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ static bool isSupportedTypeForConversion(Type type) {
134134
if (isa<LLVM::LLVMStructType, LLVM::LLVMArrayType>(type))
135135
return false;
136136

137-
// LLVM vector types are only used for either pointers or target specific
138-
// types. These types cannot be casted in the general case, thus the memory
139-
// optimizations do not support them.
140-
if (isa<LLVM::LLVMScalableVectorType>(type))
141-
return false;
142-
143137
if (auto vectorType = dyn_cast<VectorType>(type)) {
144138
// Vectors of pointers cannot be casted.
145139
if (isa<LLVM::LLVMPointerType>(vectorType.getElementType()))

mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static StringRef getTypeKeyword(Type type) {
4040
.Case<LLVMMetadataType>([&](Type) { return "metadata"; })
4141
.Case<LLVMFunctionType>([&](Type) { return "func"; })
4242
.Case<LLVMPointerType>([&](Type) { return "ptr"; })
43-
.Case<LLVMScalableVectorType>([&](Type) { return "vec"; })
4443
.Case<LLVMArrayType>([&](Type) { return "array"; })
4544
.Case<LLVMStructType>([&](Type) { return "struct"; })
4645
.Case<LLVMTargetExtType>([&](Type) { return "target"; })
@@ -103,9 +102,8 @@ void mlir::LLVM::detail::printType(Type type, AsmPrinter &printer) {
103102
printer << getTypeKeyword(type);
104103

105104
llvm::TypeSwitch<Type>(type)
106-
.Case<LLVMPointerType, LLVMArrayType, LLVMScalableVectorType,
107-
LLVMFunctionType, LLVMTargetExtType, LLVMStructType>(
108-
[&](auto type) { type.print(printer); });
105+
.Case<LLVMPointerType, LLVMArrayType, LLVMFunctionType, LLVMTargetExtType,
106+
LLVMStructType>([&](auto type) { type.print(printer); });
109107
}
110108

111109
//===----------------------------------------------------------------------===//
@@ -114,41 +112,6 @@ void mlir::LLVM::detail::printType(Type type, AsmPrinter &printer) {
114112

115113
static ParseResult dispatchParse(AsmParser &parser, Type &type);
116114

117-
/// Parses an LLVM dialect vector type.
118-
/// llvm-type ::= `vec<` `? x`? integer `x` llvm-type `>`
119-
/// Supports both fixed and scalable vectors.
120-
static Type parseVectorType(AsmParser &parser) {
121-
SmallVector<int64_t, 2> dims;
122-
SMLoc dimPos, typePos;
123-
Type elementType;
124-
SMLoc loc = parser.getCurrentLocation();
125-
if (parser.parseLess() || parser.getCurrentLocation(&dimPos) ||
126-
parser.parseDimensionList(dims, /*allowDynamic=*/true) ||
127-
parser.getCurrentLocation(&typePos) ||
128-
dispatchParse(parser, elementType) || parser.parseGreater())
129-
return Type();
130-
131-
// We parsed a generic dimension list, but vectors only support two forms:
132-
// - single non-dynamic entry in the list (fixed vector);
133-
// - two elements, the first dynamic (indicated by ShapedType::kDynamic)
134-
// and the second
135-
// non-dynamic (scalable vector).
136-
if (dims.empty() || dims.size() > 2 ||
137-
((dims.size() == 2) ^ (ShapedType::isDynamic(dims[0]))) ||
138-
(dims.size() == 2 && ShapedType::isDynamic(dims[1]))) {
139-
parser.emitError(dimPos)
140-
<< "expected '? x <integer> x <type>' or '<integer> x <type>'";
141-
return Type();
142-
}
143-
144-
bool isScalable = dims.size() == 2;
145-
if (!isScalable) {
146-
parser.emitError(dimPos) << "expected scalable vector";
147-
return Type();
148-
}
149-
return parser.getChecked<LLVMScalableVectorType>(loc, elementType, dims[1]);
150-
}
151-
152115
/// Attempts to set the body of an identified structure type. Reports a parsing
153116
/// error at `subtypesLoc` in case of failure.
154117
static LLVMStructType trySetStructBody(LLVMStructType type,
@@ -307,7 +270,6 @@ static Type dispatchParse(AsmParser &parser, bool allowAny = true) {
307270
.Case("metadata", [&] { return LLVMMetadataType::get(ctx); })
308271
.Case("func", [&] { return LLVMFunctionType::parse(parser); })
309272
.Case("ptr", [&] { return LLVMPointerType::parse(parser); })
310-
.Case("vec", [&] { return parseVectorType(parser); })
311273
.Case("array", [&] { return LLVMArrayType::parse(parser); })
312274
.Case("struct", [&] { return LLVMStructType::parse(parser); })
313275
.Case("target", [&] { return LLVMTargetExtType::parse(parser); })

mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp

Lines changed: 7 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ generatedTypePrinter(Type def, AsmPrinter &printer);
150150

151151
bool LLVMArrayType::isValidElementType(Type type) {
152152
return !llvm::isa<LLVMVoidType, LLVMLabelType, LLVMMetadataType,
153-
LLVMFunctionType, LLVMTokenType, LLVMScalableVectorType>(
154-
type);
153+
LLVMFunctionType, LLVMTokenType>(type);
155154
}
156155

157156
LLVMArrayType LLVMArrayType::get(Type elementType, uint64_t numElements) {
@@ -657,53 +656,6 @@ LogicalResult LLVMStructType::verifyEntries(DataLayoutEntryListRef entries,
657656
return mlir::success();
658657
}
659658

660-
//===----------------------------------------------------------------------===//
661-
// LLVMScalableVectorType.
662-
//===----------------------------------------------------------------------===//
663-
664-
/// Verifies that the type about to be constructed is well-formed.
665-
template <typename VecTy>
666-
static LogicalResult
667-
verifyVectorConstructionInvariants(function_ref<InFlightDiagnostic()> emitError,
668-
Type elementType, unsigned numElements) {
669-
if (numElements == 0)
670-
return emitError() << "the number of vector elements must be positive";
671-
672-
if (!VecTy::isValidElementType(elementType))
673-
return emitError() << "invalid vector element type";
674-
675-
return success();
676-
}
677-
678-
LLVMScalableVectorType LLVMScalableVectorType::get(Type elementType,
679-
unsigned minNumElements) {
680-
assert(elementType && "expected non-null subtype");
681-
return Base::get(elementType.getContext(), elementType, minNumElements);
682-
}
683-
684-
LLVMScalableVectorType
685-
LLVMScalableVectorType::getChecked(function_ref<InFlightDiagnostic()> emitError,
686-
Type elementType, unsigned minNumElements) {
687-
assert(elementType && "expected non-null subtype");
688-
return Base::getChecked(emitError, elementType.getContext(), elementType,
689-
minNumElements);
690-
}
691-
692-
bool LLVMScalableVectorType::isValidElementType(Type type) {
693-
if (auto intType = llvm::dyn_cast<IntegerType>(type))
694-
return intType.isSignless();
695-
696-
return isCompatibleFloatingPointType(type) ||
697-
llvm::isa<LLVMPointerType>(type);
698-
}
699-
700-
LogicalResult
701-
LLVMScalableVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
702-
Type elementType, unsigned numElements) {
703-
return verifyVectorConstructionInvariants<LLVMScalableVectorType>(
704-
emitError, elementType, numElements);
705-
}
706-
707659
//===----------------------------------------------------------------------===//
708660
// LLVMTargetExtType.
709661
//===----------------------------------------------------------------------===//
@@ -762,7 +714,6 @@ bool mlir::LLVM::isCompatibleOuterType(Type type) {
762714
LLVMPointerType,
763715
LLVMStructType,
764716
LLVMTokenType,
765-
LLVMScalableVectorType,
766717
LLVMTargetExtType,
767718
LLVMVoidType,
768719
LLVMX86AMXType
@@ -810,7 +761,6 @@ static bool isCompatibleImpl(Type type, DenseSet<Type> &compatibleTypes) {
810761
})
811762
// clang-format off
812763
.Case<
813-
LLVMScalableVectorType,
814764
LLVMArrayType
815765
>([&](auto containerType) {
816766
return isCompatible(containerType.getElementType());
@@ -857,9 +807,6 @@ bool mlir::LLVM::isCompatibleFloatingPointType(Type type) {
857807
}
858808

859809
bool mlir::LLVM::isCompatibleVectorType(Type type) {
860-
if (llvm::isa<LLVMScalableVectorType>(type))
861-
return true;
862-
863810
if (auto vecType = llvm::dyn_cast<VectorType>(type)) {
864811
if (vecType.getRank() != 1)
865812
return false;
@@ -874,8 +821,7 @@ bool mlir::LLVM::isCompatibleVectorType(Type type) {
874821

875822
Type mlir::LLVM::getVectorElementType(Type type) {
876823
return llvm::TypeSwitch<Type, Type>(type)
877-
.Case<LLVMScalableVectorType, VectorType>(
878-
[](auto ty) { return ty.getElementType(); })
824+
.Case<VectorType>([](auto ty) { return ty.getElementType(); })
879825
.Default([](Type) -> Type {
880826
llvm_unreachable("incompatible with LLVM vector type");
881827
});
@@ -888,37 +834,22 @@ llvm::ElementCount mlir::LLVM::getVectorNumElements(Type type) {
888834
return llvm::ElementCount::getScalable(ty.getNumElements());
889835
return llvm::ElementCount::getFixed(ty.getNumElements());
890836
})
891-
.Case([](LLVMScalableVectorType ty) {
892-
return llvm::ElementCount::getScalable(ty.getMinNumElements());
893-
})
894837
.Default([](Type) -> llvm::ElementCount {
895838
llvm_unreachable("incompatible with LLVM vector type");
896839
});
897840
}
898841

899842
bool mlir::LLVM::isScalableVectorType(Type vectorType) {
900-
assert((llvm::isa<LLVMScalableVectorType, VectorType>(vectorType)) &&
843+
assert(llvm::isa<VectorType>(vectorType) &&
901844
"expected LLVM-compatible vector type");
902-
return llvm::isa<LLVMScalableVectorType>(vectorType) ||
903-
llvm::cast<VectorType>(vectorType).isScalable();
845+
return llvm::cast<VectorType>(vectorType).isScalable();
904846
}
905847

906848
Type mlir::LLVM::getVectorType(Type elementType, unsigned numElements,
907849
bool isScalable) {
908-
if (!isScalable) {
909-
// Non-scalable vectors always use the MLIR vector type.
910-
assert(VectorType::isValidElementType(elementType) &&
911-
"incompatible element type");
912-
return VectorType::get(numElements, elementType, {false});
913-
}
914-
915-
// This is a scalable vector.
916-
if (VectorType::isValidElementType(elementType))
917-
return VectorType::get(numElements, elementType, {true});
918-
assert(LLVMScalableVectorType::isValidElementType(elementType) &&
919-
"neither the MLIR vector type nor LLVMScalableVectorType is "
920-
"compatible with the specified element type");
921-
return LLVMScalableVectorType::get(elementType, numElements);
850+
assert(VectorType::isValidElementType(elementType) &&
851+
"incompatible element type");
852+
return VectorType::get(numElements, elementType, {isScalable});
922853
}
923854

924855
Type mlir::LLVM::getVectorType(Type elementType,
@@ -937,15 +868,6 @@ Type mlir::LLVM::getFixedVectorType(Type elementType, unsigned numElements) {
937868
}
938869

939870
Type mlir::LLVM::getScalableVectorType(Type elementType, unsigned numElements) {
940-
bool useLLVM = LLVMScalableVectorType::isValidElementType(elementType);
941-
bool useBuiltIn = VectorType::isValidElementType(elementType);
942-
(void)useBuiltIn;
943-
assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible scalable-vector "
944-
"type to be either builtin or LLVM dialect "
945-
"type");
946-
if (useLLVM)
947-
return LLVMScalableVectorType::get(elementType, numElements);
948-
949871
// LLVM vectors are always 1-D, hence only 1 bool is required to mark it as
950872
// scalable/non-scalable.
951873
return VectorType::get(numElements, elementType, /*scalableDims=*/true);

mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class TypeFromLLVMIRTranslatorImpl {
130130

131131
/// Translates the given scalable-vector type.
132132
Type translate(llvm::ScalableVectorType *type) {
133-
return LLVM::LLVMScalableVectorType::get(
134-
translateType(type->getElementType()), type->getMinNumElements());
133+
return LLVM::getScalableVectorType(translateType(type->getElementType()),
134+
type->getMinNumElements());
135135
}
136136

137137
/// Translates the given target extension type.

0 commit comments

Comments
 (0)