diff --git a/mlir/docs/Dialects/LLVM.md b/mlir/docs/Dialects/LLVM.md index fadc81b567b4e..d0509e036682f 100644 --- a/mlir/docs/Dialects/LLVM.md +++ b/mlir/docs/Dialects/LLVM.md @@ -327,20 +327,7 @@ multiple of some fixed size in case of _scalable_ vectors, and the element type. Vectors cannot be nested and only 1D vectors are supported. Scalable vectors are still considered 1D. -LLVM dialect uses built-in vector types for _fixed_-size vectors of built-in -types, and provides additional types for fixed-sized vectors of LLVM dialect -types (`LLVMFixedVectorType`) and scalable vectors of any types -(`LLVMScalableVectorType`). These two additional types share the following -syntax: - -``` - llvm-vec-type ::= `!llvm.vec<` (`?` `x`)? integer-literal `x` type `>` -``` - -Note that the sets of element types supported by built-in and LLVM dialect -vector types are mutually exclusive, e.g., the built-in vector type does not -accept `!llvm.ptr` and the LLVM dialect fixed-width vector type does not -accept `i32`. +The LLVM dialect uses built-in vector type. The following functions are provided to operate on any kind of the vector types compatible with the LLVM dialect: @@ -360,8 +347,8 @@ compatible with the LLVM dialect: ```mlir vector<42 x i32> // Vector of 42 32-bit integers. -!llvm.vec<42 x ptr> // Vector of 42 pointers. -!llvm.vec // Scalable vector of 32-bit integers with +vector<42 x !llvm.ptr> // Vector of 42 pointers. +vector<[4] x i32> // Scalable vector of 32-bit integers with // size divisible by 4. !llvm.array<2 x vector<2 x i32>> // Array of 2 vectors of 2 32-bit integers. !llvm.array<2 x vec<2 x ptr>> // Array of 2 vectors of 2 pointers. diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h index 8b380751c2f9d..03c246e589643 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h @@ -66,7 +66,6 @@ namespace LLVM { } DEFINE_TRIVIAL_LLVM_TYPE(LLVMVoidType, "llvm.void"); -DEFINE_TRIVIAL_LLVM_TYPE(LLVMPPCFP128Type, "llvm.ppc_fp128"); DEFINE_TRIVIAL_LLVM_TYPE(LLVMTokenType, "llvm.token"); DEFINE_TRIVIAL_LLVM_TYPE(LLVMLabelType, "llvm.label"); DEFINE_TRIVIAL_LLVM_TYPE(LLVMMetadataType, "llvm.metadata"); diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td index 438df08cd1f28..e9f01ba5cd4e4 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td @@ -288,70 +288,6 @@ def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [ ]; } -//===----------------------------------------------------------------------===// -// LLVMFixedVectorType -//===----------------------------------------------------------------------===// - -def LLVMFixedVectorType : LLVMType<"LLVMFixedVector", "vec"> { - let summary = "LLVM fixed vector type"; - let description = [{ - LLVM dialect vector type that supports all element types that are supported - in LLVM vectors but that are not supported by the builtin MLIR vector type. - E.g., LLVMFixedVectorType supports LLVM pointers as element type. - }]; - - let typeName = "llvm.fixed_vec"; - - let parameters = (ins "Type":$elementType, "unsigned":$numElements); - let assemblyFormat = [{ - `<` $numElements `x` custom($elementType) `>` - }]; - - let genVerifyDecl = 1; - - let builders = [ - TypeBuilderWithInferredContext<(ins "Type":$elementType, - "unsigned":$numElements)> - ]; - - let extraClassDeclaration = [{ - /// Checks if the given type can be used in a vector type. - static bool isValidElementType(Type type); - }]; -} - -//===----------------------------------------------------------------------===// -// LLVMScalableVectorType -//===----------------------------------------------------------------------===// - -def LLVMScalableVectorType : LLVMType<"LLVMScalableVector", "vec"> { - let summary = "LLVM scalable vector type"; - let description = [{ - LLVM dialect scalable vector type, represents a sequence of elements of - unknown length that is known to be divisible by some constant. These - elements can be processed as one in SIMD context. - }]; - - let typeName = "llvm.scalable_vec"; - - let parameters = (ins "Type":$elementType, "unsigned":$minNumElements); - let assemblyFormat = [{ - `<` `?` `x` $minNumElements `x` ` ` custom($elementType) `>` - }]; - - let genVerifyDecl = 1; - - let builders = [ - TypeBuilderWithInferredContext<(ins "Type":$elementType, - "unsigned":$minNumElements)> - ]; - - let extraClassDeclaration = [{ - /// Checks if the given type can be used in a vector type. - static bool isValidElementType(Type type); - }]; -} - //===----------------------------------------------------------------------===// // LLVMTargetExtType //===----------------------------------------------------------------------===// @@ -400,4 +336,17 @@ def LLVMX86AMXType : LLVMType<"LLVMX86AMX", "x86_amx"> { }]; } +//===----------------------------------------------------------------------===// +// LLVMPPCFP128Type +//===----------------------------------------------------------------------===// + +def LLVMPPCFP128Type : LLVMType<"LLVMPPCFP128", "ppc_fp128", + [DeclareTypeInterfaceMethods]> { + let summary = "128 bit FP type with IBM double-double semantics"; + let description = [{ + A 128 bit floating-point type with IBM double-double semantics. + See S_PPCDoubleDouble in APFloat.h for details. + }]; +} + #endif // LLVMTYPES_TD diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 42a3839e8c638..78eb4c9b3481f 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -685,10 +685,6 @@ GEPIndicesAdaptor GEPOp::getIndices() { static Type extractVectorElementType(Type type) { if (auto vectorType = llvm::dyn_cast(type)) return vectorType.getElementType(); - if (auto scalableVectorType = llvm::dyn_cast(type)) - return scalableVectorType.getElementType(); - if (auto fixedVectorType = llvm::dyn_cast(type)) - return fixedVectorType.getElementType(); return type; } @@ -725,20 +721,18 @@ static void destructureIndices(Type currType, ArrayRef indices, if (rawConstantIndices.size() == 1 || !currType) continue; - currType = - TypeSwitch(currType) - .Case([](auto containerType) { - return containerType.getElementType(); - }) - .Case([&](LLVMStructType structType) -> Type { - int64_t memberIndex = rawConstantIndices.back(); - if (memberIndex >= 0 && static_cast(memberIndex) < - structType.getBody().size()) - return structType.getBody()[memberIndex]; - return nullptr; - }) - .Default(Type(nullptr)); + currType = TypeSwitch(currType) + .Case([](auto containerType) { + return containerType.getElementType(); + }) + .Case([&](LLVMStructType structType) -> Type { + int64_t memberIndex = rawConstantIndices.back(); + if (memberIndex >= 0 && static_cast(memberIndex) < + structType.getBody().size()) + return structType.getBody()[memberIndex]; + return nullptr; + }) + .Default(Type(nullptr)); } } @@ -839,11 +833,11 @@ verifyStructIndices(Type baseGEPType, unsigned indexPos, return verifyStructIndices(elementTypes[gepIndex], indexPos + 1, indices, emitOpError); }) - .Case([&](auto containerType) -> LogicalResult { - return verifyStructIndices(containerType.getElementType(), indexPos + 1, - indices, emitOpError); - }) + .Case( + [&](auto containerType) -> LogicalResult { + return verifyStructIndices(containerType.getElementType(), + indexPos + 1, indices, emitOpError); + }) .Default([&](auto otherType) -> LogicalResult { return emitOpError() << "type " << otherType << " cannot be indexed (index #" @@ -3157,26 +3151,23 @@ OpFoldResult LLVM::ZeroOp::fold(FoldAdaptor) { //===----------------------------------------------------------------------===// /// Compute the total number of elements in the given type, also taking into -/// account nested types. Supported types are `VectorType`, `LLVMArrayType` and -/// `LLVMFixedVectorType`. Everything else is treated as a scalar. +/// account nested types. Supported types are `VectorType` and `LLVMArrayType`. +/// Everything else is treated as a scalar. static int64_t getNumElements(Type t) { - if (auto vecType = dyn_cast(t)) + if (auto vecType = dyn_cast(t)) { + assert(!vecType.isScalable() && + "number of elements of a scalable vector type is unknown"); return vecType.getNumElements() * getNumElements(vecType.getElementType()); + } if (auto arrayType = dyn_cast(t)) return arrayType.getNumElements() * getNumElements(arrayType.getElementType()); - if (auto vecType = dyn_cast(t)) - return vecType.getNumElements() * getNumElements(vecType.getElementType()); - assert(!isa(t) && - "number of elements of a scalable vector type is unknown"); return 1; } /// Check if the given type is a scalable vector type or a vector/array type /// that contains a nested scalable vector type. static bool hasScalableVectorType(Type t) { - if (isa(t)) - return true; if (auto vecType = dyn_cast(t)) { if (vecType.isScalable()) return true; @@ -3184,8 +3175,6 @@ static bool hasScalableVectorType(Type t) { } if (auto arrayType = dyn_cast(t)) return hasScalableVectorType(arrayType.getElementType()); - if (auto vecType = dyn_cast(t)) - return hasScalableVectorType(vecType.getElementType()); return false; } @@ -3265,8 +3254,7 @@ LogicalResult LLVM::ConstantOp::verify() { << "scalable vector type requires a splat attribute"; return success(); } - if (!isa( - getType())) + if (!isa(getType())) return emitOpError() << "expected vector or array type"; // The number of elements of the attribute and the type must match. int64_t attrNumElements; @@ -3515,8 +3503,7 @@ LogicalResult LLVM::BitcastOp::verify() { if (!resultType) return success(); - auto isVector = - llvm::IsaPred; + auto isVector = llvm::IsaPred; // Due to bitcast requiring both operands to be of the same size, it is not // possible for only one of the two to be a pointer of vectors. @@ -3982,7 +3969,6 @@ void LLVMDialect::initialize() { // clang-format off addTypes(); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp index 51dcb071f9c18..8640ef28a9e56 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp @@ -134,12 +134,6 @@ static bool isSupportedTypeForConversion(Type type) { if (isa(type)) return false; - // LLVM vector types are only used for either pointers or target specific - // types. These types cannot be casted in the general case, thus the memory - // optimizations do not support them. - if (isa(type)) - return false; - if (auto vectorType = dyn_cast(type)) { // Vectors of pointers cannot be casted. if (isa(vectorType.getElementType())) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp index d700dc52d42d2..319bb90d9b601 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp @@ -40,8 +40,6 @@ static StringRef getTypeKeyword(Type type) { .Case([&](Type) { return "metadata"; }) .Case([&](Type) { return "func"; }) .Case([&](Type) { return "ptr"; }) - .Case( - [&](Type) { return "vec"; }) .Case([&](Type) { return "array"; }) .Case([&](Type) { return "struct"; }) .Case([&](Type) { return "target"; }) @@ -104,8 +102,7 @@ void mlir::LLVM::detail::printType(Type type, AsmPrinter &printer) { printer << getTypeKeyword(type); llvm::TypeSwitch(type) - .Case([&](auto type) { type.print(printer); }); } @@ -115,44 +112,6 @@ void mlir::LLVM::detail::printType(Type type, AsmPrinter &printer) { static ParseResult dispatchParse(AsmParser &parser, Type &type); -/// Parses an LLVM dialect vector type. -/// llvm-type ::= `vec<` `? x`? integer `x` llvm-type `>` -/// Supports both fixed and scalable vectors. -static Type parseVectorType(AsmParser &parser) { - SmallVector dims; - SMLoc dimPos, typePos; - Type elementType; - SMLoc loc = parser.getCurrentLocation(); - if (parser.parseLess() || parser.getCurrentLocation(&dimPos) || - parser.parseDimensionList(dims, /*allowDynamic=*/true) || - parser.getCurrentLocation(&typePos) || - dispatchParse(parser, elementType) || parser.parseGreater()) - return Type(); - - // We parsed a generic dimension list, but vectors only support two forms: - // - single non-dynamic entry in the list (fixed vector); - // - two elements, the first dynamic (indicated by ShapedType::kDynamic) - // and the second - // non-dynamic (scalable vector). - if (dims.empty() || dims.size() > 2 || - ((dims.size() == 2) ^ (ShapedType::isDynamic(dims[0]))) || - (dims.size() == 2 && ShapedType::isDynamic(dims[1]))) { - parser.emitError(dimPos) - << "expected '? x x ' or ' x '"; - return Type(); - } - - bool isScalable = dims.size() == 2; - if (isScalable) - return parser.getChecked(loc, elementType, dims[1]); - if (elementType.isSignlessIntOrFloat()) { - parser.emitError(typePos) - << "cannot use !llvm.vec for built-in primitives, use 'vector' instead"; - return Type(); - } - return parser.getChecked(loc, elementType, dims[0]); -} - /// Attempts to set the body of an identified structure type. Reports a parsing /// error at `subtypesLoc` in case of failure. static LLVMStructType trySetStructBody(LLVMStructType type, @@ -311,7 +270,6 @@ static Type dispatchParse(AsmParser &parser, bool allowAny = true) { .Case("metadata", [&] { return LLVMMetadataType::get(ctx); }) .Case("func", [&] { return LLVMFunctionType::parse(parser); }) .Case("ptr", [&] { return LLVMPointerType::parse(parser); }) - .Case("vec", [&] { return parseVectorType(parser); }) .Case("array", [&] { return LLVMArrayType::parse(parser); }) .Case("struct", [&] { return LLVMStructType::parse(parser); }) .Case("target", [&] { return LLVMTargetExtType::parse(parser); }) diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp index 140d909da5f74..663adc3c34256 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp @@ -150,8 +150,7 @@ generatedTypePrinter(Type def, AsmPrinter &printer); bool LLVMArrayType::isValidElementType(Type type) { return !llvm::isa( - type); + LLVMFunctionType, LLVMTokenType>(type); } LLVMArrayType LLVMArrayType::get(Type elementType, uint64_t numElements) { @@ -659,82 +658,6 @@ LogicalResult LLVMStructType::verifyEntries(DataLayoutEntryListRef entries, return mlir::success(); } -//===----------------------------------------------------------------------===// -// Vector types. -//===----------------------------------------------------------------------===// - -/// Verifies that the type about to be constructed is well-formed. -template -static LogicalResult -verifyVectorConstructionInvariants(function_ref emitError, - Type elementType, unsigned numElements) { - if (numElements == 0) - return emitError() << "the number of vector elements must be positive"; - - if (!VecTy::isValidElementType(elementType)) - return emitError() << "invalid vector element type"; - - return success(); -} - -LLVMFixedVectorType LLVMFixedVectorType::get(Type elementType, - unsigned numElements) { - assert(elementType && "expected non-null subtype"); - return Base::get(elementType.getContext(), elementType, numElements); -} - -LLVMFixedVectorType -LLVMFixedVectorType::getChecked(function_ref emitError, - Type elementType, unsigned numElements) { - assert(elementType && "expected non-null subtype"); - return Base::getChecked(emitError, elementType.getContext(), elementType, - numElements); -} - -bool LLVMFixedVectorType::isValidElementType(Type type) { - return llvm::isa(type); -} - -LogicalResult -LLVMFixedVectorType::verify(function_ref emitError, - Type elementType, unsigned numElements) { - return verifyVectorConstructionInvariants( - emitError, elementType, numElements); -} - -//===----------------------------------------------------------------------===// -// LLVMScalableVectorType. -//===----------------------------------------------------------------------===// - -LLVMScalableVectorType LLVMScalableVectorType::get(Type elementType, - unsigned minNumElements) { - assert(elementType && "expected non-null subtype"); - return Base::get(elementType.getContext(), elementType, minNumElements); -} - -LLVMScalableVectorType -LLVMScalableVectorType::getChecked(function_ref emitError, - Type elementType, unsigned minNumElements) { - assert(elementType && "expected non-null subtype"); - return Base::getChecked(emitError, elementType.getContext(), elementType, - minNumElements); -} - -bool LLVMScalableVectorType::isValidElementType(Type type) { - if (auto intType = llvm::dyn_cast(type)) - return intType.isSignless(); - - return isCompatibleFloatingPointType(type) || - llvm::isa(type); -} - -LogicalResult -LLVMScalableVectorType::verify(function_ref emitError, - Type elementType, unsigned numElements) { - return verifyVectorConstructionInvariants( - emitError, elementType, numElements); -} - //===----------------------------------------------------------------------===// // LLVMTargetExtType. //===----------------------------------------------------------------------===// @@ -764,6 +687,14 @@ bool LLVM::LLVMTargetExtType::supportsMemOps() const { return false; } +//===----------------------------------------------------------------------===// +// LLVMPPCFP128Type +//===----------------------------------------------------------------------===// + +const llvm::fltSemantics &LLVMPPCFP128Type::getFloatSemantics() const { + return APFloat::PPCDoubleDouble(); +} + //===----------------------------------------------------------------------===// // Utility functions. //===----------------------------------------------------------------------===// @@ -785,8 +716,6 @@ bool mlir::LLVM::isCompatibleOuterType(Type type) { LLVMPointerType, LLVMStructType, LLVMTokenType, - LLVMFixedVectorType, - LLVMScalableVectorType, LLVMTargetExtType, LLVMVoidType, LLVMX86AMXType @@ -834,8 +763,6 @@ static bool isCompatibleImpl(Type type, DenseSet &compatibleTypes) { }) // clang-format off .Case< - LLVMFixedVectorType, - LLVMScalableVectorType, LLVMArrayType >([&](auto containerType) { return isCompatible(containerType.getElementType()); @@ -882,9 +809,6 @@ bool mlir::LLVM::isCompatibleFloatingPointType(Type type) { } bool mlir::LLVM::isCompatibleVectorType(Type type) { - if (llvm::isa(type)) - return true; - if (auto vecType = llvm::dyn_cast(type)) { if (vecType.getRank() != 1) return false; @@ -898,56 +822,29 @@ bool mlir::LLVM::isCompatibleVectorType(Type type) { } Type mlir::LLVM::getVectorElementType(Type type) { - return llvm::TypeSwitch(type) - .Case( - [](auto ty) { return ty.getElementType(); }) - .Default([](Type) -> Type { - llvm_unreachable("incompatible with LLVM vector type"); - }); + auto vecTy = dyn_cast(type); + assert(vecTy && "incompatible with LLVM vector type"); + return vecTy.getElementType(); } llvm::ElementCount mlir::LLVM::getVectorNumElements(Type type) { - return llvm::TypeSwitch(type) - .Case([](VectorType ty) { - if (ty.isScalable()) - return llvm::ElementCount::getScalable(ty.getNumElements()); - return llvm::ElementCount::getFixed(ty.getNumElements()); - }) - .Case([](LLVMFixedVectorType ty) { - return llvm::ElementCount::getFixed(ty.getNumElements()); - }) - .Case([](LLVMScalableVectorType ty) { - return llvm::ElementCount::getScalable(ty.getMinNumElements()); - }) - .Default([](Type) -> llvm::ElementCount { - llvm_unreachable("incompatible with LLVM vector type"); - }); + auto vecTy = dyn_cast(type); + assert(vecTy && "incompatible with LLVM vector type"); + if (vecTy.isScalable()) + return llvm::ElementCount::getScalable(vecTy.getNumElements()); + return llvm::ElementCount::getFixed(vecTy.getNumElements()); } bool mlir::LLVM::isScalableVectorType(Type vectorType) { - assert((llvm::isa( - vectorType)) && + assert(llvm::isa(vectorType) && "expected LLVM-compatible vector type"); - return !llvm::isa(vectorType) && - (llvm::isa(vectorType) || - llvm::cast(vectorType).isScalable()); + return llvm::cast(vectorType).isScalable(); } Type mlir::LLVM::getVectorType(Type elementType, unsigned numElements, bool isScalable) { - bool useLLVM = LLVMFixedVectorType::isValidElementType(elementType); - bool useBuiltIn = VectorType::isValidElementType(elementType); - (void)useBuiltIn; - assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible fixed-vector type " - "to be either builtin or LLVM dialect type"); - if (useLLVM) { - if (isScalable) - return LLVMScalableVectorType::get(elementType, numElements); - return LLVMFixedVectorType::get(elementType, numElements); - } - - // LLVM vectors are always 1-D, hence only 1 bool is required to mark it as - // scalable/non-scalable. + assert(VectorType::isValidElementType(elementType) && + "incompatible element type"); return VectorType::get(numElements, elementType, {isScalable}); } @@ -961,26 +858,12 @@ Type mlir::LLVM::getVectorType(Type elementType, } Type mlir::LLVM::getFixedVectorType(Type elementType, unsigned numElements) { - bool useLLVM = LLVMFixedVectorType::isValidElementType(elementType); - bool useBuiltIn = VectorType::isValidElementType(elementType); - (void)useBuiltIn; - assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible fixed-vector type " - "to be either builtin or LLVM dialect type"); - if (useLLVM) - return LLVMFixedVectorType::get(elementType, numElements); + assert(VectorType::isValidElementType(elementType) && + "incompatible element type"); return VectorType::get(numElements, elementType); } Type mlir::LLVM::getScalableVectorType(Type elementType, unsigned numElements) { - bool useLLVM = LLVMScalableVectorType::isValidElementType(elementType); - bool useBuiltIn = VectorType::isValidElementType(elementType); - (void)useBuiltIn; - assert((useLLVM ^ useBuiltIn) && "expected LLVM-compatible scalable-vector " - "type to be either builtin or LLVM dialect " - "type"); - if (useLLVM) - return LLVMScalableVectorType::get(elementType, numElements); - // LLVM vectors are always 1-D, hence only 1 bool is required to mark it as // scalable/non-scalable. return VectorType::get(numElements, elementType, /*scalableDims=*/true); @@ -1002,12 +885,6 @@ llvm::TypeSize mlir::LLVM::getPrimitiveTypeSizeInBits(Type type) { }) .Case( [](Type) { return llvm::TypeSize::getFixed(128); }) - .Case([](LLVMFixedVectorType t) { - llvm::TypeSize elementSize = - getPrimitiveTypeSizeInBits(t.getElementType()); - return llvm::TypeSize(elementSize.getFixedValue() * t.getNumElements(), - elementSize.isScalable()); - }) .Case([](VectorType t) { assert(isCompatibleVectorType(t) && "unexpected incompatible with LLVM vector type"); diff --git a/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp b/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp index ea990ca7aefbe..bc9765fff2953 100644 --- a/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp +++ b/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp @@ -130,8 +130,8 @@ class TypeFromLLVMIRTranslatorImpl { /// Translates the given scalable-vector type. Type translate(llvm::ScalableVectorType *type) { - return LLVM::LLVMScalableVectorType::get( - translateType(type->getElementType()), type->getMinNumElements()); + return LLVM::getScalableVectorType(translateType(type->getElementType()), + type->getMinNumElements()); } /// Translates the given target extension type. diff --git a/mlir/lib/Target/LLVMIR/TypeToLLVM.cpp b/mlir/lib/Target/LLVMIR/TypeToLLVM.cpp index c7a533eddce84..af78dcd16f792 100644 --- a/mlir/lib/Target/LLVMIR/TypeToLLVM.cpp +++ b/mlir/lib/Target/LLVMIR/TypeToLLVM.cpp @@ -71,9 +71,8 @@ class TypeToLLVMIRTranslatorImpl { return llvm::Type::getX86_AMXTy(context); }) .Case( + LLVM::LLVMPointerType, LLVM::LLVMStructType, VectorType, + LLVM::LLVMTargetExtType>( [this](auto type) { return this->translate(type); }) .Default([](Type t) -> llvm::Type * { llvm_unreachable("unknown LLVM dialect type"); @@ -143,18 +142,6 @@ class TypeToLLVMIRTranslatorImpl { type.getNumElements()); } - /// Translates the given fixed-vector type. - llvm::Type *translate(LLVM::LLVMFixedVectorType type) { - return llvm::FixedVectorType::get(translateType(type.getElementType()), - type.getNumElements()); - } - - /// Translates the given scalable-vector type. - llvm::Type *translate(LLVM::LLVMScalableVectorType type) { - return llvm::ScalableVectorType::get(translateType(type.getElementType()), - type.getMinNumElements()); - } - /// Translates the given target extension type. llvm::Type *translate(LLVM::LLVMTargetExtType type) { SmallVector typeParams; diff --git a/mlir/test/Dialect/LLVMIR/mem2reg.mlir b/mlir/test/Dialect/LLVMIR/mem2reg.mlir index 3c13eacde4856..56634cff87aa9 100644 --- a/mlir/test/Dialect/LLVMIR/mem2reg.mlir +++ b/mlir/test/Dialect/LLVMIR/mem2reg.mlir @@ -1033,7 +1033,7 @@ llvm.func @scalable_vector() -> i16 { llvm.func @scalable_llvm_vector() -> i16 { %0 = llvm.mlir.constant(1 : i32) : i32 // CHECK: llvm.alloca - %1 = llvm.alloca %0 x !llvm.vec : (i32) -> !llvm.ptr + %1 = llvm.alloca %0 x vector<[4] x !llvm.ppc_fp128> : (i32) -> !llvm.ptr %2 = llvm.load %1 : !llvm.ptr -> i16 llvm.return %2 : i16 } diff --git a/mlir/test/Dialect/LLVMIR/types-invalid.mlir b/mlir/test/Dialect/LLVMIR/types-invalid.mlir index 76fb6780d8668..04710fa6f2396 100644 --- a/mlir/test/Dialect/LLVMIR/types-invalid.mlir +++ b/mlir/test/Dialect/LLVMIR/types-invalid.mlir @@ -118,48 +118,6 @@ func.func @identified_struct_with_void() { // ----- -func.func @dynamic_vector() { - // expected-error @+1 {{expected '? x x ' or ' x '}} - "some.op"() : () -> !llvm.vec -} - -// ----- - -func.func @dynamic_scalable_vector() { - // expected-error @+1 {{expected '? x x ' or ' x '}} - "some.op"() : () -> !llvm.vec -} - -// ----- - -func.func @unscalable_vector() { - // expected-error @+1 {{expected '? x x ' or ' x '}} - "some.op"() : () -> !llvm.vec<4x4 x ptr> -} - -// ----- - -func.func @zero_vector() { - // expected-error @+1 {{the number of vector elements must be positive}} - "some.op"() : () -> !llvm.vec<0 x ptr> -} - -// ----- - -func.func @nested_vector() { - // expected-error @+1 {{invalid vector element type}} - "some.op"() : () -> !llvm.vec<2 x vector<2xi32>> -} - -// ----- - -func.func @scalable_void_vector() { - // expected-error @+1 {{invalid vector element type}} - "some.op"() : () -> !llvm.vec -} - -// ----- - // expected-error @+1 {{unexpected type, expected keyword}} func.func private @unexpected_type() -> !llvm.tensor<*xf32> @@ -170,11 +128,6 @@ func.func private @unexpected_type() -> !llvm.f32 // ----- -// expected-error @below {{cannot use !llvm.vec for built-in primitives, use 'vector' instead}} -func.func private @llvm_vector_primitive() -> !llvm.vec<4 x f32> - -// ----- - func.func private @target_ext_invalid_order() { // expected-error @+1 {{failed to parse parameter list for target extension type}} "some.op"() : () -> !llvm.target<"target1", 5, i32, 1> diff --git a/mlir/test/Dialect/LLVMIR/types.mlir b/mlir/test/Dialect/LLVMIR/types.mlir index 184205bb0b1e7..b87c3dd6f2d7a 100644 --- a/mlir/test/Dialect/LLVMIR/types.mlir +++ b/mlir/test/Dialect/LLVMIR/types.mlir @@ -72,12 +72,14 @@ func.func @vec() { "some.op"() : () -> vector<4xi32> // CHECK: vector<4xf32> "some.op"() : () -> vector<4xf32> - // CHECK: !llvm.vec - "some.op"() : () -> !llvm.vec - // CHECK: !llvm.vec - "some.op"() : () -> !llvm.vec + // CHECK: vector<[4]xi32> + "some.op"() : () -> vector<[4] x i32> + // CHECK: vector<[8]xf16> + "some.op"() : () -> vector<[8] x f16> // CHECK: vector<4x!llvm.ptr> "some.op"() : () -> vector<4x!llvm.ptr> + // CHECK: vector<4x!llvm.ppc_fp128> + "some.op"() : () -> vector<4x!llvm.ppc_fp128> return } diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll index 0c205b7a9f13a..b0a36939d8c48 100644 --- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll +++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll @@ -882,7 +882,7 @@ define void @invariant_group(ptr %0) { ; CHECK-LABEL: llvm.func @vector_insert define void @vector_insert( %0, <4 x float> %1) { - ; CHECK: llvm.intr.vector.insert %{{.*}}, %{{.*}}[4] : vector<4xf32> into !llvm.vec + ; CHECK: llvm.intr.vector.insert %{{.*}}, %{{.*}}[4] : vector<4xf32> into vector<[4]xf32> %3 = call @llvm.vector.insert.nxv4f32.v4f32( %0, <4 x float> %1, i64 4); ret void } @@ -898,7 +898,7 @@ define void @vector_extract( %0) { define void @vector_deinterleave2(<4 x double> %0, %1) { ; CHECK: "llvm.intr.vector.deinterleave2"(%{{.*}}) : (vector<4xf64>) -> !llvm.struct<(vector<2xf64>, vector<2xf64>)> %3 = call { <2 x double>, <2 x double> } @llvm.vector.deinterleave2.v4f64(<4 x double> %0); - ; CHECK: "llvm.intr.vector.deinterleave2"(%{{.*}}) : (!llvm.vec) -> !llvm.struct<(vec, vec)> + ; CHECK: "llvm.intr.vector.deinterleave2"(%{{.*}}) : (vector<[8]xi32>) -> !llvm.struct<(vector<[4]xi32>, vector<[4]xi32>)> %4 = call { , } @llvm.vector.deinterleave2.nxv8i32( %1); ret void } diff --git a/mlir/test/Target/LLVMIR/llvmir-types.mlir b/mlir/test/Target/LLVMIR/llvmir-types.mlir index 33e1c7e6382ae..5278e1492bb72 100644 --- a/mlir/test/Target/LLVMIR/llvmir-types.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-types.mlir @@ -81,9 +81,9 @@ llvm.func @return_v4_float() -> vector<4xf32> // CHECK: declare @return_vs_4_float() llvm.func @return_vs_4_float() -> vector<[4]xf32> // CHECK: declare @return_vs_4_i32() -llvm.func @return_vs_4_i32() -> !llvm.vec +llvm.func @return_vs_4_i32() -> vector<[4]xi32> // CHECK: declare @return_vs_8_half() -llvm.func @return_vs_8_half() -> !llvm.vec +llvm.func @return_vs_8_half() -> vector<[8]xf16> // CHECK: declare <4 x ptr> @return_v_4_pi8() llvm.func @return_v_4_pi8() -> vector<4x!llvm.ptr>