summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Zinenko <zinenko@google.com>2019-09-16 03:30:33 -0700
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-09-16 03:31:09 -0700
commit6755dfdec9e4af64109d5767ad374d1d5fd2c95d (patch)
tree6a51f21cb88465aa5ea8af2e7e690ff02f79c32c
parent9814b3fa0ddc497f215813ca261dc97214e53295 (diff)
downloadbcm5719-llvm-6755dfdec9e4af64109d5767ad374d1d5fd2c95d.tar.gz
bcm5719-llvm-6755dfdec9e4af64109d5767ad374d1d5fd2c95d.zip
Drop makePositionAttr and the like in favor of Builder::getI64ArrayAttr
The helper functions makePositionAttr() and positionAttr() were originally introduced in the lowering-to-LLVM-dialect pass to construct integer array attributes that are used for static positions in extract/insertelement. Constructing an integer array attribute being fairly common, a utility function Builder::getI64ArrayAttr was later introduced into the Builder API. Drop makePositionAttr and similar homegrown functions and use that API instead. PiperOrigin-RevId: 269295836
-rw-r--r--mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp24
-rw-r--r--mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp14
-rw-r--r--mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp19
-rw-r--r--mlir/lib/Dialect/Linalg/Transforms/LowerToLLVMDialect.cpp38
4 files changed, 28 insertions, 67 deletions
diff --git a/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp b/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
index abbd9c95ac9..48beba77d72 100644
--- a/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
+++ b/mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
@@ -122,16 +122,6 @@ Type linalg::convertLinalgType(Type t) {
return t;
}
-// Create an array attribute containing integer attributes with values provided
-// in `position`.
-static ArrayAttr makePositionAttr(OpBuilder &builder, ArrayRef<int> position) {
- SmallVector<Attribute, 4> attrs;
- attrs.reserve(position.size());
- for (auto p : position)
- attrs.push_back(builder.getI64IntegerAttr(p));
- return builder.getArrayAttr(attrs);
-}
-
// RangeOp creates a new range descriptor.
class RangeOpConversion : public ConversionPattern {
public:
@@ -151,11 +141,11 @@ public:
// Fill in an aggregate value of the descriptor.
Value *rangeDescriptor = undef(rangeDescriptorType);
rangeDescriptor = insertvalue(rangeDescriptorType, rangeDescriptor,
- operands[0], makePositionAttr(rewriter, 0));
+ operands[0], rewriter.getI64ArrayAttr(0));
rangeDescriptor = insertvalue(rangeDescriptorType, rangeDescriptor,
- operands[1], makePositionAttr(rewriter, 1));
+ operands[1], rewriter.getI64ArrayAttr(1));
rangeDescriptor = insertvalue(rangeDescriptorType, rangeDescriptor,
- operands[2], makePositionAttr(rewriter, 2));
+ operands[2], rewriter.getI64ArrayAttr(2));
rewriter.replaceOp(op, rangeDescriptor);
return matchSuccess();
}
@@ -177,8 +167,8 @@ public:
// Helper function to create an integer array attribute out of a list of
// values.
- auto pos = [&rewriter](ArrayRef<int> values) {
- return makePositionAttr(rewriter, values);
+ auto pos = [&rewriter](ArrayRef<int64_t> values) {
+ return rewriter.getI64ArrayAttr(values);
};
// Helper function to emit an LLVMIR Dialect 64-bit integer constant given
@@ -303,8 +293,8 @@ public:
.getPointerTo();
auto int64Ty = linalg::convertLinalgType(rewriter.getIntegerType(64));
- auto pos = [&rewriter](ArrayRef<int> values) {
- return makePositionAttr(rewriter, values);
+ auto pos = [&rewriter](ArrayRef<int64_t> values) {
+ return rewriter.getI64ArrayAttr(values);
};
// First operand to `slice` is the old view descriptor.
diff --git a/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp b/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
index ea3f700e733..0932bdd6746 100644
--- a/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
+++ b/mlir/examples/Linalg/Linalg3/lib/ConvertToLLVMDialect.cpp
@@ -40,16 +40,6 @@
using namespace mlir;
-// Create an array attribute containing integer attributes with values provided
-// in `position`.
-static ArrayAttr makePositionAttr(Builder &builder, ArrayRef<int> position) {
- SmallVector<Attribute, 4> attrs;
- attrs.reserve(position.size());
- for (auto p : position)
- attrs.push_back(builder.getI64IntegerAttr(p));
- return builder.getArrayAttr(attrs);
-}
-
namespace {
// Common functionality for Linalg LoadOp and StoreOp conversion to the
// LLVM IR Dialect.
@@ -73,8 +63,8 @@ public:
.getPointerTo();
auto int64Ty = linalg::convertLinalgType(rewriter.getIntegerType(64));
- auto pos = [&rewriter](ArrayRef<int> values) {
- return makePositionAttr(rewriter, values);
+ auto pos = [&rewriter](ArrayRef<int64_t> values) {
+ return rewriter.getI64ArrayAttr(values);
};
using namespace intrinsics;
diff --git a/mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp
index 2b15637ae14..38037c2596b 100644
--- a/mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/VectorToLLVM.cpp
@@ -49,16 +49,6 @@ static LLVM::LLVMType getPtrToElementType(T containerType,
.getPointerTo();
}
-// Create an array attribute containing integer attributes with values provided
-// in `position`.
-static ArrayAttr positionAttr(Builder &builder, ArrayRef<int> position) {
- SmallVector<Attribute, 4> attrs;
- attrs.reserve(position.size());
- for (auto p : position)
- attrs.push_back(builder.getI64IntegerAttr(p));
- return builder.getArrayAttr(attrs);
-}
-
class ExtractElementOpConversion : public LLVMOpLowering {
public:
explicit ExtractElementOpConversion(MLIRContext *context,
@@ -148,16 +138,17 @@ public:
aD = rewriter.create<LLVM::ShuffleVectorOp>(loc, a, a, bcastArrayAttr);
// 2. If acc is present, extract 1-d vector acc[d] into accD.
if (acc)
- accD = rewriter.create<LLVM::ExtractValueOp>(loc, vRHS, acc,
- positionAttr(rewriter, d));
+ accD = rewriter.create<LLVM::ExtractValueOp>(
+ loc, vRHS, acc, rewriter.getI64ArrayAttr(d));
// 3. Compute aD outer b (plus accD, if relevant).
Value *aOuterbD =
accD ? rewriter.create<LLVM::fmuladd>(loc, vRHS, aD, b, accD)
.getResult()
: rewriter.create<LLVM::FMulOp>(loc, aD, b).getResult();
// 4. Insert as value `d` in the descriptor.
- desc = rewriter.create<LLVM::InsertValueOp>(
- loc, llvmArrayOfVectType, desc, aOuterbD, positionAttr(rewriter, d));
+ desc = rewriter.create<LLVM::InsertValueOp>(loc, llvmArrayOfVectType,
+ desc, aOuterbD,
+ rewriter.getI64ArrayAttr(d));
}
rewriter.replaceOp(op, desc);
return matchSuccess();
diff --git a/mlir/lib/Dialect/Linalg/Transforms/LowerToLLVMDialect.cpp b/mlir/lib/Dialect/Linalg/Transforms/LowerToLLVMDialect.cpp
index 48b4eda8697..4115a5099bb 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/LowerToLLVMDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/LowerToLLVMDialect.cpp
@@ -164,16 +164,6 @@ static constexpr int kOffsetPosInView = 1;
static constexpr int kSizePosInView = 2;
static constexpr int kStridePosInView = 3;
-// Create an array attribute containing integer attributes with values provided
-// in `position`.
-static ArrayAttr positionAttr(Builder &builder, ArrayRef<int> position) {
- SmallVector<Attribute, 4> attrs;
- attrs.reserve(position.size());
- for (auto p : position)
- attrs.push_back(builder.getI64IntegerAttr(p));
- return builder.getArrayAttr(attrs);
-}
-
namespace {
/// Factor out the common information for all view conversions:
/// 1. common types in (standard and LLVM dialects)
@@ -192,8 +182,8 @@ public:
desc = rewriter.create<LLVM::UndefOp>(op->getLoc(), viewDescriptorTy);
}
- ArrayAttr pos(ArrayRef<int> values) const {
- return positionAttr(rewriter, values);
+ ArrayAttr pos(ArrayRef<int64_t> values) const {
+ return rewriter.getI64ArrayAttr(values);
};
LLVMType elementTy, int64Ty, viewDescriptorTy;
@@ -273,11 +263,11 @@ public:
data = bitcast(elementPtrType, data);
Value *desc = llvm_undef(bufferDescriptorTy);
desc = insertvalue(bufferDescriptorTy, desc, allocated,
- positionAttr(rewriter, kBasePtrPosInBuffer));
+ rewriter.getI64ArrayAttr(kBasePtrPosInBuffer));
desc = insertvalue(bufferDescriptorTy, desc, data,
- positionAttr(rewriter, kPtrPosInBuffer));
+ rewriter.getI64ArrayAttr(kPtrPosInBuffer));
desc = insertvalue(bufferDescriptorTy, desc, size,
- positionAttr(rewriter, kSizePosInBuffer));
+ rewriter.getI64ArrayAttr(kSizePosInBuffer));
rewriter.replaceOp(op, desc);
return matchSuccess();
}
@@ -309,7 +299,7 @@ public:
BufferDeallocOpOperandAdaptor adaptor(operands);
edsc::ScopedContext context(rewriter, op->getLoc());
Value *base = extractvalue(voidPtrTy, adaptor.buffer(),
- positionAttr(rewriter, kBasePtrPosInBuffer));
+ rewriter.getI64ArrayAttr(kBasePtrPosInBuffer));
llvm_call(ArrayRef<Type>(), rewriter.getSymbolRefAttr(freeFunc), base);
rewriter.replaceOp(op, llvm::None);
return matchSuccess();
@@ -330,7 +320,7 @@ public:
BufferSizeOpOperandAdaptor adaptor(operands);
rewriter.replaceOp(
op, {extractvalue(int64Ty, adaptor.buffer(),
- positionAttr(rewriter, kSizePosInBuffer))});
+ rewriter.getI64ArrayAttr(kSizePosInBuffer))});
return matchSuccess();
}
};
@@ -347,8 +337,8 @@ public:
auto dimOp = cast<linalg::DimOp>(op);
auto indexTy = lowering.convertType(rewriter.getIndexType());
edsc::ScopedContext context(rewriter, op->getLoc());
- auto pos = positionAttr(
- rewriter, {kSizePosInView, static_cast<int>(dimOp.getIndex())});
+ auto pos = rewriter.getI64ArrayAttr(
+ {kSizePosInView, static_cast<int>(dimOp.getIndex())});
linalg::DimOpOperandAdaptor adaptor(operands);
Value *viewDescriptor = adaptor.view();
rewriter.replaceOp(op, {extractvalue(indexTy, viewDescriptor, pos)});
@@ -376,8 +366,8 @@ public:
auto loadOp = cast<Op>(op);
auto elementTy = getPtrToElementType(loadOp.getViewType(), lowering);
auto int64Ty = lowering.convertType(rewriter.getIntegerType(64));
- auto pos = [&rewriter](ArrayRef<int> values) {
- return positionAttr(rewriter, values);
+ auto pos = [&rewriter](ArrayRef<int64_t> values) {
+ return rewriter.getI64ArrayAttr(values);
};
// Linearize subscripts as:
@@ -430,9 +420,9 @@ public:
// Fill in an aggregate value of the descriptor.
RangeOpOperandAdaptor adaptor(operands);
Value *desc = llvm_undef(rangeDescriptorTy);
- desc = insertvalue(desc, adaptor.min(), positionAttr(rewriter, 0));
- desc = insertvalue(desc, adaptor.max(), positionAttr(rewriter, 1));
- desc = insertvalue(desc, adaptor.step(), positionAttr(rewriter, 2));
+ desc = insertvalue(desc, adaptor.min(), rewriter.getI64ArrayAttr(0));
+ desc = insertvalue(desc, adaptor.max(), rewriter.getI64ArrayAttr(1));
+ desc = insertvalue(desc, adaptor.step(), rewriter.getI64ArrayAttr(2));
rewriter.replaceOp(op, desc);
return matchSuccess();
}
OpenPOWER on IntegriCloud