Make namespace handling uniform across dialect backends.

Now backends spell out which namespace they want to be in, instead of relying on
clients #including them inside already-opened namespaces. This also means that
cppNamespaces should be fully qualified, and there's no implicit "::mlir::"
prepended to them anymore.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D86811
This commit is contained in:
Federico Lebrón 2020-09-14 20:01:07 +00:00 committed by Mehdi Amini
parent 9d01612db4
commit 7d1ed69c8a
79 changed files with 330 additions and 325 deletions

View File

@ -41,9 +41,10 @@ mlir::ParseResult parseSelector(mlir::OpAsmParser &parser,
mlir::OpAsmParser::OperandType &selector, mlir::OpAsmParser::OperandType &selector,
mlir::Type &type); mlir::Type &type);
} // namespace fir
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "flang/Optimizer/Dialect/FIROps.h.inc" #include "flang/Optimizer/Dialect/FIROps.h.inc"
} // namespace fir
#endif // OPTIMIZER_DIALECT_FIROPS_H #endif // OPTIMIZER_DIALECT_FIROPS_H

View File

@ -21,6 +21,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def fir_Dialect : Dialect { def fir_Dialect : Dialect {
let name = "fir"; let name = "fir";
let cppNamespace = "::fir";
} }
// Types and predicates // Types and predicates

View File

@ -1552,11 +1552,8 @@ fir::GlobalOp fir::createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
return modBuilder.create<fir::GlobalOp>(loc, name, type, attrs); return modBuilder.create<fir::GlobalOp>(loc, name, type, attrs);
} }
namespace fir {
// Tablegen operators // Tablegen operators
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "flang/Optimizer/Dialect/FIROps.cpp.inc" #include "flang/Optimizer/Dialect/FIROps.cpp.inc"
} // namespace fir

View File

@ -34,12 +34,12 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
/// Include the auto-generated header file containing the declarations of the /// Include the auto-generated header file containing the declarations of the
/// toy operations. /// toy operations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
} // end namespace toy
} // end namespace mlir
#endif // MLIR_TUTORIAL_TOY_DIALECT_H_ #endif // MLIR_TUTORIAL_TOY_DIALECT_H_

View File

@ -20,7 +20,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -34,12 +34,12 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
/// Include the auto-generated header file containing the declarations of the /// Include the auto-generated header file containing the declarations of the
/// toy operations. /// toy operations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
} // end namespace toy
} // end namespace mlir
#endif // MLIR_TUTORIAL_TOY_DIALECT_H_ #endif // MLIR_TUTORIAL_TOY_DIALECT_H_

View File

@ -19,7 +19,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -36,12 +36,12 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
/// Include the auto-generated header file containing the declarations of the /// Include the auto-generated header file containing the declarations of the
/// toy operations. /// toy operations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
} // end namespace toy
} // end namespace mlir
#endif // MLIR_TUTORIAL_TOY_DIALECT_H_ #endif // MLIR_TUTORIAL_TOY_DIALECT_H_

View File

@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -36,12 +36,12 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
/// Include the auto-generated header file containing the declarations of the /// Include the auto-generated header file containing the declarations of the
/// toy operations. /// toy operations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
} // end namespace toy
} // end namespace mlir
#endif // MLIR_TUTORIAL_TOY_DIALECT_H_ #endif // MLIR_TUTORIAL_TOY_DIALECT_H_

View File

@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -36,12 +36,12 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
/// Include the auto-generated header file containing the declarations of the /// Include the auto-generated header file containing the declarations of the
/// toy operations. /// toy operations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
} // end namespace toy
} // end namespace mlir
#endif // MLIR_TUTORIAL_TOY_DIALECT_H_ #endif // MLIR_TUTORIAL_TOY_DIALECT_H_

View File

