diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h --- a/mlir/include/mlir/TableGen/Operator.h +++ b/mlir/include/mlir/TableGen/Operator.h @@ -95,7 +95,9 @@ using var_decorator_range = llvm::iterator_range; using value_iterator = NamedTypeConstraint *; + using const_value_iterator = const NamedTypeConstraint *; using value_range = llvm::iterator_range; + using const_value_range = llvm::iterator_range; // Returns true if this op has variable length operands or results. bool isVariadic() const; @@ -104,9 +106,9 @@ bool skipDefaultBuilders() const; // Op result iterators. - value_iterator result_begin(); - value_iterator result_end(); - value_range getResults(); + const_value_iterator result_begin() const; + const_value_iterator result_end() const; + const_value_range getResults() const; // Returns the number of results this op produces. int getNumResults() const; @@ -143,9 +145,9 @@ } // Op operand iterators. - value_iterator operand_begin(); - value_iterator operand_end(); - value_range getOperands(); + const_value_iterator operand_begin() const; + const_value_iterator operand_end() const; + const_value_range getOperands() const; int getNumOperands() const { return operands.size(); } NamedTypeConstraint &getOperand(int index) { return operands[index]; } diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -141,11 +141,15 @@ return def.getValueAsBit("skipDefaultBuilders"); } -auto Operator::result_begin() -> value_iterator { return results.begin(); } +auto Operator::result_begin() const -> const_value_iterator { + return results.begin(); +} -auto Operator::result_end() -> value_iterator { return results.end(); } +auto Operator::result_end() const -> const_value_iterator { + return results.end(); +} -auto Operator::getResults() -> value_range { +auto Operator::getResults() const -> const_value_range { return {result_begin(), result_end()}; } @@ -286,9 +290,13 @@ return {attribute_begin(), attribute_end()}; } -auto Operator::operand_begin() -> value_iterator { return operands.begin(); } -auto Operator::operand_end() -> value_iterator { return operands.end(); } -auto Operator::getOperands() -> value_range { +auto Operator::operand_begin() const -> const_value_iterator { + return operands.begin(); +} +auto Operator::operand_end() const -> const_value_iterator { + return operands.end(); +} +auto Operator::getOperands() const -> const_value_range { return {operand_begin(), operand_end()}; } diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -52,15 +52,15 @@ if (selectedDialect.empty()) { // If a dialect was not specified, ensure that all found defs belong to the // same dialect. - if (!llvm::is_splat( - llvm::map_range(defs, [](auto def) { return def.getDialect(); }))) { + if (!llvm::is_splat(llvm::map_range( + defs, [](const auto &def) { return def.getDialect(); }))) { llvm::PrintFatalError("defs belonging to more than one dialect. Must " "select one via '--(attr|type)defs-dialect'"); } resultDefs.assign(defs.begin(), defs.end()); } else { // Otherwise, generate the defs that belong to the selected dialect. - auto dialectDefs = llvm::make_filter_range(defs, [&](auto def) { + auto dialectDefs = llvm::make_filter_range(defs, [&](const auto &def) { return def.getDialect().getName().equals(selectedDialect); }); resultDefs.assign(dialectDefs.begin(), dialectDefs.end()); diff --git a/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp b/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp --- a/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp +++ b/mlir/tools/mlir-tblgen/CodeGenHelpers.cpp @@ -299,7 +299,7 @@ void StaticVerifierFunctionEmitter::collectOpConstraints( ArrayRef opDefs) { - const auto collectTypeConstraints = [&](Operator::value_range values) { + const auto collectTypeConstraints = [&](Operator::const_value_range values) { for (const NamedTypeConstraint &value : values) if (value.hasPredicate()) collectConstraint(typeConstraints, "type", value.constraint); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -396,7 +396,8 @@ // Generates verify statements for operands and results in the operation. // The generated code will be attached to `body`. - void genOperandResultVerifier(MethodBody &body, Operator::value_range values, + void genOperandResultVerifier(MethodBody &body, + Operator::const_value_range values, StringRef valueKind); // Generates verify statements for regions in the operation. @@ -2246,7 +2247,7 @@ } void OpEmitter::genOperandResultVerifier(MethodBody &body, - Operator::value_range values, + Operator::const_value_range values, StringRef valueKind) { // Check that an optional value is at most 1 element. // diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp --- a/mlir/tools/mlir-tblgen/OpDocGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp @@ -143,7 +143,7 @@ } } -static void emitOpDoc(Operator op, raw_ostream &os) { +static void emitOpDoc(const Operator &op, raw_ostream &os) { os << llvm::formatv("### `{0}` ({1})\n", op.getOperationName(), op.getQualCppClassName()); diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -84,12 +84,12 @@ InterfaceGenerator(std::vector &&defs, raw_ostream &os) : defs(std::move(defs)), os(os) {} - void emitConceptDecl(Interface &interface); - void emitModelDecl(Interface &interface); - void emitModelMethodsDef(Interface &interface); - void emitTraitDecl(Interface &interface, StringRef interfaceName, + void emitConceptDecl(const Interface &interface); + void emitModelDecl(const Interface &interface); + void emitModelMethodsDef(const Interface &interface); + void emitTraitDecl(const Interface &interface, StringRef interfaceName, StringRef interfaceTraitsName); - void emitInterfaceDecl(Interface interface); + void emitInterfaceDecl(const Interface &interface); /// The set of interface records to emit. std::vector defs; @@ -200,7 +200,7 @@ // GEN: Interface declarations //===----------------------------------------------------------------------===// -void InterfaceGenerator::emitConceptDecl(Interface &interface) { +void InterfaceGenerator::emitConceptDecl(const Interface &interface) { os << " struct Concept {\n"; // Insert each of the pure virtual concept methods. @@ -220,7 +220,7 @@ os << " };\n"; } -void InterfaceGenerator::emitModelDecl(Interface &interface) { +void InterfaceGenerator::emitModelDecl(const Interface &interface) { // Emit the basic model and the fallback model. for (const char *modelClass : {"Model", "FallbackModel"}) { os << " template\n"; @@ -280,7 +280,7 @@ os << " };\n"; } -void InterfaceGenerator::emitModelMethodsDef(Interface &interface) { +void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { for (auto &method : interface.getMethods()) { os << "template\n"; emitCPPType(method.getReturnType(), os); @@ -378,7 +378,7 @@ } } -void InterfaceGenerator::emitTraitDecl(Interface &interface, +void InterfaceGenerator::emitTraitDecl(const Interface &interface, StringRef interfaceName, StringRef interfaceTraitsName) { os << llvm::formatv(" template \n" @@ -425,7 +425,7 @@ os << " };\n"; } -void InterfaceGenerator::emitInterfaceDecl(Interface interface) { +void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) { llvm::SmallVector namespaces; llvm::SplitString(interface.getCppNamespace(), namespaces, "::"); for (StringRef ns : namespaces)