1 //===- ArmSVEDialect.cpp - MLIR ArmSVE dialect implementation -------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the ArmSVE dialect and its operations. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/Dialect/ArmSVE/ArmSVEDialect.h" 14 #include "mlir/Dialect/LLVMIR/LLVMTypes.h" 15 #include "mlir/Dialect/Vector/VectorOps.h" 16 #include "mlir/IR/Builders.h" 17 #include "mlir/IR/DialectImplementation.h" 18 #include "mlir/IR/OpImplementation.h" 19 #include "mlir/IR/TypeUtilities.h" 20 #include "llvm/ADT/TypeSwitch.h" 21 22 using namespace mlir; 23 24 static Type getI1SameShape(Type type); 25 26 #define GET_OP_CLASSES 27 #include "mlir/Dialect/ArmSVE/ArmSVE.cpp.inc" 28 29 #define GET_TYPEDEF_CLASSES 30 #include "mlir/Dialect/ArmSVE/ArmSVETypes.cpp.inc" 31 32 void arm_sve::ArmSVEDialect::initialize() { 33 addOperations< 34 #define GET_OP_LIST 35 #include "mlir/Dialect/ArmSVE/ArmSVE.cpp.inc" 36 >(); 37 addTypes< 38 #define GET_TYPEDEF_LIST 39 #include "mlir/Dialect/ArmSVE/ArmSVETypes.cpp.inc" 40 >(); 41 } 42 43 //===----------------------------------------------------------------------===// 44 // ScalableVectorType 45 //===----------------------------------------------------------------------===// 46 47 Type arm_sve::ArmSVEDialect::parseType(DialectAsmParser &parser) const { 48 llvm::SMLoc typeLoc = parser.getCurrentLocation(); 49 { 50 Type genType; 51 auto parseResult = generatedTypeParser(parser.getBuilder().getContext(), 52 parser, "vector", genType); 53 if (parseResult.hasValue()) 54 return genType; 55 } 56 parser.emitError(typeLoc, "unknown type in ArmSVE dialect"); 57 return Type(); 58 } 59 60 void arm_sve::ArmSVEDialect::printType(Type type, DialectAsmPrinter &os) const { 61 if (failed(generatedTypePrinter(type, os))) 62 llvm_unreachable("unexpected 'arm_sve' type kind"); 63 } 64 65 //===----------------------------------------------------------------------===// 66 // ScalableVector versions of general helpers for comparison ops 67 //===----------------------------------------------------------------------===// 68 69 // Return the scalable vector of the same shape and containing i1. 70 static Type getI1SameShape(Type type) { 71 auto i1Type = IntegerType::get(type.getContext(), 1); 72 if (auto sVectorType = type.dyn_cast<arm_sve::ScalableVectorType>()) 73 return arm_sve::ScalableVectorType::get(type.getContext(), 74 sVectorType.getShape(), i1Type); 75 return nullptr; 76 } 77