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 @@ -22,6 +22,7 @@ def GPU_Dialect : Dialect { let name = "gpu"; let hasOperationAttrVerify = 1; + let cppNamespace = "::mlir::gpu"; let extraClassDeclaration = [{ /// Get the name of the attribute used to annotate the modules that contain 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/GPUOps.td b/mlir/include/mlir/Dialect/GPU/GPUOps.td --- a/mlir/include/mlir/Dialect/GPU/GPUOps.td +++ b/mlir/include/mlir/Dialect/GPU/GPUOps.td @@ -203,8 +203,9 @@ let skipDefaultBuilders = 1; let builders = [ - OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, " - "FunctionType type, ArrayRef workgroupAttributions = {}, " + OpBuilder<"OpBuilder &builder, OperationState &result, " + "::llvm::StringRef name, FunctionType type, " + "ArrayRef workgroupAttributions = {}, " "ArrayRef privateAttributions = {}, " "ArrayRef attrs = {}"> ]; @@ -269,7 +270,7 @@ /// Returns the name of the attribute containing the number of buffers /// located in the workgroup memory. - static StringRef getNumWorkgroupAttributionsAttrName() { + static ::llvm::StringRef getNumWorkgroupAttributionsAttrName() { return "workgroup_attributions"; } @@ -281,9 +282,9 @@ unsigned getNumFuncResults() { return getType().getNumResults(); } /// Returns the keywords used in the custom syntax for this Op. - static StringRef getWorkgroupKeyword() { return "workgroup"; } - static StringRef getPrivateKeyword() { return "private"; } - static StringRef getKernelKeyword() { return "kernel"; } + static ::llvm::StringRef getWorkgroupKeyword() { return "workgroup"; } + static ::llvm::StringRef getPrivateKeyword() { return "private"; } + static ::llvm::StringRef getKernelKeyword() { return "kernel"; } /// Hook for FunctionLike verifier. LogicalResult verifyType(); @@ -390,10 +391,10 @@ unsigned getNumKernelOperands(); /// The name of the kernel's containing module. - StringRef getKernelModuleName(); + ::llvm::StringRef getKernelModuleName(); /// The name of the kernel. - StringRef getKernelName(); + ::llvm::StringRef getKernelName(); /// The i-th operand passed to the kernel function. Value getKernelOperand(unsigned i); @@ -414,7 +415,7 @@ NamedAttribute); /// The name of the symbol reference attribute specifying the kernel to launch. - static StringRef getKernelAttrName() { return "kernel"; } + static ::llvm::StringRef getKernelAttrName() { return "kernel"; } }]; let verifier = [{ return ::verify(*this); }]; @@ -512,8 +513,8 @@ /// Get the SSA values passed as operands to specify the block size. KernelDim3 getBlockSizeOperandValues(); - static StringRef getBlocksKeyword() { return "blocks"; } - static StringRef getThreadsKeyword() { return "threads"; } + static ::llvm::StringRef getBlocksKeyword() { return "blocks"; } + static ::llvm::StringRef getThreadsKeyword() { return "threads"; } /// The number of launch configuration operands, placed at the leading /// positions of the operand list. @@ -719,7 +720,7 @@ ``` }]; let builders = [OpBuilder<"OpBuilder &builder, OperationState &result, " - "StringRef name">]; + "::llvm::StringRef name">]; let parser = [{ return ::parseGPUModuleOp(parser, result); }]; let printer = [{ return ::print(p, *this); }]; let regions = (region SizedRegion<1>:$body); 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 @@ -19,7 +19,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"); @@ -292,7 +292,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< @@ -472,8 +472,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() != @@ -747,7 +747,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,15 @@ #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 @@ -17,15 +17,9 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc" - -namespace mlir { -namespace omp { +#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc" #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/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 @@ -19,6 +19,7 @@ #include "mlir/Interfaces/SideEffectInterfaces.h" #include "llvm/Support/PointerLikeTypeTraits.h" + namespace mlir { class OpBuilder; @@ -28,11 +29,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 + // 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 + // 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,12 @@ 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/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 @@ -1072,9 +1072,6 @@ return verifySingleInputPoolingOp(op); } -namespace mlir { -namespace linalg { - #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" #define GET_OP_CLASSES @@ -1083,9 +1080,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 @@ -555,11 +555,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/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 @@ -3162,11 +3162,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 @@ -2664,11 +2664,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/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/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,15 @@ // 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; + llvm::Twine returnType = differentNamespace + ? llvm::Twine(attrDialect.getCppNamespace()) + + "::" + attr.getReturnType() + : attr.getReturnType(); + auto &method = opClass.newMethod(returnType.str(), name); auto &body = method.body(); body << " auto attr = " << name << "Attr();\n"; if (attr.hasDefaultValue()) { @@ -2158,6 +2167,26 @@ // Emits the opcode enum and op classes. static void emitOpClasses(const std::vector &defs, raw_ostream &os, bool emitDecl) { + class NamespaceEmitter { + public: + 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"; + } + } + ~NamespaceEmitter() { + for (StringRef ns : llvm::reverse(namespaces)) { + os << "} // namespace " << ns << "\n"; + } + } + private: + raw_ostream& os; + llvm::SmallVector namespaces; + }; + // First emit forward declaration for each class, this allows them to refer // to each others in traits for example. if (emitDecl) { @@ -2165,6 +2194,7 @@ os << "#undef GET_OP_FWD_DEFINES\n"; for (auto *def : defs) { Operator op(*def); + NamespaceEmitter emitter(os, op); os << "class " << op.getCppClassName() << ";\n"; } os << "#endif\n\n"; @@ -2173,6 +2203,7 @@ IfDefScope scope("GET_OP_CLASSES", os); for (auto *def : defs) { Operator op(*def); + NamespaceEmitter emitter(os, op); if (emitDecl) { os << formatv(opCommentHeader, op.getQualCppClassName(), "declarations"); OpOperandAdaptorEmitter::emitDecl(op, os);