From: Uday Bondhugula Date: Fri, 11 Oct 2019 13:08:24 +0000 (-0700) Subject: Drop obsolete code from std to llvm memref lowering X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47596f534555477ac5cee3b55095af97ca7d7cdb;p=platform%2Fupstream%2Fllvm.git Drop obsolete code from std to llvm memref lowering - dropping what looks like outdated code post some of the previous updates Signed-off-by: Uday Bondhugula Closes tensorflow/mlir#179 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/179 from bondhugula:llfix 2a72ea441fe1b3924802273ffbe9870afeb90f91 PiperOrigin-RevId: 274158273 --- diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp index 6f9b449..4282079 100644 --- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -278,18 +278,11 @@ public: // Extract raw data pointer value from a value representing a memref. static Value *extractMemRefElementPtr(ConversionPatternRewriter &builder, - Location loc, - Value *convertedMemRefValue, - Type elementTypePtr, - bool hasStaticShape) { - Value *buffer; - if (hasStaticShape) - return convertedMemRefValue; - else - return builder.create(loc, elementTypePtr, - convertedMemRefValue, - builder.getIndexArrayAttr(0)); - return buffer; + Location loc, Value *memref, + Type elementTypePtr) { + return builder.create( + loc, elementTypePtr, memref, + builder.getIndexArrayAttr(kPtrPosInMemRefDescriptor)); } protected: @@ -650,8 +643,7 @@ struct AllocOpLowering : public LLVMLegalizationPattern { // values and dynamic sizes are passed to 'alloc' as operands. In case of // zero-dimensional memref, assume a scalar (size 1). SmallVector sizes; - auto numOperands = allocOp.getNumOperands(); - sizes.reserve(numOperands); + sizes.reserve(type.getRank()); unsigned i = 0; for (int64_t s : type.getShape()) sizes.push_back(s == -1 ? operands[i++] @@ -860,11 +852,9 @@ struct DeallocOpLowering : public LLVMLegalizationPattern { } auto type = transformed.memref()->getType().cast(); - auto hasStaticShape = type.isPointerTy(); - Type elementPtrType = hasStaticShape ? type : type.getStructElementType(0); - Value *bufferPtr = - extractMemRefElementPtr(rewriter, op->getLoc(), transformed.memref(), - elementPtrType, hasStaticShape); + Type elementPtrType = type.getStructElementType(kPtrPosInMemRefDescriptor); + Value *bufferPtr = extractMemRefElementPtr( + rewriter, op->getLoc(), transformed.memref(), elementPtrType); Value *casted = rewriter.create( op->getLoc(), getVoidPtrType(), bufferPtr); rewriter.replaceOpWithNewOp( @@ -975,9 +965,8 @@ struct LoadStoreOpLowering : public LLVMLegalizationPattern { ArrayRef strides, int64_t offset, ConversionPatternRewriter &rewriter) const { auto indexTy = this->getIndexType(); - Value *base = rewriter.create( - loc, elementTypePtr, memRefDescriptor, - rewriter.getIndexArrayAttr(kPtrPosInMemRefDescriptor)); + Value *base = this->extractMemRefElementPtr(rewriter, loc, memRefDescriptor, + elementTypePtr); Value *offsetValue = offset == MemRefType::getDynamicStrideOrOffset() ? rewriter.create(