From 0af643f3ceff6d164fcbdb00bcae0a566be29b80 Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Tue, 9 Aug 2022 14:40:07 -0400 Subject: [PATCH] [mlir][LLVMIR] (NFC) Add convenience builders for ConstantOp And clean up some of the user code --- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 29 ++++++++-------------- mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp | 5 ++-- mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp | 6 ++--- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 19 +++++++++++++- .../lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp | 6 ++--- mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp | 6 ++--- mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp | 20 ++++++--------- .../Conversion/GPUCommon/GPUToLLVMConversion.cpp | 10 +++----- .../Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp | 9 +++---- mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp | 3 +-- .../GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp | 11 ++++---- mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp | 4 +-- mlir/lib/Conversion/LLVMCommon/Pattern.cpp | 4 +-- mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp | 7 ++---- mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp | 8 +++--- mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp | 22 +++++++--------- 16 files changed, 77 insertions(+), 92 deletions(-) diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index ed4b71b..b622203 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -53,8 +53,7 @@ static mlir::LLVM::ConstantOp genConstantIndex(mlir::Location loc, mlir::Type ity, mlir::ConversionPatternRewriter &rewriter, std::int64_t offset) { - auto cattr = rewriter.getI64IntegerAttr(offset); - return rewriter.create(loc, ity, cattr); + return rewriter.create(loc, ity, offset); } static mlir::Block *createBlock(mlir::ConversionPatternRewriter &rewriter, @@ -102,8 +101,7 @@ protected: genI32Constant(mlir::Location loc, mlir::ConversionPatternRewriter &rewriter, int value) const { mlir::Type i32Ty = rewriter.getI32Type(); - mlir::IntegerAttr attr = rewriter.getI32IntegerAttr(value); - return rewriter.create(loc, i32Ty, attr); + return rewriter.create(loc, i32Ty, value); } mlir::LLVM::ConstantOp @@ -111,8 +109,7 @@ protected: mlir::ConversionPatternRewriter &rewriter, int offset) const { mlir::Type ity = lowerTy().offsetType(); - mlir::IntegerAttr cattr = rewriter.getI32IntegerAttr(offset); - return rewriter.create(loc, ity, cattr); + return rewriter.create(loc, ity, offset); } /// Perform an extension or truncation as needed on an integer value. Lowering @@ -630,13 +627,11 @@ struct StringLitOpConversion : public FIROpConversion { if (auto arr = attr.dyn_cast()) { cst = rewriter.create(loc, ty, arr); } else if (auto arr = attr.dyn_cast()) { - for (auto a : llvm::enumerate(arr.getValue())) { + for (auto &a : + llvm::enumerate(arr.getAsValueRange())) { // convert each character to a precise bitsize - auto elemAttr = mlir::IntegerAttr::get( - intTy, - a.value().cast().getValue().zextOrTrunc(bits)); - auto elemCst = - rewriter.create(loc, intTy, elemAttr); + auto elemCst = rewriter.create( + loc, intTy, a.value().zextOrTrunc(bits)); auto index = mlir::ArrayAttr::get( constop.getContext(), rewriter.getI32IntegerAttr(a.index())); cst = rewriter.create(loc, ty, cst, elemCst, @@ -733,12 +728,10 @@ struct ConstcOpConversion : public FIROpConversion { mlir::MLIRContext *ctx = conc.getContext(); mlir::Type ty = convertType(conc.getType()); mlir::Type ety = convertType(getComplexEleTy(conc.getType())); - auto realFloatAttr = mlir::FloatAttr::get(ety, getValue(conc.getReal())); - auto realPart = - rewriter.create(loc, ety, realFloatAttr); - auto imFloatAttr = mlir::FloatAttr::get(ety, getValue(conc.getImaginary())); - auto imPart = - rewriter.create(loc, ety, imFloatAttr); + auto realPart = rewriter.create( + loc, ety, getValue(conc.getReal())); + auto imPart = rewriter.create( + loc, ety, getValue(conc.getImaginary())); auto realIndex = mlir::ArrayAttr::get(ctx, rewriter.getI32IntegerAttr(0)); auto imIndex = mlir::ArrayAttr::get(ctx, rewriter.getI32IntegerAttr(1)); auto undef = rewriter.create(loc, ty); diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp index c72275a..6dfcb9f 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp @@ -154,9 +154,8 @@ private: // Get the pointer to the first character in the global string. Value globalPtr = builder.create(loc, global); - Value cst0 = builder.create( - loc, IntegerType::get(builder.getContext(), 64), - builder.getIntegerAttr(builder.getIndexType(), 0)); + Value cst0 = builder.create(loc, builder.getI64Type(), + builder.getIndexAttr(0)); return builder.create( loc, LLVM::LLVMPointerType::get(IntegerType::get(builder.getContext(), 8)), diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp index c72275a..85c914a 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp @@ -154,10 +154,8 @@ private: // Get the pointer to the first character in the global string. Value globalPtr = builder.create(loc, global); - Value cst0 = builder.create( - loc, IntegerType::get(builder.getContext(), 64), - builder.getIntegerAttr(builder.getIndexType(), 0)); - return builder.create( + Value cst0 = builder.create(loc, builder.getI64Type(), + builder.getIndexAttr(0)); loc, LLVM::LLVMPointerType::get(IntegerType::get(builder.getContext(), 8)), globalPtr, ArrayRef({cst0, cst0})); diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 9961751..d12ba55 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1521,8 +1521,25 @@ def LLVM_ConstantOp let arguments = (ins AnyAttr:$value); let results = (outs LLVM_Type:$res); - let builders = [LLVM_OneResultOpBuilder]; + let assemblyFormat = "`(` $value `)` attr-dict `:` type($res)"; + + let builders = [ + LLVM_OneResultOpBuilder, + OpBuilder<(ins "Type":$type, "int64_t":$value), [{ + build($_builder, $_state, type, $_builder.getIntegerAttr(type, value)); + }]>, + OpBuilder<(ins "Type":$type, "const APInt &":$value), [{ + build($_builder, $_state, type, $_builder.getIntegerAttr(type, value)); + }]>, + OpBuilder<(ins "Type":$type, "const APFloat &":$value), [{ + build($_builder, $_state, type, $_builder.getFloatAttr(type, value)); + }]>, + OpBuilder<(ins "TypedAttr":$value), [{ + build($_builder, $_state, value.getType(), value); + }]> + ]; + let hasFolder = 1; let hasVerifier = 1; } diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp index c532906..0e2894a 100644 --- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp +++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp @@ -18,9 +18,8 @@ using namespace mlir::amdgpu; static Value createI32Constant(ConversionPatternRewriter &rewriter, Location loc, int32_t value) { - IntegerAttr valAttr = rewriter.getI32IntegerAttr(value); Type llvmI32 = rewriter.getI32Type(); - return rewriter.create(loc, llvmI32, valAttr); + return rewriter.create(loc, llvmI32, value); } namespace { @@ -118,8 +117,7 @@ struct RawBufferOpLowering : public ConvertOpToLLVMPattern { MemRefDescriptor memrefDescriptor(memref); Type llvmI64 = this->typeConverter->convertType(rewriter.getI64Type()); Type llvm2xI32 = this->typeConverter->convertType(VectorType::get(2, i32)); - Value c32I64 = rewriter.create( - loc, llvmI64, rewriter.getI64IntegerAttr(32)); + Value c32I64 = rewriter.create(loc, llvmI64, 32); Value resource = rewriter.create(loc, llvm4xI32); diff --git a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp index b923b8c..e793065 100644 --- a/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp +++ b/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp @@ -311,8 +311,8 @@ public: auto loc = op->getLoc(); // Constants for initializing coroutine frame. - auto constZero = rewriter.create( - loc, rewriter.getI32Type(), rewriter.getI32IntegerAttr(0)); + auto constZero = + rewriter.create(loc, rewriter.getI32Type(), 0); auto nullPtr = rewriter.create(loc, i8Ptr); // Get coroutine id: @llvm.coro.id. @@ -351,7 +351,7 @@ public: // parameter. auto makeConstant = [&](uint64_t c) { return rewriter.create( - op->getLoc(), rewriter.getI64Type(), rewriter.getI64IntegerAttr(c)); + op->getLoc(), rewriter.getI64Type(), c); }; coroSize = rewriter.create(op->getLoc(), coroSize, coroAlign); coroSize = diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp index 62f1f50..a62191d 100644 --- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp @@ -120,8 +120,7 @@ GPUFuncOpLowering::matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor, .template cast(), allocaAddrSpace); Value numElements = rewriter.create( - gpuFuncOp.getLoc(), int64Ty, - rewriter.getI64IntegerAttr(type.getNumElements())); + gpuFuncOp.getLoc(), int64Ty, type.getNumElements()); Value allocated = rewriter.create( gpuFuncOp.getLoc(), ptrType, numElements, /*alignment=*/0); auto descr = MemRefDescriptor::fromStaticShape( @@ -219,8 +218,7 @@ LogicalResult GPUPrintfOpToHIPLowering::matchAndRewrite( {llvmI64, i8Ptr, /*length (bytes)*/ llvmI64, /*isLast*/ llvmI32})); /// Start the printf hostcall - Value zeroI64 = rewriter.create( - loc, llvmI64, rewriter.getI64IntegerAttr(0)); + Value zeroI64 = rewriter.create(loc, llvmI64, 0); auto printfBeginCall = rewriter.create(loc, ocklBegin, zeroI64); Value printfDesc = printfBeginCall.getResult(0); @@ -251,13 +249,11 @@ LogicalResult GPUPrintfOpToHIPLowering::matchAndRewrite( Value globalPtr = rewriter.create(loc, global); Value stringStart = rewriter.create( loc, i8Ptr, globalPtr, ArrayRef{0, 0}); - Value stringLen = rewriter.create( - loc, llvmI64, rewriter.getI64IntegerAttr(formatStringSize)); + Value stringLen = + rewriter.create(loc, llvmI64, formatStringSize); - Value oneI32 = rewriter.create( - loc, llvmI32, rewriter.getI32IntegerAttr(1)); - Value zeroI32 = rewriter.create( - loc, llvmI32, rewriter.getI32IntegerAttr(0)); + Value oneI32 = rewriter.create(loc, llvmI32, 1); + Value zeroI32 = rewriter.create(loc, llvmI32, 0); auto appendFormatCall = rewriter.create( loc, ocklAppendStringN, @@ -274,8 +270,8 @@ LogicalResult GPUPrintfOpToHIPLowering::matchAndRewrite( SmallVector arguments; arguments.push_back(printfDesc); - arguments.push_back(rewriter.create( - loc, llvmI32, rewriter.getI32IntegerAttr(numArgsThisCall))); + arguments.push_back( + rewriter.create(loc, llvmI32, numArgsThisCall)); for (size_t i = group; i < bound; ++i) { Value arg = adaptor.args()[i]; if (auto floatType = arg.getType().dyn_cast()) { diff --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp index 40159aa..2704e14 100644 --- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp @@ -675,12 +675,11 @@ Value ConvertLaunchFuncOpToGpuRuntimeCallPattern::generateParamsArray( argumentTypes.push_back(argument.getType()); auto structType = LLVM::LLVMStructType::getNewIdentified(context, StringRef(), argumentTypes); - auto one = builder.create(loc, llvmInt32Type, - builder.getI32IntegerAttr(1)); + auto one = builder.create(loc, llvmInt32Type, 1); auto structPtr = builder.create( loc, LLVM::LLVMPointerType::get(structType), one, /*alignment=*/0); - auto arraySize = builder.create( - loc, llvmInt32Type, builder.getI32IntegerAttr(numArguments)); + auto arraySize = + builder.create(loc, llvmInt32Type, numArguments); auto arrayPtr = builder.create(loc, llvmPointerPointerType, arraySize, /*alignment=*/0); for (const auto &en : llvm::enumerate(arguments)) { @@ -786,8 +785,7 @@ LogicalResult ConvertLaunchFuncOpToGpuRuntimeCallPattern::matchAndRewrite( launchOp.getKernelName().getValue(), loc, rewriter); auto function = moduleGetFunctionCallBuilder.create( loc, rewriter, {module.getResult(0), kernelName}); - auto zero = rewriter.create(loc, llvmInt32Type, - rewriter.getI32IntegerAttr(0)); + auto zero = rewriter.create(loc, llvmInt32Type, 0); Value stream = adaptor.asyncDependencies().empty() ? streamCreateCallBuilder.create(loc, rewriter, {}).getResult(0) diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp index 342ae35..1f467cb 100644 --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -89,12 +89,9 @@ struct GPUShuffleOpLowering : public ConvertOpToLLVMPattern { auto resultTy = LLVM::LLVMStructType::getLiteral(rewriter.getContext(), {valueTy, predTy}); - Value one = rewriter.create( - loc, int32Type, rewriter.getI32IntegerAttr(1)); - Value minusOne = rewriter.create( - loc, int32Type, rewriter.getI32IntegerAttr(-1)); - Value thirtyTwo = rewriter.create( - loc, int32Type, rewriter.getI32IntegerAttr(32)); + Value one = rewriter.create(loc, int32Type, 1); + Value minusOne = rewriter.create(loc, int32Type, -1); + Value thirtyTwo = rewriter.create(loc, int32Type, 32); Value numLeadInactiveLane = rewriter.create( loc, int32Type, thirtyTwo, adaptor.width()); // Bit mask of active lanes: `(-1) >> (32 - activeWidth)`. diff --git a/mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp b/mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp index 0df1ae8..ee924ff 100644 --- a/mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/WmmaOpsToNvvm.cpp @@ -260,8 +260,7 @@ struct WmmaConstantOpToNVVMLowering Value vecCst = rewriter.create(loc, vecType); for (int64_t vecEl = 0; vecEl < vecType.getNumElements(); vecEl++) { Value idx = rewriter.create( - loc, typeConverter->convertType(rewriter.getIntegerType(32)), - rewriter.getI32IntegerAttr(vecEl)); + loc, rewriter.getI32Type(), vecEl); vecCst = rewriter.create(loc, vecType, vecCst, cst, idx); } diff --git a/mlir/lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp b/mlir/lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp index 9428de0..09e3ec4 100644 --- a/mlir/lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp +++ b/mlir/lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp @@ -218,15 +218,15 @@ void VulkanLaunchFuncToVulkanCallsPass::createBindMemRefCalls( // Create LLVM constant for the descriptor set index. // Bind all memrefs to the `0` descriptor set, the same way as `GPUToSPIRV` // pass does. - Value descriptorSet = builder.create( - loc, getInt32Type(), builder.getI32IntegerAttr(0)); + Value descriptorSet = + builder.create(loc, getInt32Type(), 0); for (const auto &en : llvm::enumerate(cInterfaceVulkanLaunchCallOp.getOperands().drop_front( kVulkanLaunchNumConfigOperands))) { // Create LLVM constant for the descriptor binding index. - Value descriptorBinding = builder.create( - loc, getInt32Type(), builder.getI32IntegerAttr(en.index())); + Value descriptorBinding = + builder.create(loc, getInt32Type(), en.index()); auto ptrToMemRefDescriptor = en.value(); uint32_t rank = 0; @@ -384,8 +384,7 @@ void VulkanLaunchFuncToVulkanCallsPass::translateVulkanLaunchCall( // Create LLVM constant for the size of SPIR-V binary shader. Value binarySize = builder.create( - loc, getInt32Type(), - builder.getI32IntegerAttr(spirvAttributes.first.getValue().size())); + loc, getInt32Type(), spirvAttributes.first.getValue().size()); // Create call to `bindMemRef` for each memref operand. createBindMemRefCalls(cInterfaceVulkanLaunchCallOp, vulkanRuntime); diff --git a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp index df21c428..4849dd0 100644 --- a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp +++ b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp @@ -98,8 +98,8 @@ void MemRefDescriptor::setAlignedPtr(OpBuilder &builder, Location loc, // integer attribute. static Value createIndexAttrConstant(OpBuilder &builder, Location loc, Type resultType, int64_t value) { - return builder.create( - loc, resultType, builder.getIntegerAttr(builder.getIndexType(), value)); + return builder.create(loc, resultType, + builder.getIndexAttr(value)); } /// Builds IR extracting the offset from the descriptor. diff --git a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp index b6288f5..c1fb158 100644 --- a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp +++ b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp @@ -56,8 +56,8 @@ Value ConvertToLLVMPattern::createIndexAttrConstant(OpBuilder &builder, Location loc, Type resultType, int64_t value) { - return builder.create( - loc, resultType, builder.getIntegerAttr(builder.getIndexType(), value)); + return builder.create(loc, resultType, + builder.getIndexAttr(value)); } Value ConvertToLLVMPattern::createIndexConstant( diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp index 2c0631b91..aec2d3f 100644 --- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp +++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp @@ -474,14 +474,11 @@ Type LLVMTypeConverter::packFunctionResults(TypeRange types) { Value LLVMTypeConverter::promoteOneMemRefDescriptor(Location loc, Value operand, OpBuilder &builder) { - auto *context = builder.getContext(); - auto int64Ty = IntegerType::get(builder.getContext(), 64); - auto indexType = IndexType::get(context); // Alloca with proper alignment. We do not expect optimizations of this // alloca op and so we omit allocating at the entry block. auto ptrType = LLVM::LLVMPointerType::get(operand.getType()); - Value one = builder.create(loc, int64Ty, - IntegerAttr::get(indexType, 1)); + Value one = builder.create(loc, builder.getI64Type(), + builder.getIndexAttr(1)); Value allocated = builder.create(loc, ptrType, one, /*alignment=*/0); // Store into the alloca'ed descriptor. diff --git a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp index 77fc91d..1cd24cd 100644 --- a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp +++ b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp @@ -57,12 +57,10 @@ struct CountOpLowering : public ConvertOpToLLVMPattern { auto loc = op.getLoc(); auto resultType = op.getResult().getType(); - auto boolType = rewriter.getIntegerType(1); - auto boolZero = rewriter.getIntegerAttr(boolType, 0); + auto boolZero = rewriter.getBoolAttr(false); if (!operandType.template isa()) { - LLVM::ConstantOp zero = - rewriter.create(loc, boolType, boolZero); + LLVM::ConstantOp zero = rewriter.create(loc, boolZero); rewriter.replaceOpWithNewOp(op, resultType, adaptor.getOperand(), zero); return success(); @@ -76,7 +74,7 @@ struct CountOpLowering : public ConvertOpToLLVMPattern { op.getOperation(), adaptor.getOperands(), *this->getTypeConverter(), [&](Type llvm1DVectorTy, ValueRange operands) { LLVM::ConstantOp zero = - rewriter.create(loc, boolType, boolZero); + rewriter.create(loc, boolZero); return rewriter.create(loc, llvm1DVectorTy, operands[0], zero); }, diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp index ee80825..bb120b7 100644 --- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp +++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp @@ -727,14 +727,12 @@ struct PrefetchOpLowering : public LoadStoreOpLowering { // Replace with llvm.prefetch. auto llvmI32Type = typeConverter->convertType(rewriter.getIntegerType(32)); - auto isWrite = rewriter.create( - loc, llvmI32Type, rewriter.getI32IntegerAttr(prefetchOp.getIsWrite())); + auto isWrite = rewriter.create(loc, llvmI32Type, + prefetchOp.getIsWrite()); auto localityHint = rewriter.create( - loc, llvmI32Type, - rewriter.getI32IntegerAttr(prefetchOp.getLocalityHint())); + loc, llvmI32Type, prefetchOp.getLocalityHint()); auto isData = rewriter.create( - loc, llvmI32Type, - rewriter.getI32IntegerAttr(prefetchOp.getIsDataCache())); + loc, llvmI32Type, prefetchOp.getIsDataCache()); rewriter.replaceOpWithNewOp(prefetchOp, dataPtr, isWrite, localityHint, isData); @@ -889,9 +887,8 @@ struct MemRefCopyOpLowering : public ConvertOpToLLVMPattern { Value targetOffset = targetDesc.offset(rewriter, loc); Value targetPtr = rewriter.create(loc, targetBasePtr.getType(), targetBasePtr, targetOffset); - Value isVolatile = rewriter.create( - loc, typeConverter->convertType(rewriter.getI1Type()), - rewriter.getBoolAttr(false)); + Value isVolatile = + rewriter.create(loc, rewriter.getBoolAttr(false)); rewriter.create(loc, targetPtr, srcPtr, totalSize, isVolatile); rewriter.eraseOp(op); @@ -908,8 +905,8 @@ struct MemRefCopyOpLowering : public ConvertOpToLLVMPattern { // First make sure we have an unranked memref descriptor representation. auto makeUnranked = [&, this](Value ranked, BaseMemRefType type) { - auto rank = rewriter.create( - loc, getIndexType(), rewriter.getIndexAttr(type.getRank())); + auto rank = rewriter.create(loc, getIndexType(), + type.getRank()); auto *typeConverter = getTypeConverter(); auto ptr = typeConverter->promoteOneMemRefDescriptor(loc, ranked, rewriter); @@ -1524,8 +1521,7 @@ static void fillInStridesForCollapsedMemDescriptor( break; } Value one = rewriter.create( - loc, typeConverter->convertType(rewriter.getI64Type()), - rewriter.getI32IntegerAttr(1)); + loc, rewriter.getI64Type(), rewriter.getI32IntegerAttr(1)); Value predNeOne = rewriter.create( loc, LLVM::ICmpPredicate::ne, srcDesc.size(rewriter, loc, srcIndex), one); -- 2.7.4