14 changes: 7 additions & 7 deletions mlir/examples/toy/Ch7/mlir/Dialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mlir::ParseResult ConstantOp::parse(mlir::OpAsmParser &parser,
void ConstantOp::print(mlir::OpAsmPrinter &printer) {
printer << " ";
printer.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"value"});
printer << value();
printer << getValue();
}

/// Verify that the given attribute value is valid for the given type.
Expand Down Expand Up @@ -236,16 +236,16 @@ static mlir::LogicalResult verifyConstantForType(mlir::Type type,
/// Verifier for the constant operation. This corresponds to the `::verify(...)`
/// in the op definition.
mlir::LogicalResult ConstantOp::verify() {
return verifyConstantForType(getResult().getType(), value(), *this);
return verifyConstantForType(getResult().getType(), getValue(), *this);
}

mlir::LogicalResult StructConstantOp::verify() {
return verifyConstantForType(getResult().getType(), value(), *this);
return verifyConstantForType(getResult().getType(), getValue(), *this);
}

/// Infer the output shape of the ConstantOp, this is required by the shape
/// inference interface.
void ConstantOp::inferShapes() { getResult().setType(value().getType()); }
void ConstantOp::inferShapes() { getResult().setType(getValue().getType()); }

//===----------------------------------------------------------------------===//
// AddOp
Expand Down Expand Up @@ -354,7 +354,7 @@ CallInterfaceCallable GenericCallOp::getCallableForCallee() {

/// Get the argument operands to the called function, this is required by the
/// call interface.
Operation::operand_range GenericCallOp::getArgOperands() { return inputs(); }
Operation::operand_range GenericCallOp::getArgOperands() { return getInputs(); }

//===----------------------------------------------------------------------===//
// MulOp
Expand Down Expand Up @@ -430,8 +430,8 @@ void StructAccessOp::build(mlir::OpBuilder &b, mlir::OperationState &state,
}

mlir::LogicalResult StructAccessOp::verify() {
StructType structTy = input().getType().cast<StructType>();
size_t indexValue = index();
StructType structTy = getInput().getType().cast<StructType>();
size_t indexValue = getIndex();
if (indexValue >= structTy.getNumElementTypes())
return emitOpError()
<< "index should be within the range of the input struct type";
Expand Down
12 changes: 6 additions & 6 deletions mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ struct BinaryOpLowering : public ConversionPattern {

// Generate loads for the element of 'lhs' and 'rhs' at the inner
// loop.
auto loadedLhs =
builder.create<AffineLoadOp>(loc, binaryAdaptor.lhs(), loopIvs);
auto loadedRhs =
builder.create<AffineLoadOp>(loc, binaryAdaptor.rhs(), loopIvs);
auto loadedLhs = builder.create<AffineLoadOp>(
loc, binaryAdaptor.getLhs(), loopIvs);
auto loadedRhs = builder.create<AffineLoadOp>(
loc, binaryAdaptor.getRhs(), loopIvs);

// Create the binary operation performed on the loaded values.
return builder.create<LoweredBinaryOp>(loc, loadedLhs, loadedRhs);
Expand All @@ -138,7 +138,7 @@ struct ConstantOpLowering : public OpRewritePattern<toy::ConstantOp> {

LogicalResult matchAndRewrite(toy::ConstantOp op,
PatternRewriter &rewriter) const final {
DenseElementsAttr constantValue = op.value();
DenseElementsAttr constantValue = op.getValue();
Location loc = op.getLoc();

// When lowering the constant operation, we allocate and assign the constant
Expand Down Expand Up @@ -286,7 +286,7 @@ struct TransposeOpLowering : public ConversionPattern {
// TransposeOp. This allows for using the nice named
// accessors that are generated by the ODS.
toy::TransposeOpAdaptor transposeAdaptor(memRefOperands);
Value input = transposeAdaptor.input();
Value input = transposeAdaptor.getInput();

// Transpose the elements by generating a load from the
// reverse indices.
Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PrintOpLowering : public ConversionPattern {
// Generate a call to printf for the current element of the loop.
auto printOp = cast<toy::PrintOp>(op);
auto elementLoad =
rewriter.create<memref::LoadOp>(loc, printOp.input(), loopIvs);
rewriter.create<memref::LoadOp>(loc, printOp.getInput(), loopIvs);
rewriter.create<func::CallOp>(
loc, printfRef, rewriter.getIntegerType(32),
ArrayRef<Value>({formatSpecifierCst, elementLoad}));
Expand Down
8 changes: 5 additions & 3 deletions mlir/examples/toy/Ch7/mlir/ToyCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ namespace {
} // namespace

/// Fold constants.
OpFoldResult ConstantOp::fold(ArrayRef<Attribute> operands) { return value(); }
OpFoldResult ConstantOp::fold(ArrayRef<Attribute> operands) {
return getValue();
}

/// Fold struct constants.
OpFoldResult StructConstantOp::fold(ArrayRef<Attribute> operands) {
return value();
return getValue();
}

/// Fold simple struct access operations that access into a constant.
Expand All @@ -37,7 +39,7 @@ OpFoldResult StructAccessOp::fold(ArrayRef<Attribute> operands) {
if (!structAttr)
return nullptr;

size_t elementIndex = index();
size_t elementIndex = getIndex();
return structAttr[elementIndex];
}

Expand Down
114 changes: 54 additions & 60 deletions mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def PDLInterp_Dialect : Dialect {
/// to rewrite the IR after a successful match.
static StringRef getRewriterModuleName() { return "rewriters"; }
}];
let emitAccessorPrefix = kEmitAccessorPrefix_Prefixed;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -246,11 +247,11 @@ def PDLInterp_CheckOperandCountOp
```
}];

let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
Confined<I32Attr, [IntNonNegative]>:$count,
UnitAttr:$compareAtLeast);
let assemblyFormat = [{
`of` $operation `is` (`at_least` $compareAtLeast^)? $count attr-dict
`of` $inputOp `is` (`at_least` $compareAtLeast^)? $count attr-dict
`->` successors
}];
}
Expand All @@ -274,8 +275,8 @@ def PDLInterp_CheckOperationNameOp
```
}];

let arguments = (ins PDL_Operation:$operation, StrAttr:$name);
let assemblyFormat = "`of` $operation `is` $name attr-dict `->` successors";
let arguments = (ins PDL_Operation:$inputOp, StrAttr:$name);
let assemblyFormat = "`of` $inputOp `is` $name attr-dict `->` successors";
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -303,11 +304,11 @@ def PDLInterp_CheckResultCountOp
```
}];

let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
Confined<I32Attr, [IntNonNegative]>:$count,
UnitAttr:$compareAtLeast);
let assemblyFormat = [{
`of` $operation `is` (`at_least` $compareAtLeast^)? $count attr-dict
`of` $inputOp `is` (`at_least` $compareAtLeast^)? $count attr-dict
`->` successors
}];
}
Expand Down Expand Up @@ -432,11 +433,11 @@ def PDLInterp_CreateOperationOp
}];

let arguments = (ins StrAttr:$name,
Variadic<PDL_InstOrRangeOf<PDL_Value>>:$operands,
Variadic<PDL_Attribute>:$attributes,
StrArrayAttr:$attributeNames,
Variadic<PDL_InstOrRangeOf<PDL_Type>>:$types);
let results = (outs PDL_Operation:$operation);
Variadic<PDL_InstOrRangeOf<PDL_Value>>:$inputOperands,
Variadic<PDL_Attribute>:$inputAttributes,
StrArrayAttr:$inputAttributeNames,
Variadic<PDL_InstOrRangeOf<PDL_Type>>:$inputResultTypes);
let results = (outs PDL_Operation:$resultOp);

let builders = [
OpBuilder<(ins "StringRef":$name, "ValueRange":$types,
Expand All @@ -447,9 +448,9 @@ def PDLInterp_CreateOperationOp
}]>
];
let assemblyFormat = [{
$name (`(` $operands^ `:` type($operands) `)`)?
custom<CreateOperationOpAttributes>($attributes, $attributeNames)
(`->` `(` $types^ `:` type($types) `)`)? attr-dict
$name (`(` $inputOperands^ `:` type($inputOperands) `)`)?
custom<CreateOperationOpAttributes>($inputAttributes, $inputAttributeNames)
(`->` `(` $inputResultTypes^ `:` type($inputResultTypes) `)`)? attr-dict
}];
}

Expand Down Expand Up @@ -528,8 +529,8 @@ def PDLInterp_EraseOp : PDLInterp_Op<"erase"> {
```
}];

let arguments = (ins PDL_Operation:$operation);
let assemblyFormat = "$operation attr-dict";
let arguments = (ins PDL_Operation:$inputOp);
let assemblyFormat = "$inputOp attr-dict";
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -623,7 +624,7 @@ def PDLInterp_ForEachOp

let extraClassDeclaration = [{
/// Returns the loop variable.
BlockArgument getLoopVariable() { return region().getArgument(0); }
BlockArgument getLoopVariable() { return getRegion().getArgument(0); }
}];
let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
Expand Down Expand Up @@ -667,21 +668,15 @@ def PDLInterp_FuncOp : PDLInterp_Op<"func", [
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)
>];
let extraClassDeclaration = [{
/// Returns the type of this function.
/// FIXME: We should drive this via the ODS `type` param.
FunctionType getType() {
return getTypeAttr().getValue().cast<FunctionType>();
}

//===------------------------------------------------------------------===//
// FunctionOpInterface Methods
//===------------------------------------------------------------------===//

/// Returns the argument types of this function.
ArrayRef<Type> getArgumentTypes() { return type().getInputs(); }
ArrayRef<Type> getArgumentTypes() { return getType().getInputs(); }

/// Returns the result types of this function.
ArrayRef<Type> getResultTypes() { return type().getResults(); }
ArrayRef<Type> getResultTypes() { return getType().getResults(); }
}];
let hasCustomAssemblyFormat = 1;
let skipDefaultBuilders = 1;
Expand All @@ -705,10 +700,9 @@ def PDLInterp_GetAttributeOp : PDLInterp_Op<"get_attribute", [NoSideEffect]> {
```
}];

let arguments = (ins PDL_Operation:$operation,
StrAttr:$name);
let arguments = (ins PDL_Operation:$inputOp, StrAttr:$name);
let results = (outs PDL_Attribute:$attribute);
let assemblyFormat = "$name `of` $operation attr-dict";
let assemblyFormat = "$name `of` $inputOp attr-dict";
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -761,7 +755,7 @@ def PDLInterp_GetDefiningOpOp
}];

let arguments = (ins PDL_InstOrRangeOf<PDL_Value>:$value);
let results = (outs PDL_Operation:$operation);
let results = (outs PDL_Operation:$inputOp);
let assemblyFormat = "`of` $value `:` type($value) attr-dict";
}

Expand All @@ -783,10 +777,10 @@ def PDLInterp_GetOperandOp : PDLInterp_Op<"get_operand", [NoSideEffect]> {
```
}];

let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
Confined<I32Attr, [IntNonNegative]>:$index);
let results = (outs PDL_Value:$value);
let assemblyFormat = "$index `of` $operation attr-dict";
let assemblyFormat = "$index `of` $inputOp attr-dict";
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -818,15 +812,15 @@ def PDLInterp_GetOperandsOp : PDLInterp_Op<"get_operands", [NoSideEffect]> {
}];

