From 782ae29678598e42e6984ce3bd6c5a3914edc33e Mon Sep 17 00:00:00 2001 From: Nicolas Vasilache Date: Thu, 12 Dec 2019 10:03:19 -0800 Subject: [PATCH] Retire !linalg.buffer type - NFC This type is not used anymore now that Linalg view and subview have graduated to std and that alignment is supported on alloc. PiperOrigin-RevId: 285213424 --- mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h | 23 +---- mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp | 21 +---- .../Dialect/Linalg/Analysis/DependenceAnalysis.cpp | 5 +- mlir/lib/Dialect/Linalg/IR/LinalgTypes.cpp | 97 +--------------------- mlir/test/Conversion/LoopsToGPU/linalg_to_gpu.mlir | 2 +- 5 files changed, 7 insertions(+), 141 deletions(-) diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h index 81c3097..181a79c 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h @@ -26,8 +26,7 @@ class MLIRContext; namespace linalg { enum LinalgTypes { - Buffer = Type::FIRST_LINALG_TYPE, - Range, + Range = Type::FIRST_LINALG_TYPE, LAST_USED_LINALG_TYPE = Range, }; @@ -43,26 +42,6 @@ public: void printType(Type type, DialectAsmPrinter &os) const override; }; -/// A BufferType represents a contiguous block of memory that can be allocated -/// and deallocated. A buffer cannot be indexed directly, a view must be -/// laid out on a buffer to give it indexing semantics. -struct BufferTypeStorage; -class BufferType : public Type::TypeBase { -public: - // Used for generic hooks in TypeBase. - using Base::Base; - /// Construction hook. - static BufferType get(MLIRContext *context, Type elementType, - int64_t bufferSize = -1); - /// Used to implement llvm-style cast. - static bool kindof(unsigned kind) { return kind == LinalgTypes::Buffer; } - - // Type-specific functionality. - Type getElementType(); - bool hasConstantSize(); - Optional getBufferSize(); -}; - /// A RangeType represents a minimal range abstraction (min, max, step). /// It is constructed by calling the linalg.range op with three values index of /// index type: diff --git a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp index d161e99..3eb23c1 100644 --- a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp +++ b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp @@ -100,21 +100,6 @@ static Type convertLinalgType(Type t, LLVMTypeConverter &lowering) { auto int64Ty = lowering.convertType(IntegerType::get(64, context)) .cast(); - // A buffer descriptor contains the pointer to a flat region of storage and - // the size of the region. - // - // template - // struct { - // void *baseAlloc; - // Elem *ptr; - // int64_t size; - // }; - if (auto bufferType = t.dyn_cast()) { - auto voidPtrTy = LLVMType::getInt8Ty(lowering.getDialect()).getPointerTo(); - auto ptrTy = getPtrToElementType(bufferType, lowering); - return LLVMType::getStructTy(voidPtrTy, ptrTy, int64Ty); - } - // Range descriptor contains the range bounds and the step as 64-bit integers. // // struct { @@ -568,6 +553,6 @@ mlir::linalg::createConvertLinalgToLLVMPass() { return std::make_unique(); } -static PassRegistration - pass("convert-linalg-to-llvm", - "Convert the operations from the linalg dialect into the LLVM dialect"); +static PassRegistration pass( + "convert-linalg-to-llvm", + "Convert the operations from the linalg dialect into the LLVM dialect"); diff --git a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp index 3688289..d7e4d08 100644 --- a/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp +++ b/mlir/lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp @@ -55,10 +55,7 @@ Value *Aliases::find(Value *v) { auto it = aliases.find(v); if (it != aliases.end()) { - assert(((isa(it->getSecond()) && - it->getSecond()->getType().isa()) || - it->getSecond()->getType().isa()) && - "Buffer or block argument expected"); + assert(it->getSecond()->getType().isa() && "Memref expected"); return it->getSecond(); } diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgTypes.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgTypes.cpp index 3e888f4..9fbb83b 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgTypes.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgTypes.cpp @@ -35,7 +35,7 @@ using namespace mlir::linalg; mlir::linalg::LinalgDialect::LinalgDialect(MLIRContext *context) : Dialect(getDialectNamespace(), context) { - addTypes(); + addTypes(); addOperations< #define GET_OP_LIST #include "mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc" @@ -45,69 +45,6 @@ mlir::linalg::LinalgDialect::LinalgDialect(MLIRContext *context) #include "mlir/Dialect/Linalg/IR/LinalgLibraryOps.cpp.inc" >(); } - -struct mlir::linalg::BufferTypeStorage : public TypeStorage { - /// Underlying Key type to transport the payload needed to construct a custom - /// type in a generic way. - struct Key { - Key(Type elementType, int64_t bufferSize = -1) - : elementType(elementType), bufferSize(bufferSize) {} - Type elementType; - int64_t bufferSize; - }; - /// `KeyTy` is a necessary typename hook for MLIR's custom type unique'ing. - using KeyTy = Key; - - /// Construction in the llvm::BumpPtrAllocator given a key. - static BufferTypeStorage *construct(TypeStorageAllocator &allocator, - const Key &key) { - return new (allocator.allocate()) BufferTypeStorage(key); - } - - /// Equality operator for hashing. - bool operator==(const Key &key) const { - return elementType == key.elementType && bufferSize == key.bufferSize; - } - - /// Hashing for unique'ing. - static unsigned hashKey(const Key &key) { - return llvm::hash_combine(key.elementType, key.bufferSize); - } - - Type getElementType() { return elementType; } - bool hasConstantSize() { return bufferSize >= 0; } - Optional getBufferSize() { - if (hasConstantSize()) { - return bufferSize; - } - return llvm::None; - } - -private: - BufferTypeStorage(const Key &key) - : elementType(key.elementType), bufferSize(key.bufferSize) {} - - Type elementType; - int64_t bufferSize; -}; - -BufferType mlir::linalg::BufferType::get(MLIRContext *context, Type elementType, - int64_t bufferSize) { - return Base::get(context, LinalgTypes::Buffer, elementType, bufferSize); -} - -Type mlir::linalg::BufferType::getElementType() { - return getImpl()->getElementType(); -} - -bool mlir::linalg::BufferType::hasConstantSize() { - return getImpl()->hasConstantSize(); -} - -Optional mlir::linalg::BufferType::getBufferSize() { - return getImpl()->getBufferSize(); -} - Type mlir::linalg::LinalgDialect::parseType(DialectAsmParser &parser) const { // Parse the main keyword for the type. StringRef keyword; @@ -119,39 +56,10 @@ Type mlir::linalg::LinalgDialect::parseType(DialectAsmParser &parser) const { if (keyword == "range") return RangeType::get(context); - // Handle 'buffer' types. - if (keyword == "buffer") { - llvm::SMLoc dimensionLoc; - SmallVector size; - Type type; - if (parser.parseLess() || parser.getCurrentLocation(&dimensionLoc) || - parser.parseDimensionList(size) || parser.parseType(type) || - parser.parseGreater()) - return Type(); - - if (size.size() != 1) { - parser.emitError(dimensionLoc, "expected single element in size list"); - return Type(); - } - - return (size.front() == -1 ? BufferType::get(context, type) - : BufferType::get(context, type, size.front())); - } - parser.emitError(parser.getNameLoc(), "unknown Linalg type: " + keyword); return Type(); } -/// BufferType prints as "buffer". -static void print(BufferType bt, DialectAsmPrinter &os) { - os << "buffer<"; - if (Optional bs = bt.getBufferSize()) - os << bs.getValue(); - else - os << "?"; - os << "x" << bt.getElementType() << ">"; -} - /// RangeType prints as just "range". static void print(RangeType rt, DialectAsmPrinter &os) { os << "range"; } @@ -160,9 +68,6 @@ void mlir::linalg::LinalgDialect::printType(Type type, switch (type.getKind()) { default: llvm_unreachable("Unhandled Linalg type"); - case LinalgTypes::Buffer: - print(type.cast(), os); - break; case LinalgTypes::Range: print(type.cast(), os); break; diff --git a/mlir/test/Conversion/LoopsToGPU/linalg_to_gpu.mlir b/mlir/test/Conversion/LoopsToGPU/linalg_to_gpu.mlir index 3bec955..a8a2d2d 100644 --- a/mlir/test/Conversion/LoopsToGPU/linalg_to_gpu.mlir +++ b/mlir/test/Conversion/LoopsToGPU/linalg_to_gpu.mlir @@ -1,7 +1,7 @@ // RUN: mlir-opt -convert-loops-to-gpu %s | FileCheck %s // CHECK-LABEL: @foo -func @foo(%arg0: !linalg.buffer, %arg1 : index) { +func @foo(%arg0: memref, %arg1 : index) { %c0 = constant 0 : index %c42 = constant 42 : index %c3 = constant 3 : index -- 2.7.4