diff --git a/mlir/examples/toy/Ch2/include/toy/Dialect.h b/mlir/examples/toy/Ch2/include/toy/Dialect.h --- a/mlir/examples/toy/Ch2/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch2/include/toy/Dialect.h @@ -34,12 +34,12 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + /// Include the auto-generated header file containing the declarations of the /// toy operations. #define GET_OP_CLASSES #include "toy/Ops.h.inc" -} // end namespace toy -} // end namespace mlir - #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ diff --git a/mlir/examples/toy/Ch2/include/toy/Ops.td b/mlir/examples/toy/Ch2/include/toy/Ops.td --- a/mlir/examples/toy/Ch2/include/toy/Ops.td +++ b/mlir/examples/toy/Ch2/include/toy/Ops.td @@ -20,7 +20,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/examples/toy/Ch3/include/toy/Dialect.h b/mlir/examples/toy/Ch3/include/toy/Dialect.h --- a/mlir/examples/toy/Ch3/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch3/include/toy/Dialect.h @@ -34,12 +34,12 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + /// Include the auto-generated header file containing the declarations of the /// toy operations. #define GET_OP_CLASSES #include "toy/Ops.h.inc" -} // end namespace toy -} // end namespace mlir - #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ diff --git a/mlir/examples/toy/Ch3/include/toy/Ops.td b/mlir/examples/toy/Ch3/include/toy/Ops.td --- a/mlir/examples/toy/Ch3/include/toy/Ops.td +++ b/mlir/examples/toy/Ch3/include/toy/Ops.td @@ -19,7 +19,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/examples/toy/Ch4/include/toy/Dialect.h b/mlir/examples/toy/Ch4/include/toy/Dialect.h --- a/mlir/examples/toy/Ch4/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch4/include/toy/Dialect.h @@ -36,12 +36,12 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + /// Include the auto-generated header file containing the declarations of the /// toy operations. #define GET_OP_CLASSES #include "toy/Ops.h.inc" -} // end namespace toy -} // end namespace mlir - #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ diff --git a/mlir/examples/toy/Ch4/include/toy/Ops.td b/mlir/examples/toy/Ch4/include/toy/Ops.td --- a/mlir/examples/toy/Ch4/include/toy/Ops.td +++ b/mlir/examples/toy/Ch4/include/toy/Ops.td @@ -21,7 +21,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/examples/toy/Ch5/include/toy/Dialect.h b/mlir/examples/toy/Ch5/include/toy/Dialect.h --- a/mlir/examples/toy/Ch5/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch5/include/toy/Dialect.h @@ -36,12 +36,12 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + /// Include the auto-generated header file containing the declarations of the /// toy operations. #define GET_OP_CLASSES #include "toy/Ops.h.inc" -} // end namespace toy -} // end namespace mlir - #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ diff --git a/mlir/examples/toy/Ch5/include/toy/Ops.td b/mlir/examples/toy/Ch5/include/toy/Ops.td --- a/mlir/examples/toy/Ch5/include/toy/Ops.td +++ b/mlir/examples/toy/Ch5/include/toy/Ops.td @@ -21,7 +21,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/examples/toy/Ch6/include/toy/Dialect.h b/mlir/examples/toy/Ch6/include/toy/Dialect.h --- a/mlir/examples/toy/Ch6/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch6/include/toy/Dialect.h @@ -36,12 +36,12 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + /// Include the auto-generated header file containing the declarations of the /// toy operations. #define GET_OP_CLASSES #include "toy/Ops.h.inc" -} // end namespace toy -} // end namespace mlir - #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ diff --git a/mlir/examples/toy/Ch6/include/toy/Ops.td b/mlir/examples/toy/Ch6/include/toy/Ops.td --- a/mlir/examples/toy/Ch6/include/toy/Ops.td +++ b/mlir/examples/toy/Ch6/include/toy/Ops.td @@ -21,7 +21,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/examples/toy/Ch7/include/toy/Dialect.h b/mlir/examples/toy/Ch7/include/toy/Dialect.h --- a/mlir/examples/toy/Ch7/include/toy/Dialect.h +++ b/mlir/examples/toy/Ch7/include/toy/Dialect.h @@ -50,6 +50,9 @@ static llvm::StringRef getDialectNamespace() { return "toy"; } }; +} // end namespace toy +} // end namespace mlir + //===----------------------------------------------------------------------===// // Toy Operations //===----------------------------------------------------------------------===// @@ -59,6 +62,9 @@ #define GET_OP_CLASSES #include "toy/Ops.h.inc" +namespace mlir { +namespace toy { + //===----------------------------------------------------------------------===// // Toy Types //===----------------------------------------------------------------------===// diff --git a/mlir/examples/toy/Ch7/include/toy/Ops.td b/mlir/examples/toy/Ch7/include/toy/Ops.td --- a/mlir/examples/toy/Ch7/include/toy/Ops.td +++ b/mlir/examples/toy/Ch7/include/toy/Ops.td @@ -21,7 +21,7 @@ // can define our operations. def Toy_Dialect : Dialect { let name = "toy"; - let cppNamespace = "toy"; + let cppNamespace = "::mlir::toy"; } // Base class for toy dialect operations. This operation inherits from the base diff --git a/mlir/include/mlir/Dialect/AVX512/AVX512.td b/mlir/include/mlir/Dialect/AVX512/AVX512.td --- a/mlir/include/mlir/Dialect/AVX512/AVX512.td +++ b/mlir/include/mlir/Dialect/AVX512/AVX512.td @@ -21,7 +21,7 @@ def AVX512_Dialect : Dialect { let name = "avx512"; - let cppNamespace = "avx512"; + let cppNamespace = "::mlir::avx512"; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/AVX512/AVX512Dialect.h b/mlir/include/mlir/Dialect/AVX512/AVX512Dialect.h --- a/mlir/include/mlir/Dialect/AVX512/AVX512Dialect.h +++ b/mlir/include/mlir/Dialect/AVX512/AVX512Dialect.h @@ -17,15 +17,9 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -namespace mlir { -namespace avx512 { +#include "mlir/Dialect/AVX512/AVX512Dialect.h.inc" #define GET_OP_CLASSES #include "mlir/Dialect/AVX512/AVX512.h.inc" -#include "mlir/Dialect/AVX512/AVX512Dialect.h.inc" - -} // namespace avx512 -} // namespace mlir - #endif // MLIR_DIALECT_AVX512_AVX512DIALECT_H_ diff --git a/mlir/include/mlir/Dialect/GPU/GPUBase.td b/mlir/include/mlir/Dialect/GPU/GPUBase.td --- a/mlir/include/mlir/Dialect/GPU/GPUBase.td +++ b/mlir/include/mlir/Dialect/GPU/GPUBase.td @@ -21,6 +21,7 @@ def GPU_Dialect : Dialect { let name = "gpu"; + let cppNamespace = "::mlir::gpu"; let hasOperationAttrVerify = 1; let extraClassDeclaration = [{ diff --git a/mlir/include/mlir/Dialect/GPU/GPUDialect.h b/mlir/include/mlir/Dialect/GPU/GPUDialect.h --- a/mlir/include/mlir/Dialect/GPU/GPUDialect.h +++ b/mlir/include/mlir/Dialect/GPU/GPUDialect.h @@ -34,12 +34,13 @@ Value z; }; +} // end namespace gpu +} // end namespace mlir + #include "mlir/Dialect/GPU/GPUOpsDialect.h.inc" #define GET_OP_CLASSES #include "mlir/Dialect/GPU/GPUOps.h.inc" -} // end namespace gpu -} // end namespace mlir #endif // MLIR_DIALECT_GPU_GPUDIALECT_H diff --git a/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h b/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h --- a/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h +++ b/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h @@ -27,8 +27,11 @@ class Operation; class Region; +} // namespace mlir + #include "mlir/Dialect/GPU/ParallelLoopMapperAttr.h.inc" +namespace mlir { namespace scf { class ParallelOp; } diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td @@ -21,7 +21,7 @@ def LLVMAVX512_Dialect : Dialect { let name = "llvm_avx512"; - let cppNamespace = "LLVM"; + let cppNamespace = "::mlir::LLVM"; } //----------------------------------------------------------------------------// diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h @@ -16,15 +16,9 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" -namespace mlir { -namespace LLVM { - #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/LLVMAVX512.h.inc" #include "mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h.inc" -} // namespace LLVM -} // namespace mlir - #endif // MLIR_DIALECT_LLVMIR_LLVMAVX512DIALECT_H_ diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h @@ -49,18 +49,23 @@ struct LLVMDialectImpl; } // namespace detail +} // namespace LLVM +} // namespace mlir + ///// Ops ///// #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/LLVMOps.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 /// 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 /// string (operations inserted at the builder insertion point). 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 /// function confirms that the Operation has the desired properties. diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -23,7 +23,7 @@ def LLVM_Dialect : Dialect { let name = "llvm"; - let cppNamespace = "LLVM"; + let cppNamespace = "::mlir::LLVM"; /// FIXME: at the moment this is a dependency of the translation to LLVM IR, /// not really one of this dialect per-se. diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -59,7 +59,7 @@ "OpBuilder &builder, OperationState &result, Type resultType, " "ValueRange operands, ArrayRef attributes = {}", [{ - auto llvmType = resultType.dyn_cast(); (void)llvmType; + auto llvmType = resultType.dyn_cast(); (void)llvmType; assert(llvmType && "result must be an LLVM type"); assert(llvmType.isVoidTy() && "for zero-result operands, only 'void' is accepted as result type"); @@ -301,7 +301,7 @@ "unsigned alignment = 0, bool isVolatile = false, " "bool isNonTemporal = false", [{ - auto type = addr.getType().cast().getPointerElementTy(); + auto type = addr.getType().cast().getPointerElementTy(); build(b, result, type, addr, alignment, isVolatile, isNonTemporal); }]>, OpBuilder< @@ -494,8 +494,8 @@ "OpBuilder &b, OperationState &result, Value v1, Value v2, " "ArrayAttr mask, ArrayRef attrs = {}">]; let verifier = [{ - auto wrappedVectorType1 = v1().getType().cast(); - auto wrappedVectorType2 = v2().getType().cast(); + auto wrappedVectorType1 = v1().getType().cast(); + auto wrappedVectorType2 = v2().getType().cast(); if (!wrappedVectorType2.isVectorTy()) return emitOpError("expected LLVM IR Dialect vector type for operand #2"); if (wrappedVectorType1.getVectorElementType() != @@ -770,7 +770,7 @@ let builders = [ OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, " - "LLVMType type, LLVM::Linkage linkage = LLVM::Linkage::External, " + "LLVMType type, Linkage linkage = Linkage::External, " "ArrayRef attrs = {}, " "ArrayRef argAttrs = {}"> ]; diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h --- a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h @@ -19,16 +19,10 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -namespace mlir { -namespace NVVM { - ///// Ops ///// #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/NVVMOps.h.inc" #include "mlir/Dialect/LLVMIR/NVVMOpsDialect.h.inc" -} // namespace NVVM -} // namespace mlir - #endif /* MLIR_DIALECT_LLVMIR_NVVMDIALECT_H_ */ diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td @@ -22,7 +22,7 @@ def NVVM_Dialect : Dialect { let name = "nvvm"; - let cppNamespace = "NVVM"; + let cppNamespace = "::mlir::NVVM"; let dependentDialects = ["LLVM::LLVMDialect"]; } diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h --- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h @@ -27,16 +27,10 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -namespace mlir { -namespace ROCDL { - ///// Ops ///// #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/ROCDLOps.h.inc" #include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.h.inc" -} // namespace ROCDL -} // namespace mlir - #endif /* MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ */ diff --git a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td @@ -22,7 +22,7 @@ def ROCDL_Dialect : Dialect { let name = "rocdl"; - let cppNamespace = "ROCDL"; + let cppNamespace = "::mlir::ROCDL"; let dependentDialects = ["LLVM::LLVMDialect"]; } diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td @@ -31,6 +31,7 @@ are also available and should be read first before going in the details of the op semantics. }]; + let cppNamespace = "::mlir::linalg"; } // Whether a type is a RangeType. diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h @@ -85,6 +85,9 @@ SmallVector concat(ArrayRef a, ArrayRef b); +} // namespace linalg +} // namespace mlir + #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.h.inc" #define GET_OP_CLASSES @@ -93,7 +96,5 @@ #define GET_OP_CLASSES #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc" -} // namespace linalg -} // namespace mlir #endif // MLIR_DIALECT_LINALG_LINALGOPS_H_ diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td @@ -18,6 +18,7 @@ // The linalg 'LinalgStructuredInterface' provides access to the 'LinalgOp' // interface. def LinalgStructuredInterface : OpInterface<"LinalgOp"> { + let cppNamespace = "::mlir::linalg"; let methods = [ //===------------------------------------------------------------------===// // Loop types handling. diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h @@ -12,11 +12,12 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/Types.h" +#include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc" + namespace mlir { class MLIRContext; namespace linalg { -#include "mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc" /// A RangeType represents a minimal range abstraction (min, max, step). /// It is constructed by calling the linalg.range op with three values index of diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h --- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h @@ -16,15 +16,14 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc" #include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc" -namespace mlir { -namespace acc { - #define GET_OP_CLASSES #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. /// They refer directly to the OpenACC 3.0 standard: diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td --- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td @@ -24,7 +24,7 @@ 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. diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h @@ -16,16 +16,10 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc" #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc" -namespace mlir { -namespace omp { - #define GET_OP_CLASSES #include "mlir/Dialect/OpenMP/OpenMPOps.h.inc" -#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc" -} // namespace omp -} // namespace mlir - #endif // MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -19,7 +19,7 @@ def OpenMP_Dialect : Dialect { let name = "omp"; - let cppNamespace = "omp"; + let cppNamespace = "::mlir::omp"; } class OpenMP_Op traits = []> : diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDL.h b/mlir/include/mlir/Dialect/PDL/IR/PDL.h --- a/mlir/include/mlir/Dialect/PDL/IR/PDL.h +++ b/mlir/include/mlir/Dialect/PDL/IR/PDL.h @@ -19,8 +19,6 @@ #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -namespace mlir { -namespace pdl { //===----------------------------------------------------------------------===// // PDL Dialect //===----------------------------------------------------------------------===// @@ -34,7 +32,5 @@ #define GET_OP_CLASSES #include "mlir/Dialect/PDL/IR/PDLOps.h.inc" -} // end namespace pdl -} // end namespace mlir #endif // MLIR_DIALECT_PDL_IR_PDL_H_ diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td b/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td --- a/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td +++ b/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td @@ -63,7 +63,7 @@ }]; let name = "pdl"; - let cppNamespace = "mlir::pdl"; + let cppNamespace = "::mlir::pdl"; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h @@ -18,8 +18,6 @@ #include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -namespace mlir { -namespace pdl_interp { //===----------------------------------------------------------------------===// // PDLInterp Dialect //===----------------------------------------------------------------------===// @@ -33,7 +31,4 @@ #define GET_OP_CLASSES #include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.h.inc" -} // end namespace pdl_interp -} // end namespace mlir - #endif // MLIR_DIALECT_PDLINTERP_IR_PDLINTERP_H_ diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td @@ -34,7 +34,7 @@ }]; let name = "pdl_interp"; - let cppNamespace = "mlir::pdl_interp"; + let cppNamespace = "::mlir::pdl_interp"; let dependentDialects = ["pdl::PDLDialect"]; } diff --git a/mlir/include/mlir/Dialect/Quant/QuantOps.h b/mlir/include/mlir/Dialect/Quant/QuantOps.h --- a/mlir/include/mlir/Dialect/Quant/QuantOps.h +++ b/mlir/include/mlir/Dialect/Quant/QuantOps.h @@ -18,15 +18,9 @@ #include "mlir/Interfaces/SideEffectInterfaces.h" #include "llvm/Support/MathExtras.h" -namespace mlir { -namespace quant { - #include "mlir/Dialect/Quant/QuantOpsDialect.h.inc" #define GET_OP_CLASSES #include "mlir/Dialect/Quant/QuantOps.h.inc" -} // namespace quant -} // namespace mlir - #endif // MLIR_DIALECT_QUANT_QUANTOPS_H_ diff --git a/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td b/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td --- a/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td +++ b/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td @@ -17,6 +17,7 @@ def Quantization_Dialect : Dialect { let name = "quant"; + let cppNamespace = "::mlir::quant"; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/SCF/SCF.h b/mlir/include/mlir/Dialect/SCF/SCF.h --- a/mlir/include/mlir/Dialect/SCF/SCF.h +++ b/mlir/include/mlir/Dialect/SCF/SCF.h @@ -23,14 +23,18 @@ namespace mlir { namespace scf { - void buildTerminatedBody(OpBuilder &builder, Location loc); +} // namespace scf +} // namespace mlir #include "mlir/Dialect/SCF/SCFOpsDialect.h.inc" #define GET_OP_CLASSES #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 // 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 diff --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td --- a/mlir/include/mlir/Dialect/SCF/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td @@ -19,7 +19,7 @@ def SCF_Dialect : Dialect { let name = "scf"; - let cppNamespace = "scf"; + let cppNamespace = "::mlir::scf"; } // Base class for SCF dialect ops. diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h @@ -17,10 +17,10 @@ #include "mlir/IR/Attributes.h" #include "mlir/Support/LLVM.h" -namespace mlir { // Pull in SPIR-V attribute definitions for target and ABI. #include "mlir/Dialect/SPIRV/TargetAndABI.h.inc" +namespace mlir { namespace spirv { enum class Capability : uint32_t; enum class Extension; diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td b/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td @@ -45,7 +45,7 @@ high-level designs and implementation structures of the SPIR-V dialect. }]; - let cppNamespace = "spirv"; + let cppNamespace = "::mlir::spirv"; let hasConstantMaterializer = 1; let hasOperationAttrVerify = 1; let hasRegionArgAttrVerify = 1; @@ -226,21 +226,24 @@ let instance = "ref"; } +class SPIRVOpInterface : OpInterface { + let cppNamespace = "::mlir::spirv"; +} // TODO: the following interfaces definitions are duplicating with the above. // 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">]; } -def QueryMaxVersionInterface : OpInterface<"QueryMaxVersionInterface"> { +def QueryMaxVersionInterface : SPIRVOpInterface<"QueryMaxVersionInterface"> { let methods = [InterfaceMethod<"", "::mlir::spirv::Version", "getMaxVersion">]; } -def QueryExtensionInterface : OpInterface<"QueryExtensionInterface"> { +def QueryExtensionInterface : SPIRVOpInterface<"QueryExtensionInterface"> { let methods = [InterfaceMethod< "", "::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Extension>, 1>", "getExtensions">]; } -def QueryCapabilityInterface : OpInterface<"QueryCapabilityInterface"> { +def QueryCapabilityInterface : SPIRVOpInterface<"QueryCapabilityInterface"> { let methods = [InterfaceMethod< "", "::llvm::SmallVector<::llvm::ArrayRef<::mlir::spirv::Capability>, 1>", diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h @@ -20,9 +20,9 @@ enum class Decoration : uint32_t; -#include "mlir/Dialect/SPIRV/SPIRVOpsDialect.h.inc" - } // end namespace spirv } // end namespace mlir +#include "mlir/Dialect/SPIRV/SPIRVOpsDialect.h.inc" + #endif // MLIR_DIALECT_SPIRV_SPIRVDIALECT_H_ diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h @@ -28,11 +28,15 @@ // TableGen'erated operation interfaces for querying versions, extensions, and // capabilities. #include "mlir/Dialect/SPIRV/SPIRVAvailability.h.inc" +} // namespace spirv +} // namespace mlir // TablenGen'erated operation declarations. #define GET_OP_CLASSES #include "mlir/Dialect/SPIRV/SPIRVOps.h.inc" +namespace mlir { +namespace spirv { // TableGen'erated helper functions. // // Get the name used in the Op to refer to an enum value of the given diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h @@ -77,25 +77,25 @@ /// The extension requirements for each type are following the /// ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D)) /// convention. - using ExtensionArrayRefVector = SmallVectorImpl>; + using ExtensionArrayRefVector = SmallVectorImpl>; /// Appends to `extensions` the extensions needed for this type to appear in /// the given `storage` class. This method does not guarantee the uniqueness /// of extensions; the same extension may be appended multiple times. void getExtensions(ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); /// The capability requirements for each type are following the /// ((Capability::A OR Extension::B) AND (Capability::C OR Capability::D)) /// convention. - using CapabilityArrayRefVector = SmallVectorImpl>; + using CapabilityArrayRefVector = SmallVectorImpl>; /// Appends to `capabilities` the capabilities needed for this type to appear /// in the given `storage` class. This method does not guarantee the /// uniqueness of capabilities; the same capability may be appended multiple /// times. void getCapabilities(CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); /// 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 @@ -116,9 +116,9 @@ static bool isValid(IntegerType); void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); Optional getSizeInBytes(); }; @@ -144,9 +144,9 @@ bool hasCompileTimeKnownNumElements() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); Optional getSizeInBytes(); }; @@ -172,9 +172,9 @@ unsigned getArrayStride() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); /// Returns the array size in bytes. Since array type may have an explicit /// stride declaration (in bytes), we also include it in the calculation. @@ -215,9 +215,9 @@ // TODO: Add support for Access qualifier void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; // SPIR-V pointer type @@ -233,9 +233,9 @@ StorageClass getStorageClass() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; // SPIR-V run-time array type @@ -257,9 +257,9 @@ unsigned getArrayStride() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; // SPIR-V struct type @@ -335,21 +335,21 @@ uint64_t getMemberOffset(unsigned) const; - // Returns in `memberDecorations` the spirv::Decorations (apart from - // Offset) associated with all members of the StructType. + // Returns in `memberDecorations` the Decorations (apart from Offset) + // associated with all members of the StructType. void getMemberDecorations(SmallVectorImpl &memberDecorations) const; - // Returns in `decorationsInfo` all the spirv::Decorations (apart from - // Offset) associated with the `i`-th member of the StructType. + // Returns in `decorationsInfo` all the Decorations (apart from Offset) + // associated with the `i`-th member of the StructType. void getMemberDecorations(unsigned i, SmallVectorImpl &decorationsInfo) const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; llvm::hash_code @@ -362,21 +362,21 @@ public: using Base::Base; - static CooperativeMatrixNVType get(Type elementType, spirv::Scope scope, + static CooperativeMatrixNVType get(Type elementType, Scope scope, unsigned rows, unsigned columns); Type getElementType() const; /// Return the scope of the cooperative matrix. - spirv::Scope getScope() const; + Scope getScope() const; /// return the number of rows of the matrix. unsigned getRows() const; /// return the number of columns of the matrix. unsigned getColumns() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; // SPIR-V matrix type @@ -412,9 +412,9 @@ Type getElementType() const; void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions, - Optional storage = llvm::None); + Optional storage = llvm::None); void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities, - Optional storage = llvm::None); + Optional storage = llvm::None); }; } // end namespace spirv diff --git a/mlir/include/mlir/Dialect/Shape/IR/Shape.h b/mlir/include/mlir/Dialect/Shape/IR/Shape.h --- a/mlir/include/mlir/Dialect/Shape/IR/Shape.h +++ b/mlir/include/mlir/Dialect/Shape/IR/Shape.h @@ -67,12 +67,12 @@ using Base::Base; }; +} // namespace shape +} // namespace mlir + #define GET_OP_CLASSES #include "mlir/Dialect/Shape/IR/ShapeOps.h.inc" #include "mlir/Dialect/Shape/IR/ShapeOpsDialect.h.inc" -} // namespace shape -} // namespace mlir - #endif // MLIR_SHAPE_IR_SHAPE_H diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td @@ -36,7 +36,7 @@ concatting etc. on how to combine them). }]; - let cppNamespace = "shape"; + let cppNamespace = "::mlir::shape"; let hasConstantMaterializer = 1; } diff --git a/mlir/include/mlir/Dialect/Vector/VectorOps.h b/mlir/include/mlir/Dialect/Vector/VectorOps.h --- a/mlir/include/mlir/Dialect/Vector/VectorOps.h +++ b/mlir/include/mlir/Dialect/Vector/VectorOps.h @@ -128,13 +128,11 @@ AffineMap getTransferMinorIdentityMap(MemRefType memRefType, VectorType vectorType); } // namespace impl +} // end namespace vector +} // end namespace mlir #define GET_OP_CLASSES #include "mlir/Dialect/Vector/VectorOps.h.inc" - #include "mlir/Dialect/Vector/VectorOpsDialect.h.inc" -} // end namespace vector -} // end namespace mlir - #endif // MLIR_DIALECT_VECTOR_VECTOROPS_H diff --git a/mlir/include/mlir/Dialect/Vector/VectorOps.td b/mlir/include/mlir/Dialect/Vector/VectorOps.td --- a/mlir/include/mlir/Dialect/Vector/VectorOps.td +++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td @@ -19,7 +19,7 @@ def Vector_Dialect : Dialect { let name = "vector"; - let cppNamespace = "vector"; + let cppNamespace = "::mlir::vector"; let hasConstantMaterializer = 1; } diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1672,7 +1672,7 @@ // purpose to wrap around C++ symbol string with this class is to make // traits specified for ops in TableGen less alien and more integrated. class NativeOpTrait : OpTrait { - string trait = "OpTrait::" # prop; + string trait = "::mlir::OpTrait::" # prop; } // ParamNativeOpTrait corresponds to the template-parameterized traits in the @@ -1687,7 +1687,7 @@ // affects op definition generator internals, like how op builders and // operand/attribute/result getters are generated. class GenInternalOpTrait : OpTrait { - string trait = "OpTrait::" # prop; + string trait = "::mlir::OpTrait::" # prop; } // PredOpTrait is an op trait implemented by way of a predicate on the op. diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h --- a/mlir/include/mlir/TableGen/Operator.h +++ b/mlir/include/mlir/TableGen/Operator.h @@ -242,6 +242,17 @@ // debugging purposes. 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 namespaces; + }; + // Return whether all the result types are known. bool allResultTypesKnown() const { return allResultsHaveKnownTypes; }; diff --git a/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp b/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp --- a/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp +++ b/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp @@ -25,10 +25,5 @@ >(); } -namespace mlir { -namespace avx512 { #define GET_OP_CLASSES #include "mlir/Dialect/AVX512/AVX512.cpp.inc" -} // namespace avx512 -} // namespace mlir - diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -777,10 +777,5 @@ /*printBlockTerminators=*/false); } -// Namespace avoids ambiguous ReturnOpAdaptor. -namespace mlir { -namespace gpu { #define GET_OP_CLASSES #include "mlir/Dialect/GPU/GPUOps.cpp.inc" -} // namespace gpu -} // namespace mlir diff --git a/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp b/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp --- a/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp @@ -24,9 +24,8 @@ using namespace mlir::scf; #include "mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc" -namespace mlir { - #include "mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc" +namespace mlir { namespace gpu { StringRef getMappingAttrName() { return "mapping"; } diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp @@ -27,9 +27,5 @@ >(); } -namespace mlir { -namespace LLVM { #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/LLVMAVX512.cpp.inc" -} // namespace LLVM -} // namespace mlir diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -16,7 +16,6 @@ #include "mlir/Dialect/LLVMIR/NVVMDialect.h" -#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Builders.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Operation.h" @@ -146,10 +145,5 @@ allowUnknownOperations(); } -namespace mlir { -namespace NVVM { #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/NVVMOps.cpp.inc" -} // namespace NVVM -} // namespace mlir - diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp @@ -91,10 +91,5 @@ allowUnknownOperations(); } -namespace mlir { -namespace ROCDL { #define GET_OP_CLASSES #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" -} // namespace ROCDL -} // namespace mlir - diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -1096,9 +1096,6 @@ return verifySingleInputPoolingOp(op); } -namespace mlir { -namespace linalg { - #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" #define GET_OP_CLASSES @@ -1107,9 +1104,6 @@ #define GET_OP_CLASSES #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" -} // namespace linalg -} // namespace mlir - AffineMap mlir::linalg::extractOrIdentityMap(Optional maybeMap, unsigned rank, MLIRContext *context) { diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -271,9 +271,5 @@ return success(); } -namespace mlir { -namespace omp { #define GET_OP_CLASSES #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" -} // namespace omp -} // namespace mlir diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp --- a/mlir/lib/Dialect/PDL/IR/PDL.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp @@ -454,11 +454,5 @@ // TableGen'd op method definitions //===----------------------------------------------------------------------===// -namespace mlir { -namespace pdl { - #define GET_OP_CLASSES #include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc" - -} // end namespace pdl -} // end namespace mlir diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp --- a/mlir/lib/Dialect/SCF/SCF.cpp +++ b/mlir/lib/Dialect/SCF/SCF.cpp @@ -899,9 +899,5 @@ // TableGen'd op method definitions //===----------------------------------------------------------------------===// -namespace mlir { -namespace scf { #define GET_OP_CLASSES #include "mlir/Dialect/SCF/SCFOps.cpp.inc" -} // namespace scf -} // namespace mlir diff --git a/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp b/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp @@ -16,9 +16,10 @@ // DictionaryDict derived attributes //===----------------------------------------------------------------------===// -namespace mlir { #include "mlir/Dialect/SPIRV/TargetAndABI.cpp.inc" +namespace mlir { + //===----------------------------------------------------------------------===// // Attribute storage classes //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp @@ -3266,11 +3266,15 @@ // TableGen'erated operation interfaces for querying versions, extensions, and // capabilities. #include "mlir/Dialect/SPIRV/SPIRVAvailability.cpp.inc" +} // namespace spirv +} // namespace mlir // TablenGen'erated operation definitions. #define GET_OP_CLASSES #include "mlir/Dialect/SPIRV/SPIRVOps.cpp.inc" +namespace mlir { +namespace spirv { // TableGen'erated operation availability interface implementations. #include "mlir/Dialect/SPIRV/SPIRVOpAvailabilityImpl.inc" diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -938,11 +938,5 @@ p.printOptionalAttrDict(op.getAttrs()); } -namespace mlir { -namespace shape { - #define GET_OP_CLASSES #include "mlir/Dialect/Shape/IR/ShapeOps.cpp.inc" - -} // namespace shape -} // namespace mlir diff --git a/mlir/lib/Dialect/Vector/VectorOps.cpp b/mlir/lib/Dialect/Vector/VectorOps.cpp --- a/mlir/lib/Dialect/Vector/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/VectorOps.cpp @@ -2688,11 +2688,5 @@ TransposeFolder>(context); } -namespace mlir { -namespace vector { - #define GET_OP_CLASSES #include "mlir/Dialect/Vector/VectorOps.cpp.inc" - -} // namespace vector -} // namespace mlir diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -278,7 +279,7 @@ // Skip cases currently being custom generated. // TODO: Remove special cases. - if (getTrait("OpTrait::SameOperandsAndResultType")) + if (getTrait("::mlir::OpTrait::SameOperandsAndResultType")) return; // We create equivalence classes of argument/result types where arguments @@ -565,6 +566,20 @@ } } +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) -> VariableDecorator { return VariableDecorator(cast(init)->getDef()); diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h --- a/mlir/test/lib/Dialect/Test/TestDialect.h +++ b/mlir/test/lib/Dialect/Test/TestDialect.h @@ -29,7 +29,6 @@ #include "TestOpEnums.h.inc" -namespace mlir { #include "TestOpStructs.h.inc" #include "TestOpsDialect.h.inc" @@ -37,8 +36,8 @@ #define GET_OP_CLASSES #include "TestOps.h.inc" +namespace mlir { void registerTestDialect(DialectRegistry ®istry); - } // end namespace mlir #endif // MLIR_TESTDIALECT_H diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -22,7 +22,7 @@ def Test_Dialect : Dialect { let name = "test"; - let cppNamespace = ""; + let cppNamespace = "::mlir"; let hasOperationAttrVerify = 1; let hasRegionArgAttrVerify = 1; let hasRegionResultAttrVerify = 1; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -275,3 +275,19 @@ // RECORD-LABEL: def SomeTypedArrayAttr // 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(); diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -61,8 +61,8 @@ // CHECK: ::mlir::ValueRange odsOperands; // CHECK: }; -// CHECK: class AOp : public ::mlir::Op::Impl, OpTrait::AtLeastNResults<1>::Impl, OpTrait::ZeroSuccessor, OpTrait::AtLeastNOperands<1>::Impl, OpTrait::IsIsolatedFromAbove -// CHECK-NOT: OpTrait::IsIsolatedFromAbove +// CHECK: class AOp : public ::mlir::Op::Impl, ::mlir::OpTrait::AtLeastNResults<1>::Impl, ::mlir::OpTrait::ZeroSuccessor, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::IsIsolatedFromAbove +// CHECK-NOT: ::mlir::OpTrait::IsIsolatedFromAbove // CHECK: public: // CHECK: using Op::Op; // CHECK: using Adaptor = AOpAdaptor; diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -153,6 +153,15 @@ dialectsOs << llvm::formatv(dialectRegistrationTemplate, dependentDialect); } + + // Emit all nested namespaces. + StringRef cppNamespace = dialect.getCppNamespace(); + llvm::SmallVector namespaces; + llvm::SplitString(cppNamespace, namespaces, "::"); + + for (auto ns : namespaces) + os << "namespace " << ns << " {\n"; + // Emit the start of the decl. std::string cppName = dialect.getCppClassName(); os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName(), @@ -179,6 +188,10 @@ // End the dialect decl. 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, diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -494,6 +494,7 @@ FmtContext fctx; fctx.withBuilder("::mlir::Builder(this->getContext())"); + Dialect opDialect = op.getDialect(); // Emit the derived attribute body. auto emitDerivedAttr = [&](StringRef name, Attribute attr) { auto &method = opClass.newMethod(attr.getReturnType(), name); @@ -503,7 +504,16 @@ // Emit with return type specified. 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(); body << " auto attr = " << name << "Attr();\n"; if (attr.hasDefaultValue()) { @@ -684,9 +694,9 @@ const int numNormalOperands = numOperands - numVariadicOperands; const auto *sameVariadicSize = - op.getTrait("OpTrait::SameVariadicOperandSize"); + op.getTrait("::mlir::OpTrait::SameVariadicOperandSize"); const auto *attrSizedOperands = - op.getTrait("OpTrait::AttrSizedOperandSegments"); + op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"); if (numVariadicOperands > 1 && !sameVariadicSize && !attrSizedOperands) { PrintFatalError(op.getLoc(), "op has multiple variadic operands but no " @@ -748,7 +758,8 @@ } 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) { const auto &operand = op.getOperand(i); if (operand.name.empty()) @@ -775,9 +786,10 @@ // If we have more than one variadic results, we need more complicated logic // 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 = - op.getTrait("OpTrait::AttrSizedResultSegments"); + op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"); if (numVariadicResults > 1 && !sameVariadicSize && !attrSizedResults) { PrintFatalError(op.getLoc(), "op has multiple variadic results but no " @@ -1213,7 +1225,7 @@ // use the first operand or attribute's type as all result types // to facilitate different call patterns. 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 // generated by `genUseOperandAsResultTypeSeparateParamBuilder` will be // ambiguous with the one generated by @@ -1230,7 +1242,7 @@ if (!shouldGenerateInferredTypeCollectiveParamBuilder()) genUseOperandAsResultTypeCollectiveParamBuilder(); } - if (op.getTrait("OpTrait::FirstAttrDerivedResultType")) + if (op.getTrait("::mlir::OpTrait::FirstAttrDerivedResultType")) genUseAttrAsResultTypeBuilder(); } } @@ -1435,7 +1447,7 @@ } // 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 << ".addAttribute(\"operand_segment_sizes\", " "odsBuilder.getI32VectorAttr({"; @@ -1695,7 +1707,7 @@ continue; // TODO: We could verify equality here, but skipping that for verification. } - os << " return success();"; + os << " return ::mlir::success();"; } void OpEmitter::genParser() { @@ -1735,7 +1747,7 @@ auto &body = method.body(); body << " if (failed(" << op.getAdaptorName() << "(*this).verify(this->getLoc()))) " - << "return failure();\n"; + << "return ::mlir::failure();\n"; auto *valueInit = def.getValueInit("verifier"); CodeInit *codeInit = dyn_cast(valueInit); @@ -1904,21 +1916,21 @@ int numTotal, int numVariadic) { if (numVariadic != 0) { if (numTotal == numVariadic) - opClass.addTrait("OpTrait::Variadic" + traitKind + "s"); + opClass.addTrait("::mlir::OpTrait::Variadic" + traitKind + "s"); else - opClass.addTrait("OpTrait::AtLeastN" + traitKind + "s<" + + opClass.addTrait("::mlir::OpTrait::AtLeastN" + traitKind + "s<" + Twine(numTotal - numVariadic) + ">::Impl"); return; } switch (numTotal) { case 0: - opClass.addTrait("OpTrait::Zero" + traitKind); + opClass.addTrait("::mlir::OpTrait::Zero" + traitKind); break; case 1: - opClass.addTrait("OpTrait::One" + traitKind); + opClass.addTrait("::mlir::OpTrait::One" + traitKind); break; default: - opClass.addTrait("OpTrait::N" + traitKind + "s<" + Twine(numTotal) + + opClass.addTrait("::mlir::OpTrait::N" + traitKind + "s<" + Twine(numTotal) + ">::Impl"); break; } @@ -1947,20 +1959,20 @@ // Add operand size trait. if (numVariadicOperands != 0) { if (numOperands == numVariadicOperands) - opClass.addTrait("OpTrait::VariadicOperands"); + opClass.addTrait("::mlir::OpTrait::VariadicOperands"); else - opClass.addTrait("OpTrait::AtLeastNOperands<" + + opClass.addTrait("::mlir::OpTrait::AtLeastNOperands<" + Twine(numOperands - numVariadicOperands) + ">::Impl"); } else { switch (numOperands) { case 0: - opClass.addTrait("OpTrait::ZeroOperands"); + opClass.addTrait("::mlir::OpTrait::ZeroOperands"); break; case 1: - opClass.addTrait("OpTrait::OneOperand"); + opClass.addTrait("::mlir::OpTrait::OneOperand"); break; default: - opClass.addTrait("OpTrait::NOperands<" + Twine(numOperands) + ">::Impl"); + opClass.addTrait("::mlir::OpTrait::NOperands<" + Twine(numOperands) + ">::Impl"); break; } } @@ -2042,7 +2054,7 @@ adaptor.newField("::mlir::ValueRange", "odsOperands"); adaptor.newField("::mlir::DictionaryAttr", "odsAttrs"); const auto *attrSizedOperands = - op.getTrait("OpTrait::AttrSizedOperandSegments"); + op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"); { auto &constructor = adaptor.newConstructor( attrSizedOperands @@ -2125,11 +2137,11 @@ // getODSOperands()/getODSResults() in the rest of the verifier. for (auto &trait : op.getTraits()) { if (auto *t = dyn_cast(&trait)) { - if (t->getTrait() == "OpTrait::AttrSizedOperandSegments") { + if (t->getTrait() == "::mlir::OpTrait::AttrSizedOperandSegments") { body << formatv(checkAttrSizedValueSegmentsCode, "operand_segment_sizes", op.getNumOperands(), "operand"); - } else if (t->getTrait() == "OpTrait::AttrSizedResultSegments") { + } else if (t->getTrait() == "::mlir::OpTrait::AttrSizedResultSegments") { body << formatv(checkAttrSizedValueSegmentsCode, "result_segment_sizes", op.getNumResults(), "result"); } @@ -2144,7 +2156,7 @@ "' op \"", /*emitVerificationRequiringOp*/ false, verifyCtx, body); - body << " return success();"; + body << " return ::mlir::success();"; } void OpOperandAdaptorEmitter::emitDecl(const Operator &op, raw_ostream &os) { @@ -2165,6 +2177,7 @@ os << "#undef GET_OP_FWD_DEFINES\n"; for (auto *def : defs) { Operator op(*def); + Operator::NamespaceEmitter emitter(os, op); os << "class " << op.getCppClassName() << ";\n"; } os << "#endif\n\n"; @@ -2173,6 +2186,7 @@ IfDefScope scope("GET_OP_CLASSES", os); for (auto *def : defs) { Operator op(*def); + Operator::NamespaceEmitter emitter(os, op); if (emitDecl) { os << formatv(opCommentHeader, op.getQualCppClassName(), "declarations"); OpOperandAdaptorEmitter::emitDecl(op, os); diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -439,14 +439,14 @@ /// {1}: The type for the attribute. const char *const attrParserCode = R"( if (parser.parseAttribute({0}Attr{1}, "{0}", result.attributes)) - return failure(); + return ::mlir::failure(); )"; const char *const optionalAttrParserCode = R"( { ::mlir::OptionalParseResult parseResult = parser.parseOptionalAttribute({0}Attr{1}, "{0}", result.attributes); if (parseResult.hasValue() && failed(*parseResult)) - return failure(); + return ::mlir::failure(); } )"; @@ -455,7 +455,7 @@ /// {0}: The name of the attribute. const char *const symbolNameAttrParserCode = R"( if (parser.parseSymbolName({0}Attr, "{0}", result.attributes)) - return failure(); + return ::mlir::failure(); )"; const char *const optionalSymbolNameAttrParserCode = R"( // Parsing an optional symbol name doesn't fail, so no need to check the @@ -476,7 +476,7 @@ auto loc = parser.getCurrentLocation(); if (parser.parseAttribute(attrVal, parser.getBuilder().getNoneType(), "{0}", attrStorage)) - return failure(); + return ::mlir::failure(); auto attrOptional = {1}::{2}(attrVal.getValue()); if (!attrOptional) @@ -498,7 +498,7 @@ "{0}", attrStorage); if (parseResult.hasValue()) { if (failed(*parseResult)) - return failure(); + return ::mlir::failure(); auto attrOptional = {1}::{2}(attrVal.getValue()); if (!attrOptional) @@ -517,7 +517,7 @@ const char *const variadicOperandParserCode = R"( {0}OperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList({0}Operands)) - return failure(); + return ::mlir::failure(); )"; const char *const optionalOperandParserCode = R"( { @@ -527,7 +527,7 @@ parser.parseOptionalOperand(operand); if (parseResult.hasValue()) { if (failed(*parseResult)) - return failure(); + return ::mlir::failure(); {0}Operands.push_back(operand); } } @@ -535,7 +535,7 @@ const char *const operandParserCode = R"( {0}OperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand({0}RawOperands[0])) - return failure(); + return ::mlir::failure(); )"; /// The code snippet used to generate a parser call for a type list. @@ -543,7 +543,7 @@ /// {0}: The name for the type list. const char *const variadicTypeParserCode = R"( if (parser.parseTypeList({0}Types)) - return failure(); + return ::mlir::failure(); )"; const char *const optionalTypeParserCode = R"( { @@ -552,14 +552,14 @@ parser.parseOptionalType(optionalType); if (parseResult.hasValue()) { if (failed(*parseResult)) - return failure(); + return ::mlir::failure(); {0}Types.push_back(optionalType); } } )"; const char *const typeParserCode = R"( if (parser.parseType({0}RawTypes[0])) - return failure(); + return ::mlir::failure(); )"; /// The code snippet used to generate a parser call for a functional type. @@ -569,7 +569,7 @@ const char *const functionalTypeParserCode = R"( ::mlir::FunctionType {0}__{1}_functionType; if (parser.parseType({0}__{1}_functionType)) - return failure(); + return ::mlir::failure(); {0}Types = {0}__{1}_functionType.getInputs(); {1}Types = {0}__{1}_functionType.getResults(); )"; @@ -583,14 +583,14 @@ auto firstRegionResult = parser.parseOptionalRegion(region); if (firstRegionResult.hasValue()) { if (failed(*firstRegionResult)) - return failure(); + return ::mlir::failure(); {0}Regions.emplace_back(std::move(region)); // Parse any trailing regions. while (succeeded(parser.parseOptionalComma())) { region = std::make_unique<::mlir::Region>(); if (parser.parseRegion(*region)) - return failure(); + return ::mlir::failure(); {0}Regions.emplace_back(std::move(region)); } } @@ -610,7 +610,7 @@ /// {0}: The name of the region. const char *optionalRegionParserCode = R"( if (parser.parseOptionalRegion(*{0}Region)) - return failure(); + return ::mlir::failure(); )"; /// The code snippet used to generate a parser call for a region. @@ -618,7 +618,7 @@ /// {0}: The name of the region. const char *regionParserCode = R"( if (parser.parseRegion(*{0}Region)) - return failure(); + return ::mlir::failure(); )"; /// The code snippet used to ensure a region has a terminator. @@ -637,13 +637,13 @@ auto firstSucc = parser.parseOptionalSuccessor(succ); if (firstSucc.hasValue()) { if (failed(*firstSucc)) - return failure(); + return ::mlir::failure(); {0}Successors.emplace_back(succ); // Parse any trailing successors. while (succeeded(parser.parseOptionalComma())) { if (parser.parseSuccessor(succ)) - return failure(); + return ::mlir::failure(); {0}Successors.emplace_back(succ); } } @@ -655,7 +655,7 @@ /// {0}: The name of the successor. const char *successorParserCode = R"( if (parser.parseSuccessor({0}Successor)) - return failure(); + return ::mlir::failure(); )"; namespace { @@ -889,7 +889,7 @@ genCustomParameterParser(param, body); body << "))\n" - << " return failure();\n"; + << " return ::mlir::failure();\n"; // After parsing, add handling for any of the optional constructs. for (Element ¶m : dir->getArguments()) { @@ -949,7 +949,7 @@ genParserSuccessorResolution(op, body); genParserVariadicSegmentResolution(op, body); - body << " return success();\n"; + body << " return ::mlir::success();\n"; } void OperationFormat::genElementParser(Element *element, OpMethodBody &body, @@ -1007,7 +1007,7 @@ } else if (LiteralElement *literal = dyn_cast(element)) { body << " if (parser.parse"; genLiteralParser(literal->getLiteral(), body); - body << ")\n return failure();\n"; + body << ")\n return ::mlir::failure();\n"; /// Arguments. } else if (auto *attr = dyn_cast(element)) { @@ -1081,14 +1081,14 @@ body << " if (parser.parseOptionalAttrDict" << (attrDict->isWithKeyword() ? "WithKeyword" : "") << "(result.attributes))\n" - << " return failure();\n"; + << " return ::mlir::failure();\n"; } else if (auto *customDir = dyn_cast(element)) { genCustomDirectiveParser(customDir, body); } else if (isa(element)) { body << " ::llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n" << " if (parser.parseOperandList(allOperands))\n" - << " return failure();\n"; + << " return ::mlir::failure();\n"; } else if (isa(element)) { body << llvm::formatv(regionListParserCode, "full"); @@ -1197,7 +1197,7 @@ if (allOperands) { body << " if (parser.resolveOperands(allOperands, allOperandTypes, " "allOperandLoc, result.operands))\n" - " return failure();\n"; + " return ::mlir::failure();\n"; return; } @@ -1214,7 +1214,7 @@ body << op.operand_begin()->name << "Operands"; } body << ", allOperandTypes, parser.getNameLoc(), result.operands))\n" - << " return failure();\n"; + << " return ::mlir::failure();\n"; return; } // Handle the case where all of the operands were grouped together. @@ -1238,7 +1238,7 @@ } body << ", allOperandLoc, result.operands))\n" - << " return failure();\n"; + << " return ::mlir::failure();\n"; return; } @@ -1270,7 +1270,7 @@ // overload. if (verifyOperandAndTypeSize) 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::genParserVariadicSegmentResolution(Operator &op, OpMethodBody &body) { - if (!allOperands && op.getTrait("OpTrait::AttrSizedOperandSegments")) { + if (!allOperands && + op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments")) { body << " result.addAttribute(\"operand_segment_sizes\", " << "parser.getBuilder().getI32VectorAttr({"; auto interleaveFn = [&](const NamedTypeConstraint &operand) { @@ -1328,7 +1329,8 @@ body << "}));\n"; } - if (!allResultTypes && op.getTrait("OpTrait::AttrSizedResultSegments")) { + if (!allResultTypes && + op.getTrait("::mlir::OpTrait::AttrSizedResultSegments")) { body << " result.addAttribute(\"result_segment_sizes\", " << "parser.getBuilder().getI32VectorAttr({"; auto interleaveFn = [&](const NamedTypeConstraint &result) { @@ -1369,9 +1371,11 @@ body << " p.printOptionalAttrDict" << (withKeyword ? "WithKeyword" : "") << "(getAttrs(), /*elidedAttrs=*/{"; // 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\", "; - if (!fmt.allResultTypes && op.getTrait("OpTrait::AttrSizedResultSegments")) + if (!fmt.allResultTypes && + op.getTrait("::mlir::OpTrait::AttrSizedResultSegments")) body << "\"result_segment_sizes\", "; llvm::interleaveComma( fmt.usedAttributes, body, @@ -1607,7 +1611,7 @@ } 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(); // Emit the operation name, trimming the prefix if this is the standard @@ -2004,16 +2008,16 @@ if (curToken.getKind() != kind) return emitError(curToken.getLoc(), msg); consumeToken(); - return success(); + return ::mlir::success(); } LogicalResult emitError(llvm::SMLoc loc, const Twine &msg) { lexer.emitError(loc, msg); - return failure(); + return ::mlir::failure(); } LogicalResult emitErrorAndNote(llvm::SMLoc loc, const Twine &msg, const Twine ¬e) { lexer.emitErrorAndNote(loc, msg, note); - return failure(); + return ::mlir::failure(); } //===--------------------------------------------------------------------===// @@ -2045,7 +2049,7 @@ while (curToken.getKind() != Token::eof) { std::unique_ptr element; if (failed(parseElement(element, /*isTopLevel=*/true))) - return failure(); + return ::mlir::failure(); fmt.elements.push_back(std::move(element)); } @@ -2075,11 +2079,11 @@ failed(verifyResults(loc, variableTyResolver)) || failed(verifyOperands(loc, variableTyResolver)) || failed(verifyRegions(loc)) || failed(verifySuccessors(loc))) - return failure(); + return ::mlir::failure(); // Collect the set of used attributes in the format. fmt.usedAttributes = seenAttrs.takeVector(); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::verifyAttributes(llvm::SMLoc loc) { @@ -2093,8 +2097,8 @@ iteratorStack.emplace_back(fmt.elements.begin(), fmt.elements.end()); while (!iteratorStack.empty()) if (failed(verifyAttributes(loc, iteratorStack))) - return failure(); - return success(); + return ::mlir::failure(); + return ::mlir::success(); } /// Verify the attribute elements at the back of the given stack of iterators. LogicalResult FormatParser::verifyAttributes( @@ -2109,7 +2113,7 @@ if (auto *optional = dyn_cast(element)) { auto elements = optional->getElements(); 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 @@ -2145,7 +2149,7 @@ } } iteratorStack.pop_back(); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::verifyOperands( @@ -2193,13 +2197,13 @@ auto it = buildableTypes.insert({*builder, buildableTypes.size()}); fmt.operandTypes[i].setBuilderIdx(it.first->second); } - return success(); + return ::mlir::success(); } LogicalResult FormatParser::verifyRegions(llvm::SMLoc loc) { // Check that all of the regions are within the format. if (hasAllRegions) - return success(); + return ::mlir::success(); for (unsigned i = 0, e = op.getNumRegions(); i != e; ++i) { const NamedRegion ®ion = op.getRegion(i); @@ -2211,7 +2215,7 @@ "' directive to the custom assembly format"); } } - return success(); + return ::mlir::success(); } LogicalResult FormatParser::verifyResults( @@ -2219,7 +2223,7 @@ llvm::StringMap &variableTyResolver) { // If we format all of the types together, there is nothing to check. if (fmt.allResultTypes) - return success(); + return ::mlir::success(); // Check that all of the result types can be inferred. auto &buildableTypes = fmt.buildableTypes; @@ -2252,13 +2256,13 @@ auto it = buildableTypes.insert({*builder, buildableTypes.size()}); fmt.resultTypes[i].setBuilderIdx(it.first->second); } - return success(); + return ::mlir::success(); } LogicalResult FormatParser::verifySuccessors(llvm::SMLoc loc) { // Check that all of the successors are within the format. if (hasAllSuccessors) - return success(); + return ::mlir::success(); for (unsigned i = 0, e = op.getNumSuccessors(); i != e; ++i) { const NamedSuccessor &successor = op.getSuccessor(i); @@ -2270,7 +2274,7 @@ "' directive to the custom assembly format"); } } - return success(); + return ::mlir::success(); } void FormatParser::handleAllTypesMatchConstraint( @@ -2368,7 +2372,7 @@ if (isTopLevel && !seenAttrs.insert(attr)) return emitError(loc, "attribute '" + name + "' is already bound"); element = std::make_unique(attr); - return success(); + return ::mlir::success(); } /// Operands if (const NamedTypeConstraint *operand = findArg(op.getOperands(), name)) { @@ -2377,7 +2381,7 @@ return emitError(loc, "operand '" + name + "' is already bound"); } element = std::make_unique(operand); - return success(); + return ::mlir::success(); } /// Regions if (const NamedRegion *region = findArg(op.getRegions(), name)) { @@ -2386,14 +2390,14 @@ if (hasAllRegions || !seenRegions.insert(region).second) return emitError(loc, "region '" + name + "' is already bound"); element = std::make_unique(region); - return success(); + return ::mlir::success(); } /// Results. if (const auto *result = findArg(op.getResults(), name)) { if (isTopLevel) return emitError(loc, "results can not be used at the top level"); element = std::make_unique(result); - return success(); + return ::mlir::success(); } /// Successors. if (const auto *successor = findArg(op.getSuccessors(), name)) { @@ -2402,7 +2406,7 @@ if (hasAllSuccessors || !seenSuccessors.insert(successor).second) return emitError(loc, "successor '" + name + "' is already bound"); element = std::make_unique(successor); - return success(); + return ::mlir::success(); } return emitError(loc, "expected variable to refer to an argument, region, " "result, or successor"); @@ -2450,7 +2454,7 @@ return emitError(literalTok.getLoc(), "expected valid literal"); element = std::make_unique(value); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::parseOptional(std::unique_ptr &element, @@ -2467,11 +2471,11 @@ Optional anchorIdx; do { if (failed(parseOptionalChildElement(elements, seenVariables, anchorIdx))) - return failure(); + return ::mlir::failure(); } while (curToken.getKind() != Token::r_paren); consumeToken(); if (failed(parseToken(Token::question, "expected '?' after optional group"))) - return failure(); + return ::mlir::failure(); // The optional group is required to have an anchor. if (!anchorIdx) @@ -2494,22 +2498,22 @@ if (!seenVariables.count(var)) return emitError(curLoc, "type directive can only refer to variables " "within the optional group"); - return success(); + return ::mlir::success(); }; for (auto &ele : elements) { if (auto *typeEle = dyn_cast(ele.get())) { if (failed(checkTypeOperand(typeEle->getOperand()))) - return failure(); + return ::mlir::failure(); } else if (auto *typeEle = dyn_cast(ele.get())) { if (failed(checkTypeOperand(typeEle->getInputs())) || failed(checkTypeOperand(typeEle->getResults()))) - return failure(); + return ::mlir::failure(); } } optionalVariables.insert(seenVariables.begin(), seenVariables.end()); element = std::make_unique(std::move(elements), *anchorIdx); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::parseOptionalChildElement( @@ -2519,7 +2523,7 @@ llvm::SMLoc childLoc = curToken.getLoc(); childElements.push_back({}); 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. bool isAnchor = curToken.getKind() == Token::caret; @@ -2538,7 +2542,7 @@ if (isAnchor && !attrEle->getVar()->attr.isOptional()) return emitError(childLoc, "only optional attributes can be used to " "anchor an optional group"); - return success(); + return ::mlir::success(); }) // Only optional-like(i.e. variadic) operands can be within an optional // group. @@ -2547,12 +2551,12 @@ return emitError(childLoc, "only variable length operands can be " "used within an optional group"); seenVariables.insert(ele->getVar()); - return success(); + return ::mlir::success(); }) .Case([&](RegionVariable *) { // TODO: When ODS has proper support for marking "optional" regions, add // a check here. - return success(); + return ::mlir::success(); }) // Literals, custom directives, and type directives may be used, // but they can't anchor the group. @@ -2561,7 +2565,7 @@ if (isAnchor) return emitError(childLoc, "only variables can be used to anchor " "an optional group"); - return success(); + return ::mlir::success(); }) .Default([&](Element *) { return emitError(childLoc, "only literals, types, and variables can be " @@ -2581,7 +2585,7 @@ hasAttrDict = true; element = std::make_unique(withKeyword); - return success(); + return ::mlir::success(); } LogicalResult @@ -2592,7 +2596,7 @@ // Parse the custom directive name. if (failed( parseToken(Token::less, "expected '<' before custom directive name"))) - return failure(); + return ::mlir::failure(); Token nameTok = curToken; if (failed(parseToken(Token::identifier, @@ -2601,13 +2605,13 @@ "expected '>' after custom directive name")) || failed(parseToken(Token::l_paren, "expected '(' before custom directive parameters"))) - return failure(); + return ::mlir::failure(); // Parse the child elements for this optional group.= std::vector> elements; do { if (failed(parseCustomDirectiveParameter(elements))) - return failure(); + return ::mlir::failure(); if (curToken.getKind() != Token::comma) break; consumeToken(); @@ -2615,7 +2619,7 @@ if (failed(parseToken(Token::r_paren, "expected ')' after custom directive parameters"))) - return failure(); + return ::mlir::failure(); // After parsing all of the elements, ensure that all type directives refer // only to variables. @@ -2630,7 +2634,7 @@ element = std::make_unique(nameTok.getSpelling(), std::move(elements)); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::parseCustomDirectiveParameter( @@ -2638,7 +2642,7 @@ llvm::SMLoc childLoc = curToken.getLoc(); parameters.push_back({}); if (failed(parseElement(parameters.back(), /*isTopLevel=*/true))) - return failure(); + return ::mlir::failure(); // Verify that the element can be placed within a custom directive. if (!isa(std::move(inputs), std::move(results)); - return success(); + return ::mlir::success(); } LogicalResult @@ -2679,7 +2683,7 @@ fmt.allOperands = true; } element = std::make_unique(); - return success(); + return ::mlir::success(); } LogicalResult @@ -2691,7 +2695,7 @@ return emitError(loc, "'regions' directive creates overlap in format"); hasAllRegions = true; element = std::make_unique(); - return success(); + return ::mlir::success(); } LogicalResult @@ -2701,7 +2705,7 @@ return emitError(loc, "'results' directive can not be used as a " "top-level directive"); element = std::make_unique(); - return success(); + return ::mlir::success(); } LogicalResult @@ -2714,7 +2718,7 @@ return emitError(loc, "'successors' directive creates overlap in format"); hasAllSuccessors = true; element = std::make_unique(); - return success(); + return ::mlir::success(); } LogicalResult @@ -2728,16 +2732,16 @@ if (failed(parseToken(Token::l_paren, "expected '(' before argument list")) || failed(parseTypeDirectiveOperand(operand)) || failed(parseToken(Token::r_paren, "expected ')' after argument list"))) - return failure(); + return ::mlir::failure(); element = std::make_unique(std::move(operand)); - return success(); + return ::mlir::success(); } LogicalResult FormatParser::parseTypeDirectiveOperand(std::unique_ptr &element) { llvm::SMLoc loc = curToken.getLoc(); if (failed(parseElement(element, /*isTopLevel=*/false))) - return failure(); + return ::mlir::failure(); if (isa(element.get())) return emitError( loc, "'type' directive operand expects variable or directive operand"); @@ -2765,7 +2769,7 @@ } else { return emitError(loc, "invalid argument to 'type' directive"); } - return success(); + return ::mlir::success(); } //===----------------------------------------------------------------------===// diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -887,8 +887,9 @@ // special cases listed below, DRR needs to supply types for all results // when building an op. bool isSameOperandsAndResultType = - resultOp.getTrait("OpTrait::SameOperandsAndResultType"); - bool useFirstAttr = resultOp.getTrait("OpTrait::FirstAttrDerivedResultType"); + resultOp.getTrait("::mlir::OpTrait::SameOperandsAndResultType"); + bool useFirstAttr = + resultOp.getTrait("::mlir::OpTrait::FirstAttrDerivedResultType"); if (isSameOperandsAndResultType || useFirstAttr) { // We know how to deduce the result type for ops with these traits and we've