let arguments = (ins
PDL_Operation:$operation,
PDL_Operation:$inputOp,
OptionalAttr<Confined<I32Attr, [IntNonNegative]>>:$index
);
let results = (outs PDL_InstOrRangeOf<PDL_Value>:$value);
let assemblyFormat = "($index^)? `of` $operation `:` type($value) attr-dict";
let assemblyFormat = "($index^)? `of` $inputOp `:` type($value) attr-dict";
let builders = [
OpBuilder<(ins "Type":$resultType, "Value":$operation,
OpBuilder<(ins "Type":$resultType, "Value":$inputOp,
"Optional<unsigned>":$index), [{
build($_builder, $_state, resultType, operation,
build($_builder, $_state, resultType, inputOp,
index ? $_builder.getI32IntegerAttr(*index) : IntegerAttr());
}]>,
];
Expand All @@ -850,10 +844,10 @@ def PDLInterp_GetResultOp : PDLInterp_Op<"get_result", [NoSideEffect]> {
```
}];

let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
Confined<I32Attr, [IntNonNegative]>:$index);
let results = (outs PDL_Value:$value);
let assemblyFormat = "$index `of` $operation attr-dict";
let assemblyFormat = "$index `of` $inputOp attr-dict";
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -885,20 +879,20 @@ def PDLInterp_GetResultsOp : PDLInterp_Op<"get_results", [NoSideEffect]> {
}];

let arguments = (ins
PDL_Operation:$operation,
PDL_Operation:$inputOp,
OptionalAttr<Confined<I32Attr, [IntNonNegative]>>:$index
);
let results = (outs PDL_InstOrRangeOf<PDL_Value>:$value);
let assemblyFormat = "($index^)? `of` $operation `:` type($value) attr-dict";
let assemblyFormat = "($index^)? `of` $inputOp `:` type($value) attr-dict";
let builders = [
OpBuilder<(ins "Type":$resultType, "Value":$operation,
OpBuilder<(ins "Type":$resultType, "Value":$inputOp,
"Optional<unsigned>":$index), [{
build($_builder, $_state, resultType, operation,
build($_builder, $_state, resultType, inputOp,
index ? $_builder.getI32IntegerAttr(*index) : IntegerAttr());
}]>,
OpBuilder<(ins "Value":$operation), [{
OpBuilder<(ins "Value":$inputOp), [{
build($_builder, $_state,
pdl::RangeType::get($_builder.getType<pdl::ValueType>()), operation,
pdl::RangeType::get($_builder.getType<pdl::ValueType>()), inputOp,
IntegerAttr());
}]>,
];
Expand Down Expand Up @@ -996,7 +990,7 @@ def PDLInterp_InferredTypesOp : PDLInterp_Op<"inferred_types"> {
%types = pdl_interp.inferred_types
```
}];
let results = (outs PDL_RangeOf<PDL_Type>:$type);
let results = (outs PDL_RangeOf<PDL_Type>:$result);
let assemblyFormat = "attr-dict";
let builders = [
OpBuilder<(ins), [{
Expand Down Expand Up @@ -1086,10 +1080,10 @@ def PDLInterp_ReplaceOp : PDLInterp_Op<"replace"> {
pdl_interp.replace %root with (%val0, %val1 : !pdl.type, !pdl.type)
```
}];
let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
Variadic<PDL_InstOrRangeOf<PDL_Value>>:$replValues);
let assemblyFormat = [{
$operation `with` ` ` `(` ($replValues^ `:` type($replValues))? `)`
$inputOp `with` ` ` `(` ($replValues^ `:` type($replValues))? `)`
attr-dict
}];
}
Expand Down Expand Up @@ -1147,15 +1141,15 @@ def PDLInterp_SwitchOperandCountOp
```
}];

let arguments = (ins PDL_Operation:$operation, I32ElementsAttr:$caseValues);
let arguments = (ins PDL_Operation:$inputOp, I32ElementsAttr:$caseValues);
let assemblyFormat = [{
`of` $operation `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
`of` $inputOp `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
}];

let builders = [
OpBuilder<(ins "Value":$operation, "ArrayRef<int32_t>":$counts,
OpBuilder<(ins "Value":$inputOp, "ArrayRef<int32_t>":$counts,
"Block *":$defaultDest, "BlockRange":$dests), [{
build($_builder, $_state, operation, $_builder.getI32VectorAttr(counts),
build($_builder, $_state, inputOp, $_builder.getI32VectorAttr(counts),
defaultDest, dests);
}]>];
let hasVerifier = 1;
Expand All @@ -1181,18 +1175,18 @@ def PDLInterp_SwitchOperationNameOp
```
}];

let arguments = (ins PDL_Operation:$operation,
let arguments = (ins PDL_Operation:$inputOp,
StrArrayAttr:$caseValues);
let assemblyFormat = [{
`of` $operation `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
`of` $inputOp `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
}];

let builders = [
OpBuilder<(ins "Value":$operation, "ArrayRef<OperationName>":$names,
OpBuilder<(ins "Value":$inputOp, "ArrayRef<OperationName>":$names,
"Block *":$defaultDest, "BlockRange":$dests), [{
auto stringNames = llvm::to_vector<8>(llvm::map_range(names,
[](OperationName name) { return name.getStringRef(); }));
build($_builder, $_state, operation, $_builder.getStrArrayAttr(stringNames),
build($_builder, $_state, inputOp, $_builder.getStrArrayAttr(stringNames),
defaultDest, dests);
}]>,
];
Expand All @@ -1219,15 +1213,15 @@ def PDLInterp_SwitchResultCountOp
```
}];

let arguments = (ins PDL_Operation:$operation, I32ElementsAttr:$caseValues);
let arguments = (ins PDL_Operation:$inputOp, I32ElementsAttr:$caseValues);
let assemblyFormat = [{
`of` $operation `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
`of` $inputOp `to` $caseValues `(` $cases `)` attr-dict `->` $defaultDest
}];

let builders = [
OpBuilder<(ins "Value":$operation, "ArrayRef<int32_t>":$counts,
OpBuilder<(ins "Value":$inputOp, "ArrayRef<int32_t>":$counts,
"Block *":$defaultDest, "BlockRange":$dests), [{
build($_builder, $_state, operation, $_builder.getI32VectorAttr(counts),
build($_builder, $_state, inputOp, $_builder.getI32VectorAttr(counts),
defaultDest, dests);
}]>];
let hasVerifier = 1;
Expand Down Expand Up @@ -1266,7 +1260,7 @@ def PDLInterp_SwitchTypeOp : PDLInterp_SwitchOp<"switch_type", [NoSideEffect]> {
];

let extraClassDeclaration = [{
auto getCaseTypes() { return caseValues().getAsValueRange<TypeAttr>(); }
auto getCaseTypes() { return getCaseValues().getAsValueRange<TypeAttr>(); }
}];
let hasVerifier = 1;
}
Expand Down Expand Up @@ -1308,7 +1302,7 @@ def PDLInterp_SwitchTypesOp : PDLInterp_SwitchOp<"switch_types",
];

let extraClassDeclaration = [{
auto getCaseTypes() { return caseValues().getAsRange<ArrayAttr>(); }
auto getCaseTypes() { return getCaseValues().getAsRange<ArrayAttr>(); }
}];
let hasVerifier = 1;
}
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ Value PatternLowering::getValueAt(Block *&currentBlock, Position *pos) {
value = foreach.getLoopVariable();

// Create the continuation block.
Block *continueBlock = builder.createBlock(&foreach.region());
Block *continueBlock = builder.createBlock(&foreach.getRegion());
builder.create<pdl_interp::ContinueOp>(loc);
failureBlockStack.push_back(continueBlock);

currentBlock = &foreach.region().front();
currentBlock = &foreach.getRegion().front();
break;
}
case Predicates::OperandPos: {
Expand Down Expand Up @@ -679,7 +679,7 @@ void PatternLowering::generateRewriter(
auto interpOp = builder.create<pdl_interp::ApplyRewriteOp>(
rewriteOp.getLoc(), rewriteOp.getResultTypes(), rewriteOp.nameAttr(),
arguments, rewriteOp.constParamsAttr());
for (auto it : llvm::zip(rewriteOp.results(), interpOp.results()))
for (auto it : llvm::zip(rewriteOp.results(), interpOp.getResults()))
rewriteValues[std::get<0>(it)] = std::get<1>(it);
}

Expand Down
14 changes: 7 additions & 7 deletions mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ template <typename OpT>
static LogicalResult verifySwitchOp(OpT op) {
// Verify that the number of case destinations matches the number of case
// values.
size_t numDests = op.cases().size();
size_t numValues = op.caseValues().size();
size_t numDests = op.getCases().size();
size_t numValues = op.getCaseValues().size();
if (numDests != numValues) {
return op.emitOpError(
"expected number of cases to match the number of case "
Expand Down Expand Up @@ -140,23 +140,23 @@ ParseResult ForEachOp::parse(OpAsmParser &parser, OperationState &result) {

void ForEachOp::print(OpAsmPrinter &p) {
BlockArgument arg = getLoopVariable();
p << ' ' << arg << " : " << arg.getType() << " in " << values() << ' ';
p.printRegion(region(), /*printEntryBlockArgs=*/false);
p << ' ' << arg << " : " << arg.getType() << " in " << getValues() << ' ';
p.printRegion(getRegion(), /*printEntryBlockArgs=*/false);
p.printOptionalAttrDict((*this)->getAttrs());
p << " -> ";
p.printSuccessor(successor());
p.printSuccessor(getSuccessor());
}

LogicalResult ForEachOp::verify() {
// Verify that the operation has exactly one argument.
if (region().getNumArguments() != 1)
if (getRegion().getNumArguments() != 1)
return emitOpError("requires exactly one argument");

// Verify that the loop variable and the operand (value range)
// have compatible types.
BlockArgument arg = getLoopVariable();
Type rangeType = pdl::RangeType::get(arg.getType());
if (rangeType != values().getType())
if (rangeType != getValues().getType())
return emitOpError("operand must be a range of loop variable type");

return success();
Expand Down
156 changes: 79 additions & 77 deletions mlir/lib/Rewrite/ByteCode.cpp

Large diffs are not rendered by default.