@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -50,6 +50,9 @@ public:
static llvm::StringRef getDialectNamespace() { return "toy"; } static llvm::StringRef getDialectNamespace() { return "toy"; }
}; };
} // end namespace toy
} // end namespace mlir
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Toy Operations // Toy Operations
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -59,6 +62,9 @@ public:
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "toy/Ops.h.inc" #include "toy/Ops.h.inc"
namespace mlir {
namespace toy {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Toy Types // Toy Types
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// can define our operations. // can define our operations.
def Toy_Dialect : Dialect { def Toy_Dialect : Dialect {
let name = "toy"; let name = "toy";
let cppNamespace = "toy"; let cppNamespace = "::mlir::toy";
} }
// Base class for toy dialect operations. This operation inherits from the base // Base class for toy dialect operations. This operation inherits from the base

View File

@ -21,7 +21,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def AVX512_Dialect : Dialect { def AVX512_Dialect : Dialect {
let name = "avx512"; let name = "avx512";
let cppNamespace = "avx512"; let cppNamespace = "::mlir::avx512";
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -17,15 +17,9 @@
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
namespace mlir { #include "mlir/Dialect/AVX512/AVX512Dialect.h.inc"
namespace avx512 {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/AVX512/AVX512.h.inc" #include "mlir/Dialect/AVX512/AVX512.h.inc"
#include "mlir/Dialect/AVX512/AVX512Dialect.h.inc"
} // namespace avx512
} // namespace mlir
#endif // MLIR_DIALECT_AVX512_AVX512DIALECT_H_ #endif // MLIR_DIALECT_AVX512_AVX512DIALECT_H_

View File

@ -21,6 +21,7 @@ include "mlir/IR/OpBase.td"
def GPU_Dialect : Dialect { def GPU_Dialect : Dialect {
let name = "gpu"; let name = "gpu";
let cppNamespace = "::mlir::gpu";
let hasOperationAttrVerify = 1; let hasOperationAttrVerify = 1;
let extraClassDeclaration = [{ let extraClassDeclaration = [{

View File

@ -34,12 +34,13 @@ struct KernelDim3 {
Value z; Value z;
}; };
} // end namespace gpu
} // end namespace mlir
#include "mlir/Dialect/GPU/GPUOpsDialect.h.inc" #include "mlir/Dialect/GPU/GPUOpsDialect.h.inc"
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/GPU/GPUOps.h.inc" #include "mlir/Dialect/GPU/GPUOps.h.inc"
} // end namespace gpu
} // end namespace mlir
#endif // MLIR_DIALECT_GPU_GPUDIALECT_H #endif // MLIR_DIALECT_GPU_GPUDIALECT_H

View File

@ -27,8 +27,11 @@ struct LogicalResult;
class Operation; class Operation;
class Region; class Region;
} // namespace mlir
#include "mlir/Dialect/GPU/ParallelLoopMapperAttr.h.inc" #include "mlir/Dialect/GPU/ParallelLoopMapperAttr.h.inc"
namespace mlir {
namespace scf { namespace scf {
class ParallelOp; class ParallelOp;
} }

View File

@ -21,7 +21,7 @@ include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
def LLVMAVX512_Dialect : Dialect { def LLVMAVX512_Dialect : Dialect {
let name = "llvm_avx512"; let name = "llvm_avx512";
let cppNamespace = "LLVM"; let cppNamespace = "::mlir::LLVM";
} }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -16,15 +16,9 @@
#include "mlir/IR/Dialect.h" #include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
namespace mlir {
namespace LLVM {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMAVX512.h.inc" #include "mlir/Dialect/LLVMIR/LLVMAVX512.h.inc"
#include "mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h.inc" #include "mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h.inc"
} // namespace LLVM
} // namespace mlir
#endif // MLIR_DIALECT_LLVMIR_LLVMAVX512DIALECT_H_ #endif // MLIR_DIALECT_LLVMIR_LLVMAVX512DIALECT_H_

View File

@ -49,18 +49,23 @@ struct LLVMTypeStorage;
struct LLVMDialectImpl; struct LLVMDialectImpl;
} // namespace detail } // namespace detail
} // namespace LLVM
} // namespace mlir
///// Ops ///// ///// Ops /////
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMOps.h.inc" #include "mlir/Dialect/LLVMIR/LLVMOps.h.inc"
#include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc" #include "mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc"
namespace mlir {
namespace LLVM {
/// Create an LLVM global containing the string "value" at the module containing /// Create an LLVM global containing the string "value" at the module containing
/// surrounding the insertion point of builder. Obtain the address of that /// surrounding the insertion point of builder. Obtain the address of that
/// global and use it to compute the address of the first character in the /// global and use it to compute the address of the first character in the
/// string (operations inserted at the builder insertion point). /// string (operations inserted at the builder insertion point).
Value createGlobalString(Location loc, OpBuilder &builder, StringRef name, Value createGlobalString(Location loc, OpBuilder &builder, StringRef name,
StringRef value, LLVM::Linkage linkage); StringRef value, Linkage linkage);
/// LLVM requires some operations to be inside of a Module operation. This /// LLVM requires some operations to be inside of a Module operation. This
/// function confirms that the Operation has the desired properties. /// function confirms that the Operation has the desired properties.

View File

@ -23,7 +23,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def LLVM_Dialect : Dialect { def LLVM_Dialect : Dialect {
let name = "llvm"; let name = "llvm";
let cppNamespace = "LLVM"; let cppNamespace = "::mlir::LLVM";
/// FIXME: at the moment this is a dependency of the translation to LLVM IR, /// FIXME: at the moment this is a dependency of the translation to LLVM IR,
/// not really one of this dialect per-se. /// not really one of this dialect per-se.

View File

@ -59,7 +59,7 @@ def LLVM_VoidResultTypeOpBuilder : OpBuilder<
"OpBuilder &builder, OperationState &result, Type resultType, " "OpBuilder &builder, OperationState &result, Type resultType, "
"ValueRange operands, ArrayRef<NamedAttribute> attributes = {}", "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
[{ [{
auto llvmType = resultType.dyn_cast<LLVM::LLVMType>(); (void)llvmType; auto llvmType = resultType.dyn_cast<LLVMType>(); (void)llvmType;
assert(llvmType && "result must be an LLVM type"); assert(llvmType && "result must be an LLVM type");
assert(llvmType.isVoidTy() && assert(llvmType.isVoidTy() &&
"for zero-result operands, only 'void' is accepted as result type"); "for zero-result operands, only 'void' is accepted as result type");
@ -301,7 +301,7 @@ def LLVM_LoadOp :
"unsigned alignment = 0, bool isVolatile = false, " "unsigned alignment = 0, bool isVolatile = false, "
"bool isNonTemporal = false", "bool isNonTemporal = false",
[{ [{
auto type = addr.getType().cast<LLVM::LLVMType>().getPointerElementTy(); auto type = addr.getType().cast<LLVMType>().getPointerElementTy();
build(b, result, type, addr, alignment, isVolatile, isNonTemporal); build(b, result, type, addr, alignment, isVolatile, isNonTemporal);
}]>, }]>,
OpBuilder< OpBuilder<
@ -494,8 +494,8 @@ def LLVM_ShuffleVectorOp
"OpBuilder &b, OperationState &result, Value v1, Value v2, " "OpBuilder &b, OperationState &result, Value v1, Value v2, "
"ArrayAttr mask, ArrayRef<NamedAttribute> attrs = {}">]; "ArrayAttr mask, ArrayRef<NamedAttribute> attrs = {}">];
let verifier = [{ let verifier = [{
auto wrappedVectorType1 = v1().getType().cast<LLVM::LLVMType>(); auto wrappedVectorType1 = v1().getType().cast<LLVMType>();
auto wrappedVectorType2 = v2().getType().cast<LLVM::LLVMType>(); auto wrappedVectorType2 = v2().getType().cast<LLVMType>();
if (!wrappedVectorType2.isVectorTy()) if (!wrappedVectorType2.isVectorTy())
return emitOpError("expected LLVM IR Dialect vector type for operand #2"); return emitOpError("expected LLVM IR Dialect vector type for operand #2");
if (wrappedVectorType1.getVectorElementType() != if (wrappedVectorType1.getVectorElementType() !=
@ -770,7 +770,7 @@ def LLVM_LLVMFuncOp
let builders = [ let builders = [
OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, " OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, "
"LLVMType type, LLVM::Linkage linkage = LLVM::Linkage::External, " "LLVMType type, Linkage linkage = Linkage::External, "
"ArrayRef<NamedAttribute> attrs = {}, " "ArrayRef<NamedAttribute> attrs = {}, "
"ArrayRef<MutableDictionaryAttr> argAttrs = {}"> "ArrayRef<MutableDictionaryAttr> argAttrs = {}">
]; ];

View File

@ -19,16 +19,10 @@
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
namespace mlir {
namespace NVVM {
///// Ops ///// ///// Ops /////
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/NVVMOps.h.inc" #include "mlir/Dialect/LLVMIR/NVVMOps.h.inc"
#include "mlir/Dialect/LLVMIR/NVVMOpsDialect.h.inc" #include "mlir/Dialect/LLVMIR/NVVMOpsDialect.h.inc"
} // namespace NVVM
} // namespace mlir
#endif /* MLIR_DIALECT_LLVMIR_NVVMDIALECT_H_ */ #endif /* MLIR_DIALECT_LLVMIR_NVVMDIALECT_H_ */

View File

@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def NVVM_Dialect : Dialect { def NVVM_Dialect : Dialect {
let name = "nvvm"; let name = "nvvm";
let cppNamespace = "NVVM"; let cppNamespace = "::mlir::NVVM";
let dependentDialects = ["LLVM::LLVMDialect"]; let dependentDialects = ["LLVM::LLVMDialect"];
} }

View File

@ -27,16 +27,10 @@
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
namespace mlir {
namespace ROCDL {
///// Ops ///// ///// Ops /////
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/ROCDLOps.h.inc" #include "mlir/Dialect/LLVMIR/ROCDLOps.h.inc"
#include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.h.inc" #include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.h.inc"
} // namespace ROCDL
} // namespace mlir
#endif /* MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ */ #endif /* MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ */

View File

@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def ROCDL_Dialect : Dialect { def ROCDL_Dialect : Dialect {
let name = "rocdl"; let name = "rocdl";
let cppNamespace = "ROCDL"; let cppNamespace = "::mlir::ROCDL";
let dependentDialects = ["LLVM::LLVMDialect"]; let dependentDialects = ["LLVM::LLVMDialect"];
} }

View File

@ -31,6 +31,7 @@ def Linalg_Dialect : Dialect {
are also available and should be read first before going in the details of are also available and should be read first before going in the details of
the op semantics. the op semantics.
}]; }];
let cppNamespace = "::mlir::linalg";
} }
// Whether a type is a RangeType. // Whether a type is a RangeType.

View File

@ -85,6 +85,9 @@ AffineMap extractOrIdentityMap(Optional<AffineMap> maybeMap, unsigned rank,
SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a, SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
ArrayRef<AffineExpr> b); ArrayRef<AffineExpr> b);
} // namespace linalg
} // namespace mlir
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.h.inc" #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.h.inc"
#define GET_OP_CLASSES #define GET_OP_CLASSES
@ -93,7 +96,5 @@ SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc" #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc"
} // namespace linalg
} // namespace mlir
#endif // MLIR_DIALECT_LINALG_LINALGOPS_H_ #endif // MLIR_DIALECT_LINALG_LINALGOPS_H_

View File

@ -18,6 +18,7 @@ include "mlir/Dialect/Linalg/IR/LinalgBase.td"
// The linalg 'LinalgStructuredInterface' provides access to the 'LinalgOp' // The linalg 'LinalgStructuredInterface' provides access to the 'LinalgOp'
// interface. // interface.
def LinalgStructuredInterface : OpInterface<"LinalgOp"> { def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
let cppNamespace = "::mlir::linalg";
let methods = [ let methods = [
//===------------------------------------------------------------------===// //===------------------------------------------------------------------===//
// Loop types handling. // Loop types handling.

View File

@ -12,11 +12,12 @@
#include "mlir/IR/Dialect.h" #include "mlir/IR/Dialect.h"
#include "mlir/IR/Types.h" #include "mlir/IR/Types.h"
#include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc"
namespace mlir { namespace mlir {
class MLIRContext; class MLIRContext;
namespace linalg { namespace linalg {
#include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc"
/// A RangeType represents a minimal range abstraction (min, max, step). /// A RangeType represents a minimal range abstraction (min, max, step).
/// It is constructed by calling the linalg.range op with three values index of /// It is constructed by calling the linalg.range op with three values index of

View File

@ -16,15 +16,14 @@
#include "mlir/IR/Dialect.h" #include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc" #include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
namespace mlir {
namespace acc {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc" #include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc" namespace mlir {
namespace acc {
/// Enumeration used to encode the execution mapping on a loop construct. /// Enumeration used to encode the execution mapping on a loop construct.
/// They refer directly to the OpenACC 3.0 standard: /// They refer directly to the OpenACC 3.0 standard:

View File

@ -24,7 +24,7 @@ def OpenACC_Dialect : Dialect {
This dialect models the construct from the OpenACC 3.0 directive language. This dialect models the construct from the OpenACC 3.0 directive language.
}]; }];
let cppNamespace = "acc"; let cppNamespace = "::mlir::acc";
} }
// Base class for OpenACC dialect ops. // Base class for OpenACC dialect ops.

View File

@ -16,16 +16,10 @@
#include "mlir/IR/Dialect.h" #include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h" #include "mlir/IR/OpDefinition.h"
#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc"
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc" #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc"
namespace mlir {
namespace omp {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc" #include "mlir/Dialect/OpenMP/OpenMPOps.h.inc"
#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc"
} // namespace omp
} // namespace mlir
#endif // MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ #endif // MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_

View File

@ -19,7 +19,7 @@ include "mlir/Dialect/OpenMP/OmpCommon.td"
def OpenMP_Dialect : Dialect { def OpenMP_Dialect : Dialect {
let name = "omp"; let name = "omp";
let cppNamespace = "omp"; let cppNamespace = "::mlir::omp";
} }
class OpenMP_Op<string mnemonic, list<OpTrait> traits = []> : class OpenMP_Op<string mnemonic, list<OpTrait> traits = []> :

View File

@ -19,8 +19,6 @@
#include "mlir/IR/SymbolTable.h" #include "mlir/IR/SymbolTable.h"
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
namespace mlir {
namespace pdl {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PDL Dialect // PDL Dialect
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -34,7 +32,5 @@ namespace pdl {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/PDL/IR/PDLOps.h.inc" #include "mlir/Dialect/PDL/IR/PDLOps.h.inc"
} // end namespace pdl
} // end namespace mlir
#endif // MLIR_DIALECT_PDL_IR_PDL_H_ #endif // MLIR_DIALECT_PDL_IR_PDL_H_

View File

@ -63,7 +63,7 @@ def PDL_Dialect : Dialect {
}]; }];
let name = "pdl"; let name = "pdl";
let cppNamespace = "mlir::pdl"; let cppNamespace = "::mlir::pdl";
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -18,8 +18,6 @@
#include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
namespace mlir {
namespace pdl_interp {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PDLInterp Dialect // PDLInterp Dialect
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -33,7 +31,4 @@ namespace pdl_interp {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.h.inc" #include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.h.inc"
} // end namespace pdl_interp
} // end namespace mlir
#endif // MLIR_DIALECT_PDLINTERP_IR_PDLINTERP_H_ #endif // MLIR_DIALECT_PDLINTERP_IR_PDLINTERP_H_

View File

@ -34,7 +34,7 @@ def PDLInterp_Dialect : Dialect {
}]; }];
let name = "pdl_interp"; let name = "pdl_interp";
let cppNamespace = "mlir::pdl_interp"; let cppNamespace = "::mlir::pdl_interp";
let dependentDialects = ["pdl::PDLDialect"]; let dependentDialects = ["pdl::PDLDialect"];
} }

View File

@ -18,15 +18,9 @@
#include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/SideEffectInterfaces.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
namespace mlir {
namespace quant {
#include "mlir/Dialect/Quant/QuantOpsDialect.h.inc" #include "mlir/Dialect/Quant/QuantOpsDialect.h.inc"
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Quant/QuantOps.h.inc" #include "mlir/Dialect/Quant/QuantOps.h.inc"
} // namespace quant
} // namespace mlir
#endif // MLIR_DIALECT_QUANT_QUANTOPS_H_ #endif // MLIR_DIALECT_QUANT_QUANTOPS_H_

View File

@ -17,6 +17,7 @@ include "mlir/IR/OpBase.td"
def Quantization_Dialect : Dialect { def Quantization_Dialect : Dialect {
let name = "quant"; let name = "quant";
let cppNamespace = "::mlir::quant";
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -23,14 +23,18 @@
namespace mlir { namespace mlir {
namespace scf { namespace scf {
void buildTerminatedBody(OpBuilder &builder, Location loc); void buildTerminatedBody(OpBuilder &builder, Location loc);
} // namespace scf
} // namespace mlir
#include "mlir/Dialect/SCF/SCFOpsDialect.h.inc" #include "mlir/Dialect/SCF/SCFOpsDialect.h.inc"
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/SCF/SCFOps.h.inc" #include "mlir/Dialect/SCF/SCFOps.h.inc"
namespace mlir {
namespace scf {
// Insert `loop.yield` at the end of the only region's only block if it // Insert `loop.yield` at the end of the only region's only block if it
// does not have a terminator already. If a new `loop.yield` is inserted, // does not have a terminator already. If a new `loop.yield` is inserted,
// the location is specified by `loc`. If the region is empty, insert a new // the location is specified by `loc`. If the region is empty, insert a new

View File

@ -19,7 +19,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def SCF_Dialect : Dialect { def SCF_Dialect : Dialect {
let name = "scf"; let name = "scf";
let cppNamespace = "scf"; let cppNamespace = "::mlir::scf";
} }
// Base class for SCF dialect ops. // Base class for SCF dialect ops.

View File

@ -17,10 +17,10 @@
#include "mlir/IR/Attributes.h" #include "mlir/IR/Attributes.h"
#include "mlir/Support/LLVM.h" #include "mlir/Support/LLVM.h"
namespace mlir {
// Pull in SPIR-V attribute definitions for target and ABI. // Pull in SPIR-V attribute definitions for target and ABI.
#include "mlir/Dialect/SPIRV/TargetAndABI.h.inc" #include "mlir/Dialect/SPIRV/TargetAndABI.h.inc"
namespace mlir {
namespace spirv { namespace spirv {
enum class Capability : uint32_t; enum class Capability : uint32_t;
enum class Extension; enum class Extension;

View File

@ -45,7 +45,7 @@ def SPIRV_Dialect : Dialect {
high-level designs and implementation structures of the SPIR-V dialect. high-level designs and implementation structures of the SPIR-V dialect.
}]; }];
let cppNamespace = "spirv"; let cppNamespace = "::mlir::spirv";
let hasConstantMaterializer = 1; let hasConstantMaterializer = 1;
let hasOperationAttrVerify = 1; let hasOperationAttrVerify = 1;
let hasRegionArgAttrVerify = 1; let hasRegionArgAttrVerify = 1;
@ -226,21 +226,24 @@ class Capability<list<I32EnumAttrCase> capabilities> : Availability {
let instance = "ref"; let instance = "ref";
} }
class SPIRVOpInterface<string name> : OpInterface<name> {
let cppNamespace = "::mlir::spirv";
}
// TODO: the following interfaces definitions are duplicating with the above. // TODO: the following interfaces definitions are duplicating with the above.
// Remove them once we are able to support dialect-specific contents in ODS. // Remove them once we are able to support dialect-specific contents in ODS.
def QueryMinVersionInterface : OpInterface<"QueryMinVersionInterface"> { def QueryMinVersionInterface : SPIRVOpInterface<"QueryMinVersionInterface"> {
let methods = [InterfaceMethod<"", "::mlir::spirv::Version", "getMinVersion">]; let methods = [InterfaceMethod<"", "::mlir::spirv::Version", "getMinVersion">];
} }
def QueryMaxVersionInterface : OpInterface<"QueryMaxVersionInterface"> { def QueryMaxVersionInterface : SPIRVOpInterface<"QueryMaxVersionInterface"> {
let methods = [InterfaceMethod<"", "::mlir::spirv::Version", "getMaxVersion">]; let methods = [InterfaceMethod<"", "::mlir::spirv::Version", "getMaxVersion">];
} }
def QueryExtensionInterface : OpInterface<"QueryExtensionInterface"> { def QueryExtensionInterface : SPIRVOpInterface<"QueryExtensionInterface"> {
let methods = [InterfaceMethod< let methods = [InterfaceMethod<
"", "",
"::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Extension>, 1>", "::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Extension>, 1>",
"getExtensions">]; "getExtensions">];
} }
def QueryCapabilityInterface : OpInterface<"QueryCapabilityInterface"> { def QueryCapabilityInterface : SPIRVOpInterface<"QueryCapabilityInterface"> {
let methods = [InterfaceMethod< let methods = [InterfaceMethod<
"", "",
"::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Capability>, 1>", "::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Capability>, 1>",

View File

@ -20,9 +20,9 @@ namespace spirv {
enum class Decoration : uint32_t; enum class Decoration : uint32_t;
#include "mlir/Dialect/SPIRV/SPIRVOpsDialect.h.inc"
} // end namespace spirv } // end namespace spirv
} // end namespace mlir } // end namespace mlir
#include "mlir/Dialect/SPIRV/SPIRVOpsDialect.h.inc"
#endif // MLIR_DIALECT_SPIRV_SPIRVDIALECT_H_ #endif // MLIR_DIALECT_SPIRV_SPIRVDIALECT_H_

View File

@ -28,11 +28,15 @@ class VerCapExtAttr;
// TableGen'erated operation interfaces for querying versions, extensions, and // TableGen'erated operation interfaces for querying versions, extensions, and
// capabilities. // capabilities.
#include "mlir/Dialect/SPIRV/SPIRVAvailability.h.inc" #include "mlir/Dialect/SPIRV/SPIRVAvailability.h.inc"
} // namespace spirv
} // namespace mlir
// TablenGen'erated operation declarations. // TablenGen'erated operation declarations.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/SPIRV/SPIRVOps.h.inc" #include "mlir/Dialect/SPIRV/SPIRVOps.h.inc"
namespace mlir {
namespace spirv {
// TableGen'erated helper functions. // TableGen'erated helper functions.
// //
// Get the name used in the Op to refer to an enum value of the given // Get the name used in the Op to refer to an enum value of the given

View File

@ -77,25 +77,25 @@ public:
/// The extension requirements for each type are following the /// The extension requirements for each type are following the
/// ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D)) /// ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D))
/// convention. /// convention.
using ExtensionArrayRefVector = SmallVectorImpl<ArrayRef<spirv::Extension>>; using ExtensionArrayRefVector = SmallVectorImpl<ArrayRef<Extension>>;
/// Appends to `extensions` the extensions needed for this type to appear in /// Appends to `extensions` the extensions needed for this type to appear in
/// the given `storage` class. This method does not guarantee the uniqueness /// the given `storage` class. This method does not guarantee the uniqueness
/// of extensions; the same extension may be appended multiple times. /// of extensions; the same extension may be appended multiple times.
void getExtensions(ExtensionArrayRefVector &extensions, void getExtensions(ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
/// The capability requirements for each type are following the /// The capability requirements for each type are following the
/// ((Capability::A OR Extension::B) AND (Capability::C OR Capability::D)) /// ((Capability::A OR Extension::B) AND (Capability::C OR Capability::D))
/// convention. /// convention.
using CapabilityArrayRefVector = SmallVectorImpl<ArrayRef<spirv::Capability>>; using CapabilityArrayRefVector = SmallVectorImpl<ArrayRef<Capability>>;
/// Appends to `capabilities` the capabilities needed for this type to appear /// Appends to `capabilities` the capabilities needed for this type to appear
/// in the given `storage` class. This method does not guarantee the /// in the given `storage` class. This method does not guarantee the
/// uniqueness of capabilities; the same capability may be appended multiple /// uniqueness of capabilities; the same capability may be appended multiple
/// times. /// times.
void getCapabilities(CapabilityArrayRefVector &capabilities, void getCapabilities(CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
/// Returns the size in bytes for each type. If no size can be calculated, /// Returns the size in bytes for each type. If no size can be calculated,
/// returns `llvm::None`. Note that if the type has explicit layout, it is /// returns `llvm::None`. Note that if the type has explicit layout, it is
@ -116,9 +116,9 @@ public:
static bool isValid(IntegerType); static bool isValid(IntegerType);
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
Optional<int64_t> getSizeInBytes(); Optional<int64_t> getSizeInBytes();
}; };
@ -144,9 +144,9 @@ public:
bool hasCompileTimeKnownNumElements() const; bool hasCompileTimeKnownNumElements() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
Optional<int64_t> getSizeInBytes(); Optional<int64_t> getSizeInBytes();
}; };
@ -172,9 +172,9 @@ public:
unsigned getArrayStride() const; unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
/// Returns the array size in bytes. Since array type may have an explicit /// Returns the array size in bytes. Since array type may have an explicit
/// stride declaration (in bytes), we also include it in the calculation. /// stride declaration (in bytes), we also include it in the calculation.
@ -215,9 +215,9 @@ public:
// TODO: Add support for Access qualifier // TODO: Add support for Access qualifier
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
// SPIR-V pointer type // SPIR-V pointer type
@ -233,9 +233,9 @@ public:
StorageClass getStorageClass() const; StorageClass getStorageClass() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
// SPIR-V run-time array type // SPIR-V run-time array type
@ -257,9 +257,9 @@ public:
unsigned getArrayStride() const; unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
// SPIR-V struct type // SPIR-V struct type
@ -335,21 +335,21 @@ public:
uint64_t getMemberOffset(unsigned) const; uint64_t getMemberOffset(unsigned) const;
// Returns in `memberDecorations` the spirv::Decorations (apart from // Returns in `memberDecorations` the Decorations (apart from Offset)
// Offset) associated with all members of the StructType. // associated with all members of the StructType.
void getMemberDecorations(SmallVectorImpl<StructType::MemberDecorationInfo> void getMemberDecorations(SmallVectorImpl<StructType::MemberDecorationInfo>
&memberDecorations) const; &memberDecorations) const;
// Returns in `decorationsInfo` all the spirv::Decorations (apart from // Returns in `decorationsInfo` all the Decorations (apart from Offset)
// Offset) associated with the `i`-th member of the StructType. // associated with the `i`-th member of the StructType.
void getMemberDecorations(unsigned i, void getMemberDecorations(unsigned i,
SmallVectorImpl<StructType::MemberDecorationInfo> SmallVectorImpl<StructType::MemberDecorationInfo>
&decorationsInfo) const; &decorationsInfo) const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
llvm::hash_code llvm::hash_code
@ -362,21 +362,21 @@ class CooperativeMatrixNVType
public: public:
using Base::Base; using Base::Base;
static CooperativeMatrixNVType get(Type elementType, spirv::Scope scope, static CooperativeMatrixNVType get(Type elementType, Scope scope,
unsigned rows, unsigned columns); unsigned rows, unsigned columns);
Type getElementType() const; Type getElementType() const;
/// Return the scope of the cooperative matrix. /// Return the scope of the cooperative matrix.
spirv::Scope getScope() const; Scope getScope() const;
/// return the number of rows of the matrix. /// return the number of rows of the matrix.
unsigned getRows() const; unsigned getRows() const;
/// return the number of columns of the matrix. /// return the number of columns of the matrix.
unsigned getColumns() const; unsigned getColumns() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
// SPIR-V matrix type // SPIR-V matrix type
@ -412,9 +412,9 @@ public:
Type getElementType() const; Type getElementType() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
Optional<spirv::StorageClass> storage = llvm::None); Optional<StorageClass> storage = llvm::None);
}; };
} // end namespace spirv } // end namespace spirv

View File

@ -67,12 +67,12 @@ public:
using Base::Base; using Base::Base;
}; };
} // namespace shape
} // namespace mlir
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Shape/IR/ShapeOps.h.inc" #include "mlir/Dialect/Shape/IR/ShapeOps.h.inc"
#include "mlir/Dialect/Shape/IR/ShapeOpsDialect.h.inc" #include "mlir/Dialect/Shape/IR/ShapeOpsDialect.h.inc"
} // namespace shape
} // namespace mlir
#endif // MLIR_SHAPE_IR_SHAPE_H #endif // MLIR_SHAPE_IR_SHAPE_H

View File

@ -36,7 +36,7 @@ def ShapeDialect : Dialect {
concatting etc. on how to combine them). concatting etc. on how to combine them).
}]; }];
let cppNamespace = "shape"; let cppNamespace = "::mlir::shape";
let hasConstantMaterializer = 1; let hasConstantMaterializer = 1;
} }

