[mlir][ODS] Add `constBuilderCall` to `Dense*ArrayAttr`s

These are useful in builders of Ops taking DenseArrayAttrs or for use in Rewriter, to create constant instances.

Differential Revision: https://reviews.llvm.org/D132067
This commit is contained in:
Markus Böck 2022-08-17 22:17:58 +02:00
parent 19ce5e515f
commit f289c47b5e
5 changed files with 6 additions and 12 deletions

View File

@ -770,11 +770,6 @@ def LLVM_InsertValueOp : LLVM_Op<
DenseI64ArrayAttr:$position);
let results = (outs LLVM_AnyAggregate:$res);
let builders = [
OpBuilder<(ins "Value":$container, "Value":$value,
"ArrayRef<int64_t>":$position)>
];
let assemblyFormat = [{
$value `,` $container `` $position attr-dict `:` type($container)
custom<InsertExtractValueElementType>(type($value), ref(type($container)),

View File

@ -138,6 +138,7 @@ public:
DenseIntElementsAttr getIndexTensorAttr(ArrayRef<int64_t> values);
/// Tensor-typed DenseArrayAttr getters.
DenseBoolArrayAttr getDenseBoolArrayAttr(ArrayRef<bool> values);
DenseI8ArrayAttr getDenseI8ArrayAttr(ArrayRef<int8_t> values);
DenseI16ArrayAttr getDenseI16ArrayAttr(ArrayRef<int16_t> values);
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef<int32_t> values);

View File

@ -1291,6 +1291,7 @@ class DenseArrayAttrBase<string denseAttrName, string cppType, string summaryNam
summaryName # " dense array attribute"> {
let storageType = "::mlir::" # denseAttrName;
let returnType = "::llvm::ArrayRef<" # cppType # ">";
let constBuilderCall = "$_builder.get" # denseAttrName # "($0)";
}
def DenseBoolArrayAttr : DenseArrayAttrBase<"DenseBoolArrayAttr", "bool", "i1">;
def DenseI8ArrayAttr : DenseArrayAttrBase<"DenseI8ArrayAttr", "int8_t", "i8">;

View File

@ -1619,13 +1619,6 @@ LogicalResult InsertValueOp::verify() {
return success();
}
void InsertValueOp::build(OpBuilder &builder, OperationState &state,
Value container, Value value,
ArrayRef<int64_t> position) {
build(builder, state, container.getType(), container, value,
builder.getAttr<DenseI64ArrayAttr>(position));
}
//===----------------------------------------------------------------------===//
// ReturnOp
//===----------------------------------------------------------------------===//

View File

@ -124,6 +124,10 @@ DenseIntElementsAttr Builder::getIndexVectorAttr(ArrayRef<int64_t> values) {
values);
}
DenseBoolArrayAttr Builder::getDenseBoolArrayAttr(ArrayRef<bool> values) {
return DenseBoolArrayAttr::get(context, values);
}
DenseI8ArrayAttr Builder::getDenseI8ArrayAttr(ArrayRef<int8_t> values) {
return DenseI8ArrayAttr::get(context, values);
}