View File

@ -128,13 +128,11 @@ namespace impl {
AffineMap getTransferMinorIdentityMap(MemRefType memRefType, AffineMap getTransferMinorIdentityMap(MemRefType memRefType,
VectorType vectorType); VectorType vectorType);
} // namespace impl } // namespace impl
#define GET_OP_CLASSES
#include "mlir/Dialect/Vector/VectorOps.h.inc"
#include "mlir/Dialect/Vector/VectorOpsDialect.h.inc"
} // end namespace vector } // end namespace vector
} // end namespace mlir } // end namespace mlir
#define GET_OP_CLASSES
#include "mlir/Dialect/Vector/VectorOps.h.inc"
#include "mlir/Dialect/Vector/VectorOpsDialect.h.inc"
#endif // MLIR_DIALECT_VECTOR_VECTOROPS_H #endif // MLIR_DIALECT_VECTOR_VECTOROPS_H

View File

@ -19,7 +19,7 @@ include "mlir/Interfaces/VectorInterfaces.td"
def Vector_Dialect : Dialect { def Vector_Dialect : Dialect {
let name = "vector"; let name = "vector";
let cppNamespace = "vector"; let cppNamespace = "::mlir::vector";
let hasConstantMaterializer = 1; let hasConstantMaterializer = 1;
} }

View File

@ -1672,7 +1672,7 @@ class OpTrait;
// purpose to wrap around C++ symbol string with this class is to make // purpose to wrap around C++ symbol string with this class is to make
// traits specified for ops in TableGen less alien and more integrated. // traits specified for ops in TableGen less alien and more integrated.
class NativeOpTrait<string prop> : OpTrait { class NativeOpTrait<string prop> : OpTrait {
string trait = "OpTrait::" # prop; string trait = "::mlir::OpTrait::" # prop;
} }
// ParamNativeOpTrait corresponds to the template-parameterized traits in the // ParamNativeOpTrait corresponds to the template-parameterized traits in the
@ -1687,7 +1687,7 @@ class ParamNativeOpTrait<string prop, string params>
// affects op definition generator internals, like how op builders and // affects op definition generator internals, like how op builders and
// operand/attribute/result getters are generated. // operand/attribute/result getters are generated.
class GenInternalOpTrait<string prop> : OpTrait { class GenInternalOpTrait<string prop> : OpTrait {
string trait = "OpTrait::" # prop; string trait = "::mlir::OpTrait::" # prop;
} }
// PredOpTrait is an op trait implemented by way of a predicate on the op. // PredOpTrait is an op trait implemented by way of a predicate on the op.

View File

@ -242,6 +242,17 @@ public:
// debugging purposes. // debugging purposes.
void print(llvm::raw_ostream &os) const; void print(llvm::raw_ostream &os) const;
// A helper RAII class to emit nested namespaces for this op.
class NamespaceEmitter {
public:
NamespaceEmitter(raw_ostream &os, Operator &op);
~NamespaceEmitter();
private:
raw_ostream &os;
SmallVector<StringRef, 2> namespaces;
};
// Return whether all the result types are known. // Return whether all the result types are known.
bool allResultTypesKnown() const { return allResultsHaveKnownTypes; }; bool allResultTypesKnown() const { return allResultsHaveKnownTypes; };

View File

@ -25,10 +25,5 @@ void avx512::AVX512Dialect::initialize() {
>(); >();
} }
namespace mlir {
namespace avx512 {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/AVX512/AVX512.cpp.inc" #include "mlir/Dialect/AVX512/AVX512.cpp.inc"
} // namespace avx512
} // namespace mlir

View File

@ -777,10 +777,5 @@ static void print(OpAsmPrinter &p, GPUModuleOp op) {
/*printBlockTerminators=*/false); /*printBlockTerminators=*/false);
} }
// Namespace avoids ambiguous ReturnOpAdaptor.
namespace mlir {
namespace gpu {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/GPU/GPUOps.cpp.inc" #include "mlir/Dialect/GPU/GPUOps.cpp.inc"
} // namespace gpu
} // namespace mlir

View File

@ -23,10 +23,9 @@ using namespace mlir;
using namespace mlir::gpu; using namespace mlir::gpu;
using namespace mlir::scf; using namespace mlir::scf;
#include "mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc"
#include "mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc" #include "mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc"
namespace mlir { namespace mlir {
#include "mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc"
namespace gpu { namespace gpu {
StringRef getMappingAttrName() { return "mapping"; } StringRef getMappingAttrName() { return "mapping"; }

View File

@ -27,9 +27,5 @@ void LLVM::LLVMAVX512Dialect::initialize() {
>(); >();
} }
namespace mlir {
namespace LLVM {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMAVX512.cpp.inc" #include "mlir/Dialect/LLVMIR/LLVMAVX512.cpp.inc"
} // namespace LLVM
} // namespace mlir

View File

@ -16,7 +16,6 @@
#include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Builders.h" #include "mlir/IR/Builders.h"
#include "mlir/IR/MLIRContext.h" #include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Operation.h" #include "mlir/IR/Operation.h"
@ -146,10 +145,5 @@ void NVVMDialect::initialize() {
allowUnknownOperations(); allowUnknownOperations();
} }
namespace mlir {
namespace NVVM {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/NVVMOps.cpp.inc" #include "mlir/Dialect/LLVMIR/NVVMOps.cpp.inc"
} // namespace NVVM
} // namespace mlir

View File

@ -91,10 +91,5 @@ void ROCDLDialect::initialize() {
allowUnknownOperations(); allowUnknownOperations();
} }
namespace mlir {
namespace ROCDL {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc"
} // namespace ROCDL
} // namespace mlir

View File

@ -1096,9 +1096,6 @@ static LogicalResult verify(PoolingSumOp op) {
return verifySingleInputPoolingOp(op); return verifySingleInputPoolingOp(op);
} }
namespace mlir {
namespace linalg {
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc"
#define GET_OP_CLASSES #define GET_OP_CLASSES
@ -1107,9 +1104,6 @@ namespace linalg {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
} // namespace linalg
} // namespace mlir
AffineMap mlir::linalg::extractOrIdentityMap(Optional<AffineMap> maybeMap, AffineMap mlir::linalg::extractOrIdentityMap(Optional<AffineMap> maybeMap,
unsigned rank, unsigned rank,
MLIRContext *context) { MLIRContext *context) {

View File

@ -271,9 +271,5 @@ static ParseResult parseParallelOp(OpAsmParser &parser,
return success(); return success();
} }
namespace mlir {
namespace omp {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc"
} // namespace omp
} // namespace mlir

View File

@ -454,11 +454,5 @@ static LogicalResult verify(TypeOp op) {
// TableGen'd op method definitions // TableGen'd op method definitions
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
namespace mlir {
namespace pdl {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc" #include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc"
} // end namespace pdl
} // end namespace mlir

View File

@ -899,9 +899,5 @@ static void print(OpAsmPrinter &p, scf::YieldOp op) {
// TableGen'd op method definitions // TableGen'd op method definitions
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
namespace mlir {
namespace scf {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/SCF/SCFOps.cpp.inc" #include "mlir/Dialect/SCF/SCFOps.cpp.inc"
} // namespace scf
} // namespace mlir

View File

@ -16,9 +16,10 @@ using namespace mlir;
// DictionaryDict derived attributes // DictionaryDict derived attributes
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
namespace mlir {
#include "mlir/Dialect/SPIRV/TargetAndABI.cpp.inc" #include "mlir/Dialect/SPIRV/TargetAndABI.cpp.inc"
namespace mlir {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Attribute storage classes // Attribute storage classes
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -3266,11 +3266,15 @@ namespace spirv {
// TableGen'erated operation interfaces for querying versions, extensions, and // TableGen'erated operation interfaces for querying versions, extensions, and
// capabilities. // capabilities.
#include "mlir/Dialect/SPIRV/SPIRVAvailability.cpp.inc" #include "mlir/Dialect/SPIRV/SPIRVAvailability.cpp.inc"
} // namespace spirv
} // namespace mlir
// TablenGen'erated operation definitions. // TablenGen'erated operation definitions.
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/SPIRV/SPIRVOps.cpp.inc" #include "mlir/Dialect/SPIRV/SPIRVOps.cpp.inc"
namespace mlir {
namespace spirv {
// TableGen'erated operation availability interface implementations. // TableGen'erated operation availability interface implementations.
#include "mlir/Dialect/SPIRV/SPIRVOpAvailabilityImpl.inc" #include "mlir/Dialect/SPIRV/SPIRVOpAvailabilityImpl.inc"

View File

@ -938,11 +938,5 @@ static void print(OpAsmPrinter &p, ReduceOp op) {
p.printOptionalAttrDict(op.getAttrs()); p.printOptionalAttrDict(op.getAttrs());
} }
namespace mlir {
namespace shape {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Shape/IR/ShapeOps.cpp.inc" #include "mlir/Dialect/Shape/IR/ShapeOps.cpp.inc"
} // namespace shape
} // namespace mlir

View File

@ -2688,11 +2688,5 @@ void mlir::vector::populateVectorToVectorCanonicalizationPatterns(
TransposeFolder>(context); TransposeFolder>(context);
} }
namespace mlir {
namespace vector {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "mlir/Dialect/Vector/VectorOps.cpp.inc" #include "mlir/Dialect/Vector/VectorOps.cpp.inc"
} // namespace vector
} // namespace mlir

View File

@ -18,6 +18,7 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h" #include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h" #include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/FormatVariadic.h"
@ -278,7 +279,7 @@ void Operator::populateTypeInferenceInfo(
// Skip cases currently being custom generated. // Skip cases currently being custom generated.
// TODO: Remove special cases. // TODO: Remove special cases.
if (getTrait("OpTrait::SameOperandsAndResultType")) if (getTrait("::mlir::OpTrait::SameOperandsAndResultType"))
return; return;
// We create equivalence classes of argument/result types where arguments // We create equivalence classes of argument/result types where arguments
@ -565,6 +566,21 @@ void Operator::print(llvm::raw_ostream &os) const {
} }
} }
Operator::NamespaceEmitter::NamespaceEmitter(raw_ostream &os, Operator &op)
: os(os) {
auto dialect = op.getDialect();
if (!dialect)
return;
llvm::SplitString(dialect.getCppNamespace(), namespaces, "::");
for (StringRef ns : namespaces)
os << "namespace " << ns << " {\n";
}
Operator::NamespaceEmitter::~NamespaceEmitter() {
for (StringRef ns : llvm::reverse(namespaces))
os << "} // namespace " << ns << "\n";
}
auto Operator::VariableDecoratorIterator::unwrap(llvm::Init *init) auto Operator::VariableDecoratorIterator::unwrap(llvm::Init *init)
-> VariableDecorator { -> VariableDecorator {
return VariableDecorator(cast<llvm::DefInit>(init)->getDef()); return VariableDecorator(cast<llvm::DefInit>(init)->getDef());

View File

@ -29,7 +29,6 @@
#include "TestOpEnums.h.inc" #include "TestOpEnums.h.inc"
namespace mlir {
#include "TestOpStructs.h.inc" #include "TestOpStructs.h.inc"
#include "TestOpsDialect.h.inc" #include "TestOpsDialect.h.inc"
@ -37,8 +36,8 @@ namespace mlir {
#define GET_OP_CLASSES #define GET_OP_CLASSES
#include "TestOps.h.inc" #include "TestOps.h.inc"
namespace mlir {
void registerTestDialect(DialectRegistry &registry); void registerTestDialect(DialectRegistry &registry);
} // end namespace mlir } // end namespace mlir
#endif // MLIR_TESTDIALECT_H #endif // MLIR_TESTDIALECT_H

View File

@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def Test_Dialect : Dialect { def Test_Dialect : Dialect {
let name = "test"; let name = "test";
let cppNamespace = ""; let cppNamespace = "::mlir";
let hasOperationAttrVerify = 1; let hasOperationAttrVerify = 1;
let hasRegionArgAttrVerify = 1; let hasRegionArgAttrVerify = 1;
let hasRegionResultAttrVerify = 1; let hasRegionResultAttrVerify = 1;

View File

@ -275,3 +275,19 @@ def SomeTypedArrayAttr : TypedArrayAttrBase<SomeAttr, "SomeAttr array">;
// RECORD-LABEL: def SomeTypedArrayAttr // RECORD-LABEL: def SomeTypedArrayAttr
// RECORD: Attr elementAttr = SomeAttr; // RECORD: Attr elementAttr = SomeAttr;
def Test_Dialect_2 : Dialect {
let name = "dialect_2";
}
def MyStruct : StructAttr<"MyStruct", Test_Dialect_2,
[StructFieldAttr<"potatoes", I64ElementsAttr>]> {
let description = "A structure describing a number of potatoes.";
}
def StructAttrOp : NS_Op<"struct_attr_op", []> {
let arguments = (ins
MyStruct:$potatoes
);
}
// DECL: dialect_2::MyStruct potatoes();

View File

@ -61,8 +61,8 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
// CHECK: ::mlir::ValueRange odsOperands; // CHECK: ::mlir::ValueRange odsOperands;
// CHECK: }; // CHECK: };
// CHECK: class AOp : public ::mlir::Op<AOp, OpTrait::AtLeastNRegions<1>::Impl, OpTrait::AtLeastNResults<1>::Impl, OpTrait::ZeroSuccessor, OpTrait::AtLeastNOperands<1>::Impl, OpTrait::IsIsolatedFromAbove // CHECK: class AOp : public ::mlir::Op<AOp, ::mlir::OpTrait::AtLeastNRegions<1>::Impl, ::mlir::OpTrait::AtLeastNResults<1>::Impl, ::mlir::OpTrait::ZeroSuccessor, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::IsIsolatedFromAbove
// CHECK-NOT: OpTrait::IsIsolatedFromAbove // CHECK-NOT: ::mlir::OpTrait::IsIsolatedFromAbove
// CHECK: public: // CHECK: public:
// CHECK: using Op::Op; // CHECK: using Op::Op;
// CHECK: using Adaptor = AOpAdaptor; // CHECK: using Adaptor = AOpAdaptor;

View File

@ -153,6 +153,15 @@ static void emitDialectDecl(Dialect &dialect,
dialectsOs << llvm::formatv(dialectRegistrationTemplate, dialectsOs << llvm::formatv(dialectRegistrationTemplate,
dependentDialect); dependentDialect);
} }
// Emit all nested namespaces.
StringRef cppNamespace = dialect.getCppNamespace();
llvm::SmallVector<StringRef, 2> namespaces;
llvm::SplitString(cppNamespace, namespaces, "::");
for (auto ns : namespaces)
os << "namespace " << ns << " {\n";
// Emit the start of the decl. // Emit the start of the decl.
std::string cppName = dialect.getCppClassName(); std::string cppName = dialect.getCppClassName();
os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName(), os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName(),
@ -179,6 +188,10 @@ static void emitDialectDecl(Dialect &dialect,
// End the dialect decl. // End the dialect decl.
os << "};\n"; os << "};\n";
// Close all nested namespaces in reverse order.
for (auto ns : llvm::reverse(namespaces))
os << "} // namespace " << ns << "\n";
} }
static bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper, static bool emitDialectDecls(const llvm::RecordKeeper &recordKeeper,

View File

@ -494,6 +494,7 @@ void OpEmitter::genAttrGetters() {
FmtContext fctx; FmtContext fctx;
fctx.withBuilder("::mlir::Builder(this->getContext())"); fctx.withBuilder("::mlir::Builder(this->getContext())");
Dialect opDialect = op.getDialect();
// Emit the derived attribute body. // Emit the derived attribute body.
auto emitDerivedAttr = [&](StringRef name, Attribute attr) { auto emitDerivedAttr = [&](StringRef name, Attribute attr) {
auto &method = opClass.newMethod(attr.getReturnType(), name); auto &method = opClass.newMethod(attr.getReturnType(), name);
@ -503,7 +504,16 @@ void OpEmitter::genAttrGetters() {
// Emit with return type specified. // Emit with return type specified.
auto emitAttrWithReturnType = [&](StringRef name, Attribute attr) { auto emitAttrWithReturnType = [&](StringRef name, Attribute attr) {
auto &method = opClass.newMethod(attr.getReturnType(), name); Dialect attrDialect = attr.getDialect();
// Does the current operation have a different namespace than the attribute?
bool differentNamespace =
attrDialect && opDialect && attrDialect != opDialect;
std::string returnType = differentNamespace
? (llvm::Twine(attrDialect.getCppNamespace()) +
"::" + attr.getReturnType())
.str()
: attr.getReturnType().str();
auto &method = opClass.newMethod(returnType, name);
auto &body = method.body(); auto &body = method.body();
body << " auto attr = " << name << "Attr();\n"; body << " auto attr = " << name << "Attr();\n";
if (attr.hasDefaultValue()) { if (attr.hasDefaultValue()) {
@ -684,9 +694,9 @@ static void generateNamedOperandGetters(const Operator &op, Class &opClass,
const int numNormalOperands = numOperands - numVariadicOperands; const int numNormalOperands = numOperands - numVariadicOperands;
const auto *sameVariadicSize = const auto *sameVariadicSize =
op.getTrait("OpTrait::SameVariadicOperandSize"); op.getTrait("::mlir::OpTrait::SameVariadicOperandSize");
const auto *attrSizedOperands = const auto *attrSizedOperands =
op.getTrait("OpTrait::AttrSizedOperandSegments"); op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments");
if (numVariadicOperands > 1 && !sameVariadicSize && !attrSizedOperands) { if (numVariadicOperands > 1 && !sameVariadicSize && !attrSizedOperands) {
PrintFatalError(op.getLoc(), "op has multiple variadic operands but no " PrintFatalError(op.getLoc(), "op has multiple variadic operands but no "
@ -748,7 +758,8 @@ void OpEmitter::genNamedOperandGetters() {
} }
void OpEmitter::genNamedOperandSetters() { void OpEmitter::genNamedOperandSetters() {
auto *attrSizedOperands = op.getTrait("OpTrait::AttrSizedOperandSegments"); auto *attrSizedOperands =
op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments");
for (int i = 0, e = op.getNumOperands(); i != e; ++i) { for (int i = 0, e = op.getNumOperands(); i != e; ++i) {
const auto &operand = op.getOperand(i); const auto &operand = op.getOperand(i);
if (operand.name.empty()) if (operand.name.empty())
@ -775,9 +786,10 @@ void OpEmitter::genNamedResultGetters() {
// If we have more than one variadic results, we need more complicated logic // If we have more than one variadic results, we need more complicated logic
// to calculate the value range for each result. // to calculate the value range for each result.
const auto *sameVariadicSize = op.getTrait("OpTrait::SameVariadicResultSize"); const auto *sameVariadicSize =
op.getTrait("::mlir::OpTrait::SameVariadicResultSize");
const auto *attrSizedResults = const auto *attrSizedResults =
op.getTrait("OpTrait::AttrSizedResultSegments"); op.getTrait("::mlir::OpTrait::AttrSizedResultSegments");
if (numVariadicResults > 1 && !sameVariadicSize && !attrSizedResults) { if (numVariadicResults > 1 && !sameVariadicSize && !attrSizedResults) {
PrintFatalError(op.getLoc(), "op has multiple variadic results but no " PrintFatalError(op.getLoc(), "op has multiple variadic results but no "
@ -1213,7 +1225,7 @@ void OpEmitter::genBuilder() {
// use the first operand or attribute's type as all result types // use the first operand or attribute's type as all result types
// to facilitate different call patterns. // to facilitate different call patterns.
if (op.getNumVariableLengthResults() == 0) { if (op.getNumVariableLengthResults() == 0) {
if (op.getTrait("OpTrait::SameOperandsAndResultType")) { if (op.getTrait("::mlir::OpTrait::SameOperandsAndResultType")) {
// If the operation has a single variadic input, then the build method // If the operation has a single variadic input, then the build method
// generated by `genUseOperandAsResultTypeSeparateParamBuilder` will be // generated by `genUseOperandAsResultTypeSeparateParamBuilder` will be
// ambiguous with the one generated by // ambiguous with the one generated by
@ -1230,7 +1242,7 @@ void OpEmitter::genBuilder() {
if (!shouldGenerateInferredTypeCollectiveParamBuilder()) if (!shouldGenerateInferredTypeCollectiveParamBuilder())
genUseOperandAsResultTypeCollectiveParamBuilder(); genUseOperandAsResultTypeCollectiveParamBuilder();
} }
if (op.getTrait("OpTrait::FirstAttrDerivedResultType")) if (op.getTrait("::mlir::OpTrait::FirstAttrDerivedResultType"))
genUseAttrAsResultTypeBuilder(); genUseAttrAsResultTypeBuilder();
} }
} }
@ -1435,7 +1447,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(OpMethodBody &body,
} }
// If the operation has the operand segment size attribute, add it here. // If the operation has the operand segment size attribute, add it here.
if (op.getTrait("OpTrait::AttrSizedOperandSegments")) { if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments")) {
body << " " << builderOpState body << " " << builderOpState
<< ".addAttribute(\"operand_segment_sizes\", " << ".addAttribute(\"operand_segment_sizes\", "
"odsBuilder.getI32VectorAttr({"; "odsBuilder.getI32VectorAttr({";
@ -1695,7 +1707,7 @@ void OpEmitter::genTypeInterfaceMethods() {
continue; continue;
// TODO: We could verify equality here, but skipping that for verification. // TODO: We could verify equality here, but skipping that for verification.
} }
os << " return success();"; os << " return ::mlir::success();";
} }
void OpEmitter::genParser() { void OpEmitter::genParser() {
@ -1735,7 +1747,7 @@ void OpEmitter::genVerifier() {
auto &body = method.body(); auto &body = method.body();
body << " if (failed(" << op.getAdaptorName() body << " if (failed(" << op.getAdaptorName()
<< "(*this).verify(this->getLoc()))) " << "(*this).verify(this->getLoc()))) "
<< "return failure();\n"; << "return ::mlir::failure();\n";
auto *valueInit = def.getValueInit("verifier"); auto *valueInit = def.getValueInit("verifier");
CodeInit *codeInit = dyn_cast<CodeInit>(valueInit); CodeInit *codeInit = dyn_cast<CodeInit>(valueInit);
@ -1904,21 +1916,21 @@ static void addSizeCountTrait(OpClass &opClass, StringRef traitKind,
int numTotal, int numVariadic) { int numTotal, int numVariadic) {
if (numVariadic != 0) { if (numVariadic != 0) {
if (numTotal == numVariadic) if (numTotal == numVariadic)
opClass.addTrait("OpTrait::Variadic" + traitKind + "s"); opClass.addTrait("::mlir::OpTrait::Variadic" + traitKind + "s");
else else
opClass.addTrait("OpTrait::AtLeastN" + traitKind + "s<" + opClass.addTrait("::mlir::OpTrait::AtLeastN" + traitKind + "s<" +
Twine(numTotal - numVariadic) + ">::Impl"); Twine(numTotal - numVariadic) + ">::Impl");
return; return;
} }
switch (numTotal) { switch (numTotal) {
case 0: case 0:
opClass.addTrait("OpTrait::Zero" + traitKind); opClass.addTrait("::mlir::OpTrait::Zero" + traitKind);
break; break;
case 1: case 1:
opClass.addTrait("OpTrait::One" + traitKind); opClass.addTrait("::mlir::OpTrait::One" + traitKind);
break; break;
default: default:
opClass.addTrait("OpTrait::N" + traitKind + "s<" + Twine(numTotal) + opClass.addTrait("::mlir::OpTrait::N" + traitKind + "s<" + Twine(numTotal) +
">::Impl"); ">::Impl");
break; break;
} }
@ -1947,20 +1959,21 @@ void OpEmitter::genTraits() {
// Add operand size trait. // Add operand size trait.
if (numVariadicOperands != 0) { if (numVariadicOperands != 0) {
if (numOperands == numVariadicOperands) if (numOperands == numVariadicOperands)
opClass.addTrait("OpTrait::VariadicOperands"); opClass.addTrait("::mlir::OpTrait::VariadicOperands");
else else
opClass.addTrait("OpTrait::AtLeastNOperands<" + opClass.addTrait("::mlir::OpTrait::AtLeastNOperands<" +
Twine(numOperands - numVariadicOperands) + ">::Impl"); Twine(numOperands - numVariadicOperands) + ">::Impl");
} else { } else {
switch (numOperands) { switch (numOperands) {
case 0: case 0:
opClass.addTrait("OpTrait::ZeroOperands"); opClass.addTrait("::mlir::OpTrait::ZeroOperands");
break; break;
case 1: case 1:
opClass.addTrait("OpTrait::OneOperand"); opClass.addTrait("::mlir::OpTrait::OneOperand");
break; break;
default: default:
opClass.addTrait("OpTrait::NOperands<" + Twine(numOperands) + ">::Impl"); opClass.addTrait("::mlir::OpTrait::NOperands<" + Twine(numOperands) +
">::Impl");
break; break;
} }
} }
@ -2042,7 +2055,7 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(const Operator &op)
adaptor.newField("::mlir::ValueRange", "odsOperands"); adaptor.newField("::mlir::ValueRange", "odsOperands");
adaptor.newField("::mlir::DictionaryAttr", "odsAttrs"); adaptor.newField("::mlir::DictionaryAttr", "odsAttrs");
const auto *attrSizedOperands = const auto *attrSizedOperands =
op.getTrait("OpTrait::AttrSizedOperandSegments"); op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments");
{ {
auto &constructor = adaptor.newConstructor( auto &constructor = adaptor.newConstructor(
attrSizedOperands attrSizedOperands
@ -2125,11 +2138,11 @@ void OpOperandAdaptorEmitter::addVerification() {
// getODSOperands()/getODSResults() in the rest of the verifier. // getODSOperands()/getODSResults() in the rest of the verifier.
for (auto &trait : op.getTraits()) { for (auto &trait : op.getTraits()) {
if (auto *t = dyn_cast<tblgen::NativeOpTrait>(&trait)) { if (auto *t = dyn_cast<tblgen::NativeOpTrait>(&trait)) {
if (t->getTrait() == "OpTrait::AttrSizedOperandSegments") { if (t->getTrait() == "::mlir::OpTrait::AttrSizedOperandSegments") {
body << formatv(checkAttrSizedValueSegmentsCode, body << formatv(checkAttrSizedValueSegmentsCode,
"operand_segment_sizes", op.getNumOperands(), "operand_segment_sizes", op.getNumOperands(),
"operand"); "operand");
} else if (t->getTrait() == "OpTrait::AttrSizedResultSegments") { } else if (t->getTrait() == "::mlir::OpTrait::AttrSizedResultSegments") {
body << formatv(checkAttrSizedValueSegmentsCode, "result_segment_sizes", body << formatv(checkAttrSizedValueSegmentsCode, "result_segment_sizes",
op.getNumResults(), "result"); op.getNumResults(), "result");
} }
@ -2144,7 +2157,7 @@ void OpOperandAdaptorEmitter::addVerification() {
"' op \"", "' op \"",
/*emitVerificationRequiringOp*/ false, verifyCtx, body); /*emitVerificationRequiringOp*/ false, verifyCtx, body);
body << " return success();"; body << " return ::mlir::success();";
} }
void OpOperandAdaptorEmitter::emitDecl(const Operator &op, raw_ostream &os) { void OpOperandAdaptorEmitter::emitDecl(const Operator &op, raw_ostream &os) {
@ -2165,6 +2178,7 @@ static void emitOpClasses(const std::vector<Record *> &defs, raw_ostream &os,
os << "#undef GET_OP_FWD_DEFINES\n"; os << "#undef GET_OP_FWD_DEFINES\n";
for (auto *def : defs) { for (auto *def : defs) {
Operator op(*def); Operator op(*def);
Operator::NamespaceEmitter emitter(os, op);
os << "class " << op.getCppClassName() << ";\n"; os << "class " << op.getCppClassName() << ";\n";
} }
os << "#endif\n\n"; os << "#endif\n\n";
@ -2173,6 +2187,7 @@ static void emitOpClasses(const std::vector<Record *> &defs, raw_ostream &os,
IfDefScope scope("GET_OP_CLASSES", os); IfDefScope scope("GET_OP_CLASSES", os);
for (auto *def : defs) { for (auto *def : defs) {
Operator op(*def); Operator op(*def);
Operator::NamespaceEmitter emitter(os, op);
if (emitDecl) { if (emitDecl) {
os << formatv(opCommentHeader, op.getQualCppClassName(), "declarations"); os << formatv(opCommentHeader, op.getQualCppClassName(), "declarations");
OpOperandAdaptorEmitter::emitDecl(op, os); OpOperandAdaptorEmitter::emitDecl(op, os);

View File

@ -439,14 +439,14 @@ static bool shouldFormatSymbolNameAttr(const NamedAttribute *attr) {
/// {1}: The type for the attribute. /// {1}: The type for the attribute.
const char *const attrParserCode = R"( const char *const attrParserCode = R"(
if (parser.parseAttribute({0}Attr{1}, "{0}", result.attributes)) if (parser.parseAttribute({0}Attr{1}, "{0}", result.attributes))
return failure(); return ::mlir::failure();
)"; )";
const char *const optionalAttrParserCode = R"( const char *const optionalAttrParserCode = R"(
{ {
::mlir::OptionalParseResult parseResult = ::mlir::OptionalParseResult parseResult =
parser.parseOptionalAttribute({0}Attr{1}, "{0}", result.attributes); parser.parseOptionalAttribute({0}Attr{1}, "{0}", result.attributes);
if (parseResult.hasValue() && failed(*parseResult)) if (parseResult.hasValue() && failed(*parseResult))
return failure(); return ::mlir::failure();
} }
)"; )";
@ -455,7 +455,7 @@ const char *const optionalAttrParserCode = R"(
/// {0}: The name of the attribute. /// {0}: The name of the attribute.
const char *const symbolNameAttrParserCode = R"( const char *const symbolNameAttrParserCode = R"(
if (parser.parseSymbolName({0}Attr, "{0}", result.attributes)) if (parser.parseSymbolName({0}Attr, "{0}", result.attributes))
return failure(); return ::mlir::failure();
)"; )";
const char *const optionalSymbolNameAttrParserCode = R"( const char *const optionalSymbolNameAttrParserCode = R"(
// Parsing an optional symbol name doesn't fail, so no need to check the // Parsing an optional symbol name doesn't fail, so no need to check the
@ -476,7 +476,7 @@ const char *const enumAttrParserCode = R"(
auto loc = parser.getCurrentLocation(); auto loc = parser.getCurrentLocation();
if (parser.parseAttribute(attrVal, parser.getBuilder().getNoneType(), if (parser.parseAttribute(attrVal, parser.getBuilder().getNoneType(),
"{0}", attrStorage)) "{0}", attrStorage))
return failure(); return ::mlir::failure();
auto attrOptional = {1}::{2}(attrVal.getValue()); auto attrOptional = {1}::{2}(attrVal.getValue());
if (!attrOptional) if (!attrOptional)
@ -498,7 +498,7 @@ const char *const optionalEnumAttrParserCode = R"(
"{0}", attrStorage); "{0}", attrStorage);
if (parseResult.hasValue()) { if (parseResult.hasValue()) {
if (failed(*parseResult)) if (failed(*parseResult))
return failure(); return ::mlir::failure();
auto attrOptional = {1}::{2}(attrVal.getValue()); auto attrOptional = {1}::{2}(attrVal.getValue());
if (!attrOptional) if (!attrOptional)
@ -517,7 +517,7 @@ const char *const optionalEnumAttrParserCode = R"(
const char *const variadicOperandParserCode = R"( const char *const variadicOperandParserCode = R"(
{0}OperandsLoc = parser.getCurrentLocation(); {0}OperandsLoc = parser.getCurrentLocation();
if (parser.parseOperandList({0}Operands)) if (parser.parseOperandList({0}Operands))
return failure(); return ::mlir::failure();
)"; )";
const char *const optionalOperandParserCode = R"( const char *const optionalOperandParserCode = R"(
{ {
@ -527,7 +527,7 @@ const char *const optionalOperandParserCode = R"(
parser.parseOptionalOperand(operand); parser.parseOptionalOperand(operand);
if (parseResult.hasValue()) { if (parseResult.hasValue()) {
if (failed(*parseResult)) if (failed(*parseResult))
return failure(); return ::mlir::failure();
{0}Operands.push_back(operand); {0}Operands.push_back(operand);
} }
} }
@ -535,7 +535,7 @@ const char *const optionalOperandParserCode = R"(
const char *const operandParserCode = R"( const char *const operandParserCode = R"(
{0}OperandsLoc = parser.getCurrentLocation(); {0}OperandsLoc = parser.getCurrentLocation();
if (parser.parseOperand({0}RawOperands[0])) if (parser.parseOperand({0}RawOperands[0]))
return failure(); return ::mlir::failure();
)"; )";
/// The code snippet used to generate a parser call for a type list. /// The code snippet used to generate a parser call for a type list.
@ -543,7 +543,7 @@ const char *const operandParserCode = R"(
/// {0}: The name for the type list. /// {0}: The name for the type list.
const char *const variadicTypeParserCode = R"( const char *const variadicTypeParserCode = R"(
if (parser.parseTypeList({0}Types)) if (parser.parseTypeList({0}Types))
return failure(); return ::mlir::failure();
)"; )";
const char *const optionalTypeParserCode = R"( const char *const optionalTypeParserCode = R"(
{ {
@ -552,14 +552,14 @@ const char *const optionalTypeParserCode = R"(
parser.parseOptionalType(optionalType); parser.parseOptionalType(optionalType);
if (parseResult.hasValue()) { if (parseResult.hasValue()) {
if (failed(*parseResult)) if (failed(*parseResult))
return failure(); return ::mlir::failure();
{0}Types.push_back(optionalType); {0}Types.push_back(optionalType);
} }
} }
)"; )";
const char *const typeParserCode = R"( const char *const typeParserCode = R"(
if (parser.parseType({0}RawTypes[0])) if (parser.parseType({0}RawTypes[0]))
return failure(); return ::mlir::failure();
)"; )";
/// The code snippet used to generate a parser call for a functional type. /// The code snippet used to generate a parser call for a functional type.
@ -569,7 +569,7 @@ const char *const typeParserCode = R"(
const char *const functionalTypeParserCode = R"( const char *const functionalTypeParserCode = R"(
::mlir::FunctionType {0}__{1}_functionType; ::mlir::FunctionType {0}__{1}_functionType;
if (parser.parseType({0}__{1}_functionType)) if (parser.parseType({0}__{1}_functionType))
return failure(); return ::mlir::failure();
{0}Types = {0}__{1}_functionType.getInputs(); {0}Types = {0}__{1}_functionType.getInputs();
{1}Types = {0}__{1}_functionType.getResults(); {1}Types = {0}__{1}_functionType.getResults();
)"; )";
@ -583,14 +583,14 @@ const char *regionListParserCode = R"(
auto firstRegionResult = parser.parseOptionalRegion(region); auto firstRegionResult = parser.parseOptionalRegion(region);
if (firstRegionResult.hasValue()) { if (firstRegionResult.hasValue()) {
if (failed(*firstRegionResult)) if (failed(*firstRegionResult))
return failure(); return ::mlir::failure();
{0}Regions.emplace_back(std::move(region)); {0}Regions.emplace_back(std::move(region));
// Parse any trailing regions. // Parse any trailing regions.
while (succeeded(parser.parseOptionalComma())) { while (succeeded(parser.parseOptionalComma())) {
region = std::make_unique<::mlir::Region>(); region = std::make_unique<::mlir::Region>();
if (parser.parseRegion(*region)) if (parser.parseRegion(*region))
return failure(); return ::mlir::failure();
{0}Regions.emplace_back(std::move(region)); {0}Regions.emplace_back(std::move(region));
} }
} }
@ -610,7 +610,7 @@ const char *regionListEnsureTerminatorParserCode = R"(
/// {0}: The name of the region. /// {0}: The name of the region.
const char *optionalRegionParserCode = R"( const char *optionalRegionParserCode = R"(
if (parser.parseOptionalRegion(*{0}Region)) if (parser.parseOptionalRegion(*{0}Region))
return failure(); return ::mlir::failure();
)"; )";
/// The code snippet used to generate a parser call for a region. /// The code snippet used to generate a parser call for a region.
@ -618,7 +618,7 @@ const char *optionalRegionParserCode = R"(
/// {0}: The name of the region. /// {0}: The name of the region.
const char *regionParserCode = R"( const char *regionParserCode = R"(
if (parser.parseRegion(*{0}Region)) if (parser.parseRegion(*{0}Region))
return failure(); return ::mlir::failure();
)"; )";
/// The code snippet used to ensure a region has a terminator. /// The code snippet used to ensure a region has a terminator.
@ -637,13 +637,13 @@ const char *successorListParserCode = R"(
auto firstSucc = parser.parseOptionalSuccessor(succ); auto firstSucc = parser.parseOptionalSuccessor(succ);
if (firstSucc.hasValue()) { if (firstSucc.hasValue()) {
if (failed(*firstSucc)) if (failed(*firstSucc))
return failure(); return ::mlir::failure();
{0}Successors.emplace_back(succ); {0}Successors.emplace_back(succ);
// Parse any trailing successors. // Parse any trailing successors.
while (succeeded(parser.parseOptionalComma())) { while (succeeded(parser.parseOptionalComma())) {
if (parser.parseSuccessor(succ)) if (parser.parseSuccessor(succ))
return failure(); return ::mlir::failure();
{0}Successors.emplace_back(succ); {0}Successors.emplace_back(succ);
} }
} }
@ -655,7 +655,7 @@ const char *successorListParserCode = R"(
/// {0}: The name of the successor. /// {0}: The name of the successor.
const char *successorParserCode = R"( const char *successorParserCode = R"(
if (parser.parseSuccessor({0}Successor)) if (parser.parseSuccessor({0}Successor))
return failure(); return ::mlir::failure();
)"; )";
namespace { namespace {
@ -889,7 +889,7 @@ static void genCustomDirectiveParser(CustomDirective *dir, OpMethodBody &body) {
genCustomParameterParser(param, body); genCustomParameterParser(param, body);
body << "))\n" body << "))\n"
<< " return failure();\n"; << " return ::mlir::failure();\n";
// After parsing, add handling for any of the optional constructs. // After parsing, add handling for any of the optional constructs.
for (Element &param : dir->getArguments()) { for (Element &param : dir->getArguments()) {
@ -949,7 +949,7 @@ void OperationFormat::genParser(Operator &op, OpClass &opClass) {
genParserSuccessorResolution(op, body); genParserSuccessorResolution(op, body);
genParserVariadicSegmentResolution(op, body); genParserVariadicSegmentResolution(op, body);
body << " return success();\n"; body << " return ::mlir::success();\n";
} }
void OperationFormat::genElementParser(Element *element, OpMethodBody &body, void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
@ -1007,7 +1007,7 @@ void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
} else if (LiteralElement *literal = dyn_cast<LiteralElement>(element)) { } else if (LiteralElement *literal = dyn_cast<LiteralElement>(element)) {
body << " if (parser.parse"; body << " if (parser.parse";
genLiteralParser(literal->getLiteral(), body); genLiteralParser(literal->getLiteral(), body);
body << ")\n return failure();\n"; body << ")\n return ::mlir::failure();\n";
/// Arguments. /// Arguments.
} else if (auto *attr = dyn_cast<AttributeVariable>(element)) { } else if (auto *attr = dyn_cast<AttributeVariable>(element)) {
@ -1081,14 +1081,14 @@ void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
body << " if (parser.parseOptionalAttrDict" body << " if (parser.parseOptionalAttrDict"
<< (attrDict->isWithKeyword() ? "WithKeyword" : "") << (attrDict->isWithKeyword() ? "WithKeyword" : "")
<< "(result.attributes))\n" << "(result.attributes))\n"
<< " return failure();\n"; << " return ::mlir::failure();\n";
} else if (auto *customDir = dyn_cast<CustomDirective>(element)) { } else if (auto *customDir = dyn_cast<CustomDirective>(element)) {
genCustomDirectiveParser(customDir, body); genCustomDirectiveParser(customDir, body);
} else if (isa<OperandsDirective>(element)) { } else if (isa<OperandsDirective>(element)) {
body << " ::llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n" body << " ::llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n"
<< " if (parser.parseOperandList(allOperands))\n" << " if (parser.parseOperandList(allOperands))\n"
<< " return failure();\n"; << " return ::mlir::failure();\n";
} else if (isa<RegionsDirective>(element)) { } else if (isa<RegionsDirective>(element)) {
body << llvm::formatv(regionListParserCode, "full"); body << llvm::formatv(regionListParserCode, "full");
@ -1197,7 +1197,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
if (allOperands) { if (allOperands) {
body << " if (parser.resolveOperands(allOperands, allOperandTypes, " body << " if (parser.resolveOperands(allOperands, allOperandTypes, "
"allOperandLoc, result.operands))\n" "allOperandLoc, result.operands))\n"
" return failure();\n"; " return ::mlir::failure();\n";
return; return;
} }
@ -1214,7 +1214,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
body << op.operand_begin()->name << "Operands"; body << op.operand_begin()->name << "Operands";
} }
body << ", allOperandTypes, parser.getNameLoc(), result.operands))\n" body << ", allOperandTypes, parser.getNameLoc(), result.operands))\n"
<< " return failure();\n"; << " return ::mlir::failure();\n";
return; return;
} }
// Handle the case where all of the operands were grouped together. // Handle the case where all of the operands were grouped together.
@ -1238,7 +1238,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
} }
body << ", allOperandLoc, result.operands))\n" body << ", allOperandLoc, result.operands))\n"
<< " return failure();\n"; << " return ::mlir::failure();\n";
return; return;
} }
@ -1270,7 +1270,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
// overload. // overload.
if (verifyOperandAndTypeSize) if (verifyOperandAndTypeSize)
body << ", " << operand.name << "OperandsLoc"; body << ", " << operand.name << "OperandsLoc";
body << ", result.operands))\n return failure();\n"; body << ", result.operands))\n return ::mlir::failure();\n";
} }
} }
@ -1314,7 +1314,8 @@ void OperationFormat::genParserSuccessorResolution(Operator &op,
void OperationFormat::genParserVariadicSegmentResolution(Operator &op, void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
OpMethodBody &body) { OpMethodBody &body) {
if (!allOperands && op.getTrait("OpTrait::AttrSizedOperandSegments")) { if (!allOperands &&
op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments")) {
body << " result.addAttribute(\"operand_segment_sizes\", " body << " result.addAttribute(\"operand_segment_sizes\", "
<< "parser.getBuilder().getI32VectorAttr({"; << "parser.getBuilder().getI32VectorAttr({";
auto interleaveFn = [&](const NamedTypeConstraint &operand) { auto interleaveFn = [&](const NamedTypeConstraint &operand) {
@ -1328,7 +1329,8 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
body << "}));\n"; body << "}));\n";
} }
if (!allResultTypes && op.getTrait("OpTrait::AttrSizedResultSegments")) { if (!allResultTypes &&
op.getTrait("::mlir::OpTrait::AttrSizedResultSegments")) {
body << " result.addAttribute(\"result_segment_sizes\", " body << " result.addAttribute(\"result_segment_sizes\", "
<< "parser.getBuilder().getI32VectorAttr({"; << "parser.getBuilder().getI32VectorAttr({";
auto interleaveFn = [&](const NamedTypeConstraint &result) { auto interleaveFn = [&](const NamedTypeConstraint &result) {
@ -1369,9 +1371,11 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
body << " p.printOptionalAttrDict" << (withKeyword ? "WithKeyword" : "") body << " p.printOptionalAttrDict" << (withKeyword ? "WithKeyword" : "")
<< "(getAttrs(), /*elidedAttrs=*/{"; << "(getAttrs(), /*elidedAttrs=*/{";
// Elide the variadic segment size attributes if necessary. // Elide the variadic segment size attributes if necessary.
if (!fmt.allOperands && op.getTrait("OpTrait::AttrSizedOperandSegments")) if (!fmt.allOperands &&
op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
body << "\"operand_segment_sizes\", "; body << "\"operand_segment_sizes\", ";
if (!fmt.allResultTypes && op.getTrait("OpTrait::AttrSizedResultSegments")) if (!fmt.allResultTypes &&
op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
body << "\"result_segment_sizes\", "; body << "\"result_segment_sizes\", ";
llvm::interleaveComma( llvm::interleaveComma(
fmt.usedAttributes, body, fmt.usedAttributes, body,
@ -1607,7 +1611,7 @@ void OperationFormat::genElementPrinter(Element *element, OpMethodBody &body,
} }
void OperationFormat::genPrinter(Operator &op, OpClass &opClass) { void OperationFormat::genPrinter(Operator &op, OpClass &opClass) {
auto &method = opClass.newMethod("void", "print", "OpAsmPrinter &p"); auto &method = opClass.newMethod("void", "print", "::mlir::OpAsmPrinter &p");
auto &body = method.body(); auto &body = method.body();
// Emit the operation name, trimming the prefix if this is the standard // Emit the operation name, trimming the prefix if this is the standard
@ -2004,16 +2008,16 @@ private:
if (curToken.getKind() != kind) if (curToken.getKind() != kind)
return emitError(curToken.getLoc(), msg); return emitError(curToken.getLoc(), msg);
consumeToken(); consumeToken();
return success(); return ::mlir::success();
} }
LogicalResult emitError(llvm::SMLoc loc, const Twine &msg) { LogicalResult emitError(llvm::SMLoc loc, const Twine &msg) {
lexer.emitError(loc, msg); lexer.emitError(loc, msg);
return failure(); return ::mlir::failure();
} }
LogicalResult emitErrorAndNote(llvm::SMLoc loc, const Twine &msg, LogicalResult emitErrorAndNote(llvm::SMLoc loc, const Twine &msg,
const Twine &note) { const Twine &note) {
lexer.emitErrorAndNote(loc, msg, note); lexer.emitErrorAndNote(loc, msg, note);
return failure(); return ::mlir::failure();
} }
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
@ -2045,7 +2049,7 @@ LogicalResult FormatParser::parse() {
while (curToken.getKind() != Token::eof) { while (curToken.getKind() != Token::eof) {
std::unique_ptr<Element> element; std::unique_ptr<Element> element;
if (failed(parseElement(element, /*isTopLevel=*/true))) if (failed(parseElement(element, /*isTopLevel=*/true)))
return failure(); return ::mlir::failure();
fmt.elements.push_back(std::move(element)); fmt.elements.push_back(std::move(element));
} }
@ -2075,11 +2079,11 @@ LogicalResult FormatParser::parse() {
failed(verifyResults(loc, variableTyResolver)) || failed(verifyResults(loc, variableTyResolver)) ||
failed(verifyOperands(loc, variableTyResolver)) || failed(verifyOperands(loc, variableTyResolver)) ||
failed(verifyRegions(loc)) || failed(verifySuccessors(loc))) failed(verifyRegions(loc)) || failed(verifySuccessors(loc)))
return failure(); return ::mlir::failure();
// Collect the set of used attributes in the format. // Collect the set of used attributes in the format.
fmt.usedAttributes = seenAttrs.takeVector(); fmt.usedAttributes = seenAttrs.takeVector();
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::verifyAttributes(llvm::SMLoc loc) { LogicalResult FormatParser::verifyAttributes(llvm::SMLoc loc) {
@ -2093,8 +2097,8 @@ LogicalResult FormatParser::verifyAttributes(llvm::SMLoc loc) {
iteratorStack.emplace_back(fmt.elements.begin(), fmt.elements.end()); iteratorStack.emplace_back(fmt.elements.begin(), fmt.elements.end());
while (!iteratorStack.empty()) while (!iteratorStack.empty())
if (failed(verifyAttributes(loc, iteratorStack))) if (failed(verifyAttributes(loc, iteratorStack)))
return failure(); return ::mlir::failure();
return success(); return ::mlir::success();
} }
/// Verify the attribute elements at the back of the given stack of iterators. /// Verify the attribute elements at the back of the given stack of iterators.
LogicalResult FormatParser::verifyAttributes( LogicalResult FormatParser::verifyAttributes(
@ -2109,7 +2113,7 @@ LogicalResult FormatParser::verifyAttributes(
if (auto *optional = dyn_cast<OptionalElement>(element)) { if (auto *optional = dyn_cast<OptionalElement>(element)) {
auto elements = optional->getElements(); auto elements = optional->getElements();
iteratorStack.emplace_back(elements.begin(), elements.end()); iteratorStack.emplace_back(elements.begin(), elements.end());
return success(); return ::mlir::success();
} }
// We are checking for an attribute element followed by a `:`, so there is // We are checking for an attribute element followed by a `:`, so there is
@ -2145,7 +2149,7 @@ LogicalResult FormatParser::verifyAttributes(
} }
} }
iteratorStack.pop_back(); iteratorStack.pop_back();
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::verifyOperands( LogicalResult FormatParser::verifyOperands(
@ -2193,13 +2197,13 @@ LogicalResult FormatParser::verifyOperands(
auto it = buildableTypes.insert({*builder, buildableTypes.size()}); auto it = buildableTypes.insert({*builder, buildableTypes.size()});
fmt.operandTypes[i].setBuilderIdx(it.first->second); fmt.operandTypes[i].setBuilderIdx(it.first->second);
} }
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::verifyRegions(llvm::SMLoc loc) { LogicalResult FormatParser::verifyRegions(llvm::SMLoc loc) {
// Check that all of the regions are within the format. // Check that all of the regions are within the format.
if (hasAllRegions) if (hasAllRegions)
return success(); return ::mlir::success();
for (unsigned i = 0, e = op.getNumRegions(); i != e; ++i) { for (unsigned i = 0, e = op.getNumRegions(); i != e; ++i) {
const NamedRegion &region = op.getRegion(i); const NamedRegion &region = op.getRegion(i);
@ -2211,7 +2215,7 @@ LogicalResult FormatParser::verifyRegions(llvm::SMLoc loc) {
"' directive to the custom assembly format"); "' directive to the custom assembly format");
} }
} }
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::verifyResults( LogicalResult FormatParser::verifyResults(
@ -2219,7 +2223,7 @@ LogicalResult FormatParser::verifyResults(
llvm::StringMap<TypeResolutionInstance> &variableTyResolver) { llvm::StringMap<TypeResolutionInstance> &variableTyResolver) {
// If we format all of the types together, there is nothing to check. // If we format all of the types together, there is nothing to check.
if (fmt.allResultTypes) if (fmt.allResultTypes)
return success(); return ::mlir::success();
// Check that all of the result types can be inferred. // Check that all of the result types can be inferred.
auto &buildableTypes = fmt.buildableTypes; auto &buildableTypes = fmt.buildableTypes;
@ -2252,13 +2256,13 @@ LogicalResult FormatParser::verifyResults(
auto it = buildableTypes.insert({*builder, buildableTypes.size()}); auto it = buildableTypes.insert({*builder, buildableTypes.size()});
fmt.resultTypes[i].setBuilderIdx(it.first->second); fmt.resultTypes[i].setBuilderIdx(it.first->second);
} }
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::verifySuccessors(llvm::SMLoc loc) { LogicalResult FormatParser::verifySuccessors(llvm::SMLoc loc) {
// Check that all of the successors are within the format. // Check that all of the successors are within the format.
if (hasAllSuccessors) if (hasAllSuccessors)
return success(); return ::mlir::success();
for (unsigned i = 0, e = op.getNumSuccessors(); i != e; ++i) { for (unsigned i = 0, e = op.getNumSuccessors(); i != e; ++i) {
const NamedSuccessor &successor = op.getSuccessor(i); const NamedSuccessor &successor = op.getSuccessor(i);
@ -2270,7 +2274,7 @@ LogicalResult FormatParser::verifySuccessors(llvm::SMLoc loc) {
"' directive to the custom assembly format"); "' directive to the custom assembly format");
} }
} }
return success(); return ::mlir::success();
} }
void FormatParser::handleAllTypesMatchConstraint( void FormatParser::handleAllTypesMatchConstraint(
@ -2368,7 +2372,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (isTopLevel && !seenAttrs.insert(attr)) if (isTopLevel && !seenAttrs.insert(attr))
return emitError(loc, "attribute '" + name + "' is already bound"); return emitError(loc, "attribute '" + name + "' is already bound");
element = std::make_unique<AttributeVariable>(attr); element = std::make_unique<AttributeVariable>(attr);
return success(); return ::mlir::success();
} }
/// Operands /// Operands
if (const NamedTypeConstraint *operand = findArg(op.getOperands(), name)) { if (const NamedTypeConstraint *operand = findArg(op.getOperands(), name)) {
@ -2377,7 +2381,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
return emitError(loc, "operand '" + name + "' is already bound"); return emitError(loc, "operand '" + name + "' is already bound");
} }
element = std::make_unique<OperandVariable>(operand); element = std::make_unique<OperandVariable>(operand);
return success(); return ::mlir::success();
} }
/// Regions /// Regions
if (const NamedRegion *region = findArg(op.getRegions(), name)) { if (const NamedRegion *region = findArg(op.getRegions(), name)) {
@ -2386,14 +2390,14 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (hasAllRegions || !seenRegions.insert(region).second) if (hasAllRegions || !seenRegions.insert(region).second)
return emitError(loc, "region '" + name + "' is already bound"); return emitError(loc, "region '" + name + "' is already bound");
element = std::make_unique<RegionVariable>(region); element = std::make_unique<RegionVariable>(region);
return success(); return ::mlir::success();
} }
/// Results. /// Results.
if (const auto *result = findArg(op.getResults(), name)) { if (const auto *result = findArg(op.getResults(), name)) {
if (isTopLevel) if (isTopLevel)
return emitError(loc, "results can not be used at the top level"); return emitError(loc, "results can not be used at the top level");
element = std::make_unique<ResultVariable>(result); element = std::make_unique<ResultVariable>(result);
return success(); return ::mlir::success();
} }
/// Successors. /// Successors.
if (const auto *successor = findArg(op.getSuccessors(), name)) { if (const auto *successor = findArg(op.getSuccessors(), name)) {
@ -2402,7 +2406,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (hasAllSuccessors || !seenSuccessors.insert(successor).second) if (hasAllSuccessors || !seenSuccessors.insert(successor).second)
return emitError(loc, "successor '" + name + "' is already bound"); return emitError(loc, "successor '" + name + "' is already bound");
element = std::make_unique<SuccessorVariable>(successor); element = std::make_unique<SuccessorVariable>(successor);
return success(); return ::mlir::success();
} }
return emitError(loc, "expected variable to refer to an argument, region, " return emitError(loc, "expected variable to refer to an argument, region, "
"result, or successor"); "result, or successor");
@ -2450,7 +2454,7 @@ LogicalResult FormatParser::parseLiteral(std::unique_ptr<Element> &element) {
return emitError(literalTok.getLoc(), "expected valid literal"); return emitError(literalTok.getLoc(), "expected valid literal");
element = std::make_unique<LiteralElement>(value); element = std::make_unique<LiteralElement>(value);
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element, LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
@ -2467,11 +2471,11 @@ LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
Optional<unsigned> anchorIdx; Optional<unsigned> anchorIdx;
do { do {
if (failed(parseOptionalChildElement(elements, seenVariables, anchorIdx))) if (failed(parseOptionalChildElement(elements, seenVariables, anchorIdx)))
return failure(); return ::mlir::failure();
} while (curToken.getKind() != Token::r_paren); } while (curToken.getKind() != Token::r_paren);
consumeToken(); consumeToken();
if (failed(parseToken(Token::question, "expected '?' after optional group"))) if (failed(parseToken(Token::question, "expected '?' after optional group")))
return failure(); return ::mlir::failure();
// The optional group is required to have an anchor. // The optional group is required to have an anchor.
if (!anchorIdx) if (!anchorIdx)
@ -2494,22 +2498,22 @@ LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
if (!seenVariables.count(var)) if (!seenVariables.count(var))
return emitError(curLoc, "type directive can only refer to variables " return emitError(curLoc, "type directive can only refer to variables "
"within the optional group"); "within the optional group");
return success(); return ::mlir::success();
}; };
for (auto &ele : elements) { for (auto &ele : elements) {
if (auto *typeEle = dyn_cast<TypeDirective>(ele.get())) { if (auto *typeEle = dyn_cast<TypeDirective>(ele.get())) {
if (failed(checkTypeOperand(typeEle->getOperand()))) if (failed(checkTypeOperand(typeEle->getOperand())))
return failure(); return ::mlir::failure();
} else if (auto *typeEle = dyn_cast<FunctionalTypeDirective>(ele.get())) { } else if (auto *typeEle = dyn_cast<FunctionalTypeDirective>(ele.get())) {
if (failed(checkTypeOperand(typeEle->getInputs())) || if (failed(checkTypeOperand(typeEle->getInputs())) ||
failed(checkTypeOperand(typeEle->getResults()))) failed(checkTypeOperand(typeEle->getResults())))
return failure(); return ::mlir::failure();
} }
} }
optionalVariables.insert(seenVariables.begin(), seenVariables.end()); optionalVariables.insert(seenVariables.begin(), seenVariables.end());
element = std::make_unique<OptionalElement>(std::move(elements), *anchorIdx); element = std::make_unique<OptionalElement>(std::move(elements), *anchorIdx);
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::parseOptionalChildElement( LogicalResult FormatParser::parseOptionalChildElement(
@ -2519,7 +2523,7 @@ LogicalResult FormatParser::parseOptionalChildElement(
llvm::SMLoc childLoc = curToken.getLoc(); llvm::SMLoc childLoc = curToken.getLoc();
childElements.push_back({}); childElements.push_back({});
if (failed(parseElement(childElements.back(), /*isTopLevel=*/true))) if (failed(parseElement(childElements.back(), /*isTopLevel=*/true)))
return failure(); return ::mlir::failure();
// Check to see if this element is the anchor of the optional group. // Check to see if this element is the anchor of the optional group.
bool isAnchor = curToken.getKind() == Token::caret; bool isAnchor = curToken.getKind() == Token::caret;
@ -2538,7 +2542,7 @@ LogicalResult FormatParser::parseOptionalChildElement(
if (isAnchor && !attrEle->getVar()->attr.isOptional()) if (isAnchor && !attrEle->getVar()->attr.isOptional())
return emitError(childLoc, "only optional attributes can be used to " return emitError(childLoc, "only optional attributes can be used to "
"anchor an optional group"); "anchor an optional group");
return success(); return ::mlir::success();
}) })
// Only optional-like(i.e. variadic) operands can be within an optional // Only optional-like(i.e. variadic) operands can be within an optional
// group. // group.
@ -2547,12 +2551,12 @@ LogicalResult FormatParser::parseOptionalChildElement(
return emitError(childLoc, "only variable length operands can be " return emitError(childLoc, "only variable length operands can be "
"used within an optional group"); "used within an optional group");
seenVariables.insert(ele->getVar()); seenVariables.insert(ele->getVar());
return success(); return ::mlir::success();
}) })
.Case<RegionVariable>([&](RegionVariable *) { .Case<RegionVariable>([&](RegionVariable *) {
// TODO: When ODS has proper support for marking "optional" regions, add // TODO: When ODS has proper support for marking "optional" regions, add
// a check here. // a check here.
return success(); return ::mlir::success();
}) })
// Literals, custom directives, and type directives may be used, // Literals, custom directives, and type directives may be used,
// but they can't anchor the group. // but they can't anchor the group.
@ -2561,7 +2565,7 @@ LogicalResult FormatParser::parseOptionalChildElement(
if (isAnchor) if (isAnchor)
return emitError(childLoc, "only variables can be used to anchor " return emitError(childLoc, "only variables can be used to anchor "
"an optional group"); "an optional group");
return success(); return ::mlir::success();
}) })
.Default([&](Element *) { .Default([&](Element *) {
return emitError(childLoc, "only literals, types, and variables can be " return emitError(childLoc, "only literals, types, and variables can be "
@ -2581,7 +2585,7 @@ FormatParser::parseAttrDictDirective(std::unique_ptr<Element> &element,
hasAttrDict = true; hasAttrDict = true;
element = std::make_unique<AttrDictDirective>(withKeyword); element = std::make_unique<AttrDictDirective>(withKeyword);
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2592,7 +2596,7 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
// Parse the custom directive name. // Parse the custom directive name.
if (failed( if (failed(
parseToken(Token::less, "expected '<' before custom directive name"))) parseToken(Token::less, "expected '<' before custom directive name")))
return failure(); return ::mlir::failure();
Token nameTok = curToken; Token nameTok = curToken;
if (failed(parseToken(Token::identifier, if (failed(parseToken(Token::identifier,
@ -2601,13 +2605,13 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
"expected '>' after custom directive name")) || "expected '>' after custom directive name")) ||
failed(parseToken(Token::l_paren, failed(parseToken(Token::l_paren,
"expected '(' before custom directive parameters"))) "expected '(' before custom directive parameters")))
return failure(); return ::mlir::failure();
// Parse the child elements for this optional group.= // Parse the child elements for this optional group.=
std::vector<std::unique_ptr<Element>> elements; std::vector<std::unique_ptr<Element>> elements;
do { do {
if (failed(parseCustomDirectiveParameter(elements))) if (failed(parseCustomDirectiveParameter(elements)))
return failure(); return ::mlir::failure();
if (curToken.getKind() != Token::comma) if (curToken.getKind() != Token::comma)
break; break;
consumeToken(); consumeToken();
@ -2615,7 +2619,7 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
if (failed(parseToken(Token::r_paren, if (failed(parseToken(Token::r_paren,
"expected ')' after custom directive parameters"))) "expected ')' after custom directive parameters")))
return failure(); return ::mlir::failure();
// After parsing all of the elements, ensure that all type directives refer // After parsing all of the elements, ensure that all type directives refer
// only to variables. // only to variables.
@ -2630,7 +2634,7 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
element = std::make_unique<CustomDirective>(nameTok.getSpelling(), element = std::make_unique<CustomDirective>(nameTok.getSpelling(),
std::move(elements)); std::move(elements));
return success(); return ::mlir::success();
} }
LogicalResult FormatParser::parseCustomDirectiveParameter( LogicalResult FormatParser::parseCustomDirectiveParameter(
@ -2638,7 +2642,7 @@ LogicalResult FormatParser::parseCustomDirectiveParameter(
llvm::SMLoc childLoc = curToken.getLoc(); llvm::SMLoc childLoc = curToken.getLoc();
parameters.push_back({}); parameters.push_back({});
if (failed(parseElement(parameters.back(), /*isTopLevel=*/true))) if (failed(parseElement(parameters.back(), /*isTopLevel=*/true)))
return failure(); return ::mlir::failure();
// Verify that the element can be placed within a custom directive. // Verify that the element can be placed within a custom directive.
if (!isa<TypeDirective, AttributeVariable, OperandVariable, RegionVariable, if (!isa<TypeDirective, AttributeVariable, OperandVariable, RegionVariable,
@ -2646,7 +2650,7 @@ LogicalResult FormatParser::parseCustomDirectiveParameter(
return emitError(childLoc, "only variables and types may be used as " return emitError(childLoc, "only variables and types may be used as "
"parameters to a custom directive"); "parameters to a custom directive");
} }
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2664,10 +2668,10 @@ FormatParser::parseFunctionalTypeDirective(std::unique_ptr<Element> &element,
failed(parseToken(Token::comma, "expected ',' after inputs argument")) || failed(parseToken(Token::comma, "expected ',' after inputs argument")) ||
failed(parseTypeDirectiveOperand(results)) || failed(parseTypeDirectiveOperand(results)) ||
failed(parseToken(Token::r_paren, "expected ')' after argument list"))) failed(parseToken(Token::r_paren, "expected ')' after argument list")))
return failure(); return ::mlir::failure();
element = std::make_unique<FunctionalTypeDirective>(std::move(inputs), element = std::make_unique<FunctionalTypeDirective>(std::move(inputs),
std::move(results)); std::move(results));
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2679,7 +2683,7 @@ FormatParser::parseOperandsDirective(std::unique_ptr<Element> &element,
fmt.allOperands = true; fmt.allOperands = true;
} }
element = std::make_unique<OperandsDirective>(); element = std::make_unique<OperandsDirective>();
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2691,7 +2695,7 @@ FormatParser::parseRegionsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'regions' directive creates overlap in format"); return emitError(loc, "'regions' directive creates overlap in format");
hasAllRegions = true; hasAllRegions = true;
element = std::make_unique<RegionsDirective>(); element = std::make_unique<RegionsDirective>();
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2701,7 +2705,7 @@ FormatParser::parseResultsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'results' directive can not be used as a " return emitError(loc, "'results' directive can not be used as a "
"top-level directive"); "top-level directive");
element = std::make_unique<ResultsDirective>(); element = std::make_unique<ResultsDirective>();
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2714,7 +2718,7 @@ FormatParser::parseSuccessorsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'successors' directive creates overlap in format"); return emitError(loc, "'successors' directive creates overlap in format");
hasAllSuccessors = true; hasAllSuccessors = true;
element = std::make_unique<SuccessorsDirective>(); element = std::make_unique<SuccessorsDirective>();
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
@ -2728,16 +2732,16 @@ FormatParser::parseTypeDirective(std::unique_ptr<Element> &element, Token tok,
if (failed(parseToken(Token::l_paren, "expected '(' before argument list")) || if (failed(parseToken(Token::l_paren, "expected '(' before argument list")) ||
failed(parseTypeDirectiveOperand(operand)) || failed(parseTypeDirectiveOperand(operand)) ||
failed(parseToken(Token::r_paren, "expected ')' after argument list"))) failed(parseToken(Token::r_paren, "expected ')' after argument list")))
return failure(); return ::mlir::failure();
element = std::make_unique<TypeDirective>(std::move(operand)); element = std::make_unique<TypeDirective>(std::move(operand));
return success(); return ::mlir::success();
} }
LogicalResult LogicalResult
FormatParser::parseTypeDirectiveOperand(std::unique_ptr<Element> &element) { FormatParser::parseTypeDirectiveOperand(std::unique_ptr<Element> &element) {
llvm::SMLoc loc = curToken.getLoc(); llvm::SMLoc loc = curToken.getLoc();
if (failed(parseElement(element, /*isTopLevel=*/false))) if (failed(parseElement(element, /*isTopLevel=*/false)))
return failure(); return ::mlir::failure();
if (isa<LiteralElement>(element.get())) if (isa<LiteralElement>(element.get()))
return emitError( return emitError(
loc, "'type' directive operand expects variable or directive operand"); loc, "'type' directive operand expects variable or directive operand");
@ -2765,7 +2769,7 @@ FormatParser::parseTypeDirectiveOperand(std::unique_ptr<Element> &element) {
} else { } else {
return emitError(loc, "invalid argument to 'type' directive"); return emitError(loc, "invalid argument to 'type' directive");
} }
return success(); return ::mlir::success();
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -887,8 +887,9 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex,
// special cases listed below, DRR needs to supply types for all results // special cases listed below, DRR needs to supply types for all results
// when building an op. // when building an op.
bool isSameOperandsAndResultType = bool isSameOperandsAndResultType =
resultOp.getTrait("OpTrait::SameOperandsAndResultType"); resultOp.getTrait("::mlir::OpTrait::SameOperandsAndResultType");
bool useFirstAttr = resultOp.getTrait("OpTrait::FirstAttrDerivedResultType"); bool useFirstAttr =
resultOp.getTrait("::mlir::OpTrait::FirstAttrDerivedResultType");
if (isSameOperandsAndResultType || useFirstAttr) { if (isSameOperandsAndResultType || useFirstAttr) {
// We know how to deduce the result type for ops with these traits and we've // We know how to deduce the result type for ops with these traits and we've