[flang-commits] [flang] 7d1ed69 - Make namespace handling uniform across dialect backends.
Mehdi Amini via flang-commits
flang-commits at lists.llvm.org
Mon Sep 14 13:33:46 PDT 2020
Author: Federico Lebrón
Date: 2020-09-14T20:33:31Z
New Revision: 7d1ed69c8aad00f3ba1e917da54508489de6d610
URL: https://github.com/llvm/llvm-project/commit/7d1ed69c8aad00f3ba1e917da54508489de6d610
DIFF: https://github.com/llvm/llvm-project/commit/7d1ed69c8aad00f3ba1e917da54508489de6d610.diff
LOG: Make namespace handling uniform across dialect backends.
Now backends spell out which namespace they want to be in, instead of relying on
clients #including them inside already-opened namespaces. This also means that
cppNamespaces should be fully qualified, and there's no implicit "::mlir::"
prepended to them anymore.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D86811
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.h
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Optimizer/Dialect/FIROps.cpp
mlir/examples/toy/Ch2/include/toy/Dialect.h
mlir/examples/toy/Ch2/include/toy/Ops.td
mlir/examples/toy/Ch3/include/toy/Dialect.h
mlir/examples/toy/Ch3/include/toy/Ops.td
mlir/examples/toy/Ch4/include/toy/Dialect.h
mlir/examples/toy/Ch4/include/toy/Ops.td
mlir/examples/toy/Ch5/include/toy/Dialect.h
mlir/examples/toy/Ch5/include/toy/Ops.td
mlir/examples/toy/Ch6/include/toy/Dialect.h
mlir/examples/toy/Ch6/include/toy/Ops.td
mlir/examples/toy/Ch7/include/toy/Dialect.h
mlir/examples/toy/Ch7/include/toy/Ops.td
mlir/include/mlir/Dialect/AVX512/AVX512.td
mlir/include/mlir/Dialect/AVX512/AVX512Dialect.h
mlir/include/mlir/Dialect/GPU/GPUBase.td
mlir/include/mlir/Dialect/GPU/GPUDialect.h
mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h
mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td
mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512Dialect.h
mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h
mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h
mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td
mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h
mlir/include/mlir/Dialect/OpenACC/OpenACC.h
mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/include/mlir/Dialect/PDL/IR/PDL.h
mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
mlir/include/mlir/Dialect/Quant/QuantOps.h
mlir/include/mlir/Dialect/Quant/QuantOpsBase.td
mlir/include/mlir/Dialect/SCF/SCF.h
mlir/include/mlir/Dialect/SCF/SCFOps.td
mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h
mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td
mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h
mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h
mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h
mlir/include/mlir/Dialect/Shape/IR/Shape.h
mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
mlir/include/mlir/Dialect/Vector/VectorOps.h
mlir/include/mlir/Dialect/Vector/VectorOps.td
mlir/include/mlir/IR/OpBase.td
mlir/include/mlir/TableGen/Operator.h
mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/lib/Dialect/PDL/IR/PDL.cpp
mlir/lib/Dialect/SCF/SCF.cpp
mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/lib/Dialect/Vector/VectorOps.cpp
mlir/lib/TableGen/Operator.cpp
mlir/test/lib/Dialect/Test/TestDialect.h
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/op-attribute.td
mlir/test/mlir-tblgen/op-decl.td
mlir/tools/mlir-tblgen/DialectGen.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.h b/flang/include/flang/Optimizer/Dialect/FIROps.h
index ece775bd6ffe..fe5e944fe267 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.h
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.h
@@ -41,9 +41,10 @@ mlir::ParseResult parseSelector(mlir::OpAsmParser &parser,
mlir::OpAsmParser::OperandType &selector,
mlir::Type &type);
+} // namespace fir
+
#define GET_OP_CLASSES
#include "flang/Optimizer/Dialect/FIROps.h.inc"
-} // namespace fir
#endif // OPTIMIZER_DIALECT_FIROPS_H
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 0bc543882a26..e232ec5f0111 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -21,6 +21,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
def fir_Dialect : Dialect {
let name = "fir";
+ let cppNamespace = "::fir";
}
// Types and predicates
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 36334167184d..079d16d74181 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1552,11 +1552,8 @@ fir::GlobalOp fir::createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
return modBuilder.create<fir::GlobalOp>(loc, name, type, attrs);
}
-namespace fir {
-
// Tablegen operators
#define GET_OP_CLASSES
#include "flang/Optimizer/Dialect/FIROps.cpp.inc"
-} // namespace fir
diff --git a/mlir/examples/toy/Ch2/include/toy/Dialect.h b/mlir/examples/toy/Ch2/include/toy/Dialect.h
index 4ddc63c2b4dc..8bcad903c538 100644
--- a/mlir/examples/toy/Ch2/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch2/include/toy/Dialect.h
@@ -34,12 +34,12 @@ class ToyDialect : public mlir::Dialect {
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
index 4a56edb57b3e..db01e226384b 100644
--- a/mlir/examples/toy/Ch2/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch2/include/toy/Ops.td
@@ -20,7 +20,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
// 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
index 4ddc63c2b4dc..8bcad903c538 100644
--- a/mlir/examples/toy/Ch3/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch3/include/toy/Dialect.h
@@ -34,12 +34,12 @@ class ToyDialect : public mlir::Dialect {
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
index f7320ebc1d12..d889b81bef0a 100644
--- a/mlir/examples/toy/Ch3/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch3/include/toy/Ops.td
@@ -19,7 +19,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
// 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
index b1a38ec60a0c..085334740892 100644
--- a/mlir/examples/toy/Ch4/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch4/include/toy/Dialect.h
@@ -36,12 +36,12 @@ class ToyDialect : public mlir::Dialect {
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
index 48c08a6a9369..2ce4692e63f2 100644
--- a/mlir/examples/toy/Ch4/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch4/include/toy/Ops.td
@@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// 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
index b1a38ec60a0c..085334740892 100644
--- a/mlir/examples/toy/Ch5/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch5/include/toy/Dialect.h
@@ -36,12 +36,12 @@ class ToyDialect : public mlir::Dialect {
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
index 210513f22fec..2a746bb2d800 100644
--- a/mlir/examples/toy/Ch5/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch5/include/toy/Ops.td
@@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// 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
index b1a38ec60a0c..085334740892 100644
--- a/mlir/examples/toy/Ch6/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch6/include/toy/Dialect.h
@@ -36,12 +36,12 @@ class ToyDialect : public mlir::Dialect {
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
index a92f597fd178..d9a612d00fe9 100644
--- a/mlir/examples/toy/Ch6/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch6/include/toy/Ops.td
@@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// 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
index 4eceb422efa6..fb2927834779 100644
--- a/mlir/examples/toy/Ch7/include/toy/Dialect.h
+++ b/mlir/examples/toy/Ch7/include/toy/Dialect.h
@@ -50,6 +50,9 @@ class ToyDialect : public mlir::Dialect {
static llvm::StringRef getDialectNamespace() { return "toy"; }
};
+} // end namespace toy
+} // end namespace mlir
+
//===----------------------------------------------------------------------===//
// Toy Operations
//===----------------------------------------------------------------------===//
@@ -59,6 +62,9 @@ class ToyDialect : public mlir::Dialect {
#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
index ab0cf9dbb0ff..dc9472c569a9 100644
--- a/mlir/examples/toy/Ch7/include/toy/Ops.td
+++ b/mlir/examples/toy/Ch7/include/toy/Ops.td
@@ -21,7 +21,7 @@ include "toy/ShapeInferenceInterface.td"
// 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
index e1ed35c50e87..eee24ce1d5d5 100644
--- a/mlir/include/mlir/Dialect/AVX512/AVX512.td
+++ b/mlir/include/mlir/Dialect/AVX512/AVX512.td
@@ -21,7 +21,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index 544fb7c2a495..aae3dbdf179f 100644
--- 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
index 32e0952a15b4..5641d60b0e28 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUBase.td
+++ b/mlir/include/mlir/Dialect/GPU/GPUBase.td
@@ -21,6 +21,7 @@ include "mlir/IR/OpBase.td"
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
index 35daee29aa6a..b55b0c8a3396 100644
--- a/mlir/include/mlir/Dialect/GPU/GPUDialect.h
+++ b/mlir/include/mlir/Dialect/GPU/GPUDialect.h
@@ -34,12 +34,13 @@ struct KernelDim3 {
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
index 298ec0c803f0..8bce2fd0ad2b 100644
--- a/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h
+++ b/mlir/include/mlir/Dialect/GPU/ParallelLoopMapper.h
@@ -27,8 +27,11 @@ struct LogicalResult;
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
index 12668c4da41b..fcc90a2a801e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAVX512.td
@@ -21,7 +21,7 @@ include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
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
index 27b98fd18910..c028fda514fe 100644
--- 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
index 2f465f07a97e..5c16f33e9fc0 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
@@ -49,18 +49,23 @@ struct LLVMTypeStorage;
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
index 10755a436115..a6be8ef6d8ba 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
@@ -23,7 +23,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index b5bf4ac77972..626bc4b88989 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -59,7 +59,7 @@ def LLVM_VoidResultTypeOpBuilder : OpBuilder<
"OpBuilder &builder, OperationState &result, Type resultType, "
"ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
[{
- auto llvmType = resultType.dyn_cast<LLVM::LLVMType>(); (void)llvmType;
+ auto llvmType = resultType.dyn_cast<LLVMType>(); (void)llvmType;
assert(llvmType && "result must be an LLVM type");
assert(llvmType.isVoidTy() &&
"for zero-result operands, only 'void' is accepted as result type");
@@ -301,7 +301,7 @@ def LLVM_LoadOp :
"unsigned alignment = 0, bool isVolatile = false, "
"bool isNonTemporal = false",
[{
- auto type = addr.getType().cast<LLVM::LLVMType>().getPointerElementTy();
+ auto type = addr.getType().cast<LLVMType>().getPointerElementTy();
build(b, result, type, addr, alignment, isVolatile, isNonTemporal);
}]>,
OpBuilder<
@@ -494,8 +494,8 @@ def LLVM_ShuffleVectorOp
"OpBuilder &b, OperationState &result, Value v1, Value v2, "
"ArrayAttr mask, ArrayRef<NamedAttribute> attrs = {}">];
let verifier = [{
- auto wrappedVectorType1 = v1().getType().cast<LLVM::LLVMType>();
- auto wrappedVectorType2 = v2().getType().cast<LLVM::LLVMType>();
+ auto wrappedVectorType1 = v1().getType().cast<LLVMType>();
+ auto wrappedVectorType2 = v2().getType().cast<LLVMType>();
if (!wrappedVectorType2.isVectorTy())
return emitOpError("expected LLVM IR Dialect vector type for operand #2");
if (wrappedVectorType1.getVectorElementType() !=
@@ -770,7 +770,7 @@ def LLVM_LLVMFuncOp
let builders = [
OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, "
- "LLVMType type, LLVM::Linkage linkage = LLVM::Linkage::External, "
+ "LLVMType type, Linkage linkage = Linkage::External, "
"ArrayRef<NamedAttribute> attrs = {}, "
"ArrayRef<MutableDictionaryAttr> argAttrs = {}">
];
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
index 9cc5314bdb90..fff82e3b9f4f 100644
--- 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
index 7d47e5012ac9..5f72ad35a670 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index eb40373c3f11..b00b8ac0b125 100644
--- 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
index f85c4f02899b..c6d2ded073e6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
@@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index 7955345f6966..8ac82b768ad3 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td
@@ -31,6 +31,7 @@ def Linalg_Dialect : Dialect {
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
index 21bff4185abf..09fc11bc4917 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h
@@ -85,6 +85,9 @@ AffineMap extractOrIdentityMap(Optional<AffineMap> maybeMap, unsigned rank,
SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
ArrayRef<AffineExpr> b);
+} // namespace linalg
+} // namespace mlir
+
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.h.inc"
#define GET_OP_CLASSES
@@ -93,7 +96,5 @@ SmallVector<AffineExpr, 4> concat(ArrayRef<AffineExpr> a,
#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
index f32b70efd87e..0e8216cc4268 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterface.td
@@ -18,6 +18,7 @@ include "mlir/Dialect/Linalg/IR/LinalgBase.td"
// 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
index 18b2c3aaa53d..a4e32b9263e8 100644
--- 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
index 8f5e1daf9aeb..40700e6d1b73 100644
--- 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
index 30d6f435b75f..c0178ebe9e48 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -24,7 +24,7 @@ def OpenACC_Dialect : Dialect {
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
index 8f0bb93e1043..0715b9ddd394 100644
--- 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
index eb92745d6fa5..3ac7f2c5dda5 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -19,7 +19,7 @@ include "mlir/Dialect/OpenMP/OmpCommon.td"
def OpenMP_Dialect : Dialect {
let name = "omp";
- let cppNamespace = "omp";
+ let cppNamespace = "::mlir::omp";
}
class OpenMP_Op<string mnemonic, list<OpTrait> traits = []> :
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDL.h b/mlir/include/mlir/Dialect/PDL/IR/PDL.h
index 64dbf8f74399..14136021d26c 100644
--- 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 @@ namespace pdl {
#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
index 9802bf943157..b372e594e2e7 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
@@ -63,7 +63,7 @@ def PDL_Dialect : Dialect {
}];
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
index 6d895679b3d6..07c7f84c8078 100644
--- 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 @@ namespace pdl_interp {
#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
index 58a2032a2182..e95162bb6580 100644
--- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
+++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
@@ -34,7 +34,7 @@ def PDLInterp_Dialect : Dialect {
}];
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
index 234a2b44c6f6..00a6032a2fea 100644
--- 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
index aa7c311e20a3..10339fcbcf5d 100644
--- a/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td
+++ b/mlir/include/mlir/Dialect/Quant/QuantOpsBase.td
@@ -17,6 +17,7 @@ include "mlir/IR/OpBase.td"
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
index 3974b58cbfbb..55c8cbf5fa74 100644
--- 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
index 59ba50fbe232..179b4d773a3a 100644
--- a/mlir/include/mlir/Dialect/SCF/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td
@@ -19,7 +19,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index b1909b367553..a743fa9c30d9 100644
--- 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
index 21f926a1500c..1fa72bf4dcab 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVBase.td
@@ -45,7 +45,7 @@ def SPIRV_Dialect : Dialect {
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 @@ class Capability<list<I32EnumAttrCase> capabilities> : Availability {
let instance = "ref";
}
+class SPIRVOpInterface<string name> : OpInterface<name> {
+ 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
index 2cffebec60ea..1b37abb93764 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVDialect.h
@@ -20,9 +20,9 @@ namespace spirv {
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
index 01a2c6081643..61568df03dcd 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVOps.h
@@ -28,11 +28,15 @@ class VerCapExtAttr;
// 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
index 2d224effdee3..43fb708c7908 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVTypes.h
@@ -77,25 +77,25 @@ class SPIRVType : public Type {
/// The extension requirements for each type are following the
/// ((Extension::A OR Extension::B) AND (Extension::C OR Extension::D))
/// convention.
- using ExtensionArrayRefVector = SmallVectorImpl<ArrayRef<spirv::Extension>>;
+ using ExtensionArrayRefVector = SmallVectorImpl<ArrayRef<Extension>>;
/// 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<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> 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<ArrayRef<spirv::Capability>>;
+ using CapabilityArrayRefVector = SmallVectorImpl<ArrayRef<Capability>>;
/// 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<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
/// Returns the size in bytes for each type. If no size can be calculated,
/// returns `llvm::None`. Note that if the type has explicit layout, it is
@@ -116,9 +116,9 @@ class ScalarType : public SPIRVType {
static bool isValid(IntegerType);
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
Optional<int64_t> getSizeInBytes();
};
@@ -144,9 +144,9 @@ class CompositeType : public SPIRVType {
bool hasCompileTimeKnownNumElements() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
Optional<int64_t> getSizeInBytes();
};
@@ -172,9 +172,9 @@ class ArrayType : public Type::TypeBase<ArrayType, CompositeType,
unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
/// Returns the array size in bytes. Since array type may have an explicit
/// stride declaration (in bytes), we also include it in the calculation.
@@ -215,9 +215,9 @@ class ImageType
// TODO: Add support for Access qualifier
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
};
// SPIR-V pointer type
@@ -233,9 +233,9 @@ class PointerType : public Type::TypeBase<PointerType, SPIRVType,
StorageClass getStorageClass() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
};
// SPIR-V run-time array type
@@ -257,9 +257,9 @@ class RuntimeArrayType
unsigned getArrayStride() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
};
// SPIR-V struct type
@@ -335,21 +335,21 @@ class StructType : public Type::TypeBase<StructType, CompositeType,
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<StructType::MemberDecorationInfo>
&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<StructType::MemberDecorationInfo>
&decorationsInfo) const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
};
llvm::hash_code
@@ -362,21 +362,21 @@ class CooperativeMatrixNVType
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<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
};
// SPIR-V matrix type
@@ -412,9 +412,9 @@ class MatrixType : public Type::TypeBase<MatrixType, CompositeType,
Type getElementType() const;
void getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> storage = llvm::None);
void getCapabilities(SPIRVType::CapabilityArrayRefVector &capabilities,
- Optional<spirv::StorageClass> storage = llvm::None);
+ Optional<StorageClass> 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
index cc601bdedaca..f40d6154544a 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/Shape.h
+++ b/mlir/include/mlir/Dialect/Shape/IR/Shape.h
@@ -67,12 +67,12 @@ class WitnessType : public Type::TypeBase<WitnessType, Type, TypeStorage> {
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
index 754dfcd6452f..b038819bca3d 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
@@ -36,7 +36,7 @@ def ShapeDialect : Dialect {
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
index 562e07f98774..2354cc6abd89 100644
--- a/mlir/include/mlir/Dialect/Vector/VectorOps.h
+++ b/mlir/include/mlir/Dialect/Vector/VectorOps.h
@@ -128,13 +128,11 @@ namespace impl {
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
index dceb850ad929..3cb1265b38ce 100644
--- a/mlir/include/mlir/Dialect/Vector/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td
@@ -19,7 +19,7 @@ include "mlir/Interfaces/VectorInterfaces.td"
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
index 29f139f25069..ec0e229ae627 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1672,7 +1672,7 @@ class OpTrait;
// 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<string prop> : OpTrait {
- string trait = "OpTrait::" # prop;
+ string trait = "::mlir::OpTrait::" # prop;
}
// ParamNativeOpTrait corresponds to the template-parameterized traits in the
@@ -1687,7 +1687,7 @@ class ParamNativeOpTrait<string prop, string params>
// affects op definition generator internals, like how op builders and
// operand/attribute/result getters are generated.
class GenInternalOpTrait<string prop> : OpTrait {
- string trait = "OpTrait::" # prop;
+ string trait = "::mlir::OpTrait::" # prop;
}
// PredOpTrait is an op trait implemented by way of a predicate on the op.
diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h
index d7fac87af0be..34c550650364 100644
--- a/mlir/include/mlir/TableGen/Operator.h
+++ b/mlir/include/mlir/TableGen/Operator.h
@@ -242,6 +242,17 @@ class Operator {
// 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<StringRef, 2> 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
index 3595970c38f2..697f00864b15 100644
--- a/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp
+++ b/mlir/lib/Dialect/AVX512/IR/AVX512Dialect.cpp
@@ -25,10 +25,5 @@ void avx512::AVX512Dialect::initialize() {
>();
}
-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
index 58f9480c37be..7dc74f21e2fb 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -777,10 +777,5 @@ static void print(OpAsmPrinter &p, GPUModuleOp op) {
/*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
index b42929039a97..b953bad67627 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ParallelLoopMapper.cpp
@@ -23,10 +23,9 @@ using namespace mlir;
using namespace mlir::gpu;
using namespace mlir::scf;
+#include "mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc"
#include "mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc"
namespace mlir {
-
-#include "mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc"
namespace gpu {
StringRef getMappingAttrName() { return "mapping"; }
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp
index 9f7e66b0ae0a..512234cc8764 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAVX512Dialect.cpp
@@ -27,9 +27,5 @@ void LLVM::LLVMAVX512Dialect::initialize() {
>();
}
-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
index cc809b581c84..e13a83854b1e 100644
--- 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 @@ void NVVMDialect::initialize() {
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
index 70c3558638e6..afdd9537c679 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
@@ -91,10 +91,5 @@ void ROCDLDialect::initialize() {
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
index 7071cd385f77..efe2e45f78ea 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -1096,9 +1096,6 @@ static LogicalResult verify(PoolingSumOp op) {
return verifySingleInputPoolingOp(op);
}
-namespace mlir {
-namespace linalg {
-
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc"
#define GET_OP_CLASSES
@@ -1107,9 +1104,6 @@ namespace linalg {
#define GET_OP_CLASSES
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
-} // namespace linalg
-} // namespace mlir
-
AffineMap mlir::linalg::extractOrIdentityMap(Optional<AffineMap> maybeMap,
unsigned rank,
MLIRContext *context) {
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 217588289e85..ec47177df84c 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -271,9 +271,5 @@ static ParseResult parseParallelOp(OpAsmParser &parser,
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
index 082229b6b394..a0b9c969becf 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -454,11 +454,5 @@ static LogicalResult verify(TypeOp op) {
// 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
index 498246315d64..e36ffc2e6b81 100644
--- a/mlir/lib/Dialect/SCF/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/SCF.cpp
@@ -899,9 +899,5 @@ static void print(OpAsmPrinter &p, scf::YieldOp op) {
// 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
index c2bf4840ddc8..6773862a8cd7 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVAttributes.cpp
@@ -16,9 +16,10 @@ using namespace mlir;
// 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
index c171a755891b..a16dc1c8bc35 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
@@ -3266,11 +3266,15 @@ namespace spirv {
// 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
index bcfaa896f63d..cd722870f507 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -938,11 +938,5 @@ static void print(OpAsmPrinter &p, ReduceOp op) {
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
index d00e56297532..c2b6f31cf114 100644
--- a/mlir/lib/Dialect/Vector/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/VectorOps.cpp
@@ -2688,11 +2688,5 @@ void mlir::vector::populateVectorToVectorCanonicalizationPatterns(
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
index 0586cd837e07..24dffa36e13e 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
@@ -278,7 +279,7 @@ void Operator::populateTypeInferenceInfo(
// 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,21 @@ void Operator::print(llvm::raw_ostream &os) const {
}
}
+Operator::NamespaceEmitter::NamespaceEmitter(raw_ostream &os, Operator &op)
+ : os(os) {
+ auto dialect = op.getDialect();
+ if (!dialect)
+ return;
+ llvm::SplitString(dialect.getCppNamespace(), namespaces, "::");
+ for (StringRef ns : namespaces)
+ os << "namespace " << ns << " {\n";
+}
+
+Operator::NamespaceEmitter::~NamespaceEmitter() {
+ for (StringRef ns : llvm::reverse(namespaces))
+ os << "} // namespace " << ns << "\n";
+}
+
auto Operator::VariableDecoratorIterator::unwrap(llvm::Init *init)
-> VariableDecorator {
return VariableDecorator(cast<llvm::DefInit>(init)->getDef());
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h
index 34fc1a9534e8..09f84d1ac133 100644
--- 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 @@ namespace mlir {
#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
index f03c953396a4..9ae36ed1710c 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
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
index edb387cfa2d4..457aeab18d9e 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -275,3 +275,19 @@ def SomeTypedArrayAttr : TypedArrayAttrBase<SomeAttr, "SomeAttr array">;
// 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
index d1b11556be30..8390dea18ae9 100644
--- a/mlir/test/mlir-tblgen/op-decl.td
+++ b/mlir/test/mlir-tblgen/op-decl.td
@@ -61,8 +61,8 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
// CHECK: ::mlir::ValueRange odsOperands;
// CHECK: };
-// CHECK: class AOp : public ::mlir::Op<AOp, OpTrait::AtLeastNRegions<1>::Impl, OpTrait::AtLeastNResults<1>::Impl, OpTrait::ZeroSuccessor, OpTrait::AtLeastNOperands<1>::Impl, OpTrait::IsIsolatedFromAbove
-// CHECK-NOT: OpTrait::IsIsolatedFromAbove
+// CHECK: class AOp : public ::mlir::Op<AOp, ::mlir::OpTrait::AtLeastNRegions<1>::Impl, ::mlir::OpTrait::AtLeastNResults<1>::Impl, ::mlir::OpTrait::ZeroSuccessor, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::IsIsolatedFromAbove
+// CHECK-NOT: ::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
index 3a19379da8a3..4a9ec48b777e 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -153,6 +153,15 @@ static void emitDialectDecl(Dialect &dialect,
dialectsOs << llvm::formatv(dialectRegistrationTemplate,
dependentDialect);
}
+
+ // Emit all nested namespaces.
+ StringRef cppNamespace = dialect.getCppNamespace();
+ llvm::SmallVector<StringRef, 2> namespaces;
+ llvm::SplitString(cppNamespace, namespaces, "::");
+
+ for (auto ns : namespaces)
+ os << "namespace " << ns << " {\n";
+
// Emit the start of the decl.
std::string cppName = dialect.getCppClassName();
os << llvm::formatv(dialectDeclBeginStr, cppName, dialect.getName(),
@@ -179,6 +188,10 @@ static void emitDialectDecl(Dialect &dialect,
// 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
index 0b3ad38b035f..7f1d729e81b1 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -494,6 +494,7 @@ void OpEmitter::genAttrGetters() {
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 @@ void OpEmitter::genAttrGetters() {
// 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
diff erent namespace than the attribute?
+ bool
diff erentNamespace =
+ attrDialect && opDialect && attrDialect != opDialect;
+ std::string returnType =
diff erentNamespace
+ ? (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 @@ static void generateNamedOperandGetters(const Operator &op, Class &opClass,
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::genNamedOperandGetters() {
}
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 @@ void OpEmitter::genNamedResultGetters() {
// 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 @@ void OpEmitter::genBuilder() {
// use the first operand or attribute's type as all result types
// to facilitate
diff erent 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 @@ void OpEmitter::genBuilder() {
if (!shouldGenerateInferredTypeCollectiveParamBuilder())
genUseOperandAsResultTypeCollectiveParamBuilder();
}
- if (op.getTrait("OpTrait::FirstAttrDerivedResultType"))
+ if (op.getTrait("::mlir::OpTrait::FirstAttrDerivedResultType"))
genUseAttrAsResultTypeBuilder();
}
}
@@ -1435,7 +1447,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(OpMethodBody &body,
}
// 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 @@ void OpEmitter::genTypeInterfaceMethods() {
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 @@ void OpEmitter::genVerifier() {
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<CodeInit>(valueInit);
@@ -1904,21 +1916,21 @@ static void addSizeCountTrait(OpClass &opClass, StringRef traitKind,
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,21 @@ void OpEmitter::genTraits() {
// 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 +2055,7 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(const Operator &op)
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 +2138,11 @@ void OpOperandAdaptorEmitter::addVerification() {
// getODSOperands()/getODSResults() in the rest of the verifier.
for (auto &trait : op.getTraits()) {
if (auto *t = dyn_cast<tblgen::NativeOpTrait>(&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 +2157,7 @@ void OpOperandAdaptorEmitter::addVerification() {
"' op \"",
/*emitVerificationRequiringOp*/ false, verifyCtx, body);
- body << " return success();";
+ body << " return ::mlir::success();";
}
void OpOperandAdaptorEmitter::emitDecl(const Operator &op, raw_ostream &os) {
@@ -2165,6 +2178,7 @@ static void emitOpClasses(const std::vector<Record *> &defs, raw_ostream &os,
os << "#undef GET_OP_FWD_DEFINES\n";
for (auto *def : defs) {
Operator op(*def);
+ Operator::NamespaceEmitter emitter(os, op);
os << "class " << op.getCppClassName() << ";\n";
}
os << "#endif\n\n";
@@ -2173,6 +2187,7 @@ static void emitOpClasses(const std::vector<Record *> &defs, raw_ostream &os,
IfDefScope scope("GET_OP_CLASSES", os);
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
index 1542e9c55e41..5e1041357722 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -439,14 +439,14 @@ static bool shouldFormatSymbolNameAttr(const NamedAttribute *attr) {
/// {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 @@ const char *const optionalAttrParserCode = R"(
/// {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 @@ const char *const enumAttrParserCode = R"(
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 @@ const char *const optionalEnumAttrParserCode = R"(
"{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 optionalEnumAttrParserCode = R"(
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 @@ const char *const optionalOperandParserCode = R"(
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 optionalOperandParserCode = R"(
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 @@ const char *const operandParserCode = R"(
/// {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 @@ const char *const optionalTypeParserCode = R"(
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 typeParserCode = R"(
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 @@ const char *regionListParserCode = R"(
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 @@ const char *regionListEnsureTerminatorParserCode = R"(
/// {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 @@ const char *optionalRegionParserCode = R"(
/// {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 @@ const char *successorListParserCode = R"(
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 @@ const char *successorListParserCode = R"(
/// {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 @@ static void genCustomDirectiveParser(CustomDirective *dir, OpMethodBody &body) {
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 @@ void OperationFormat::genParser(Operator &op, OpClass &opClass) {
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 @@ void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
} else if (LiteralElement *literal = dyn_cast<LiteralElement>(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<AttributeVariable>(element)) {
@@ -1081,14 +1081,14 @@ void OperationFormat::genElementParser(Element *element, OpMethodBody &body,
body << " if (parser.parseOptionalAttrDict"
<< (attrDict->isWithKeyword() ? "WithKeyword" : "")
<< "(result.attributes))\n"
- << " return failure();\n";
+ << " return ::mlir::failure();\n";
} else if (auto *customDir = dyn_cast<CustomDirective>(element)) {
genCustomDirectiveParser(customDir, body);
} else if (isa<OperandsDirective>(element)) {
body << " ::llvm::SMLoc allOperandLoc = parser.getCurrentLocation();\n"
<< " if (parser.parseOperandList(allOperands))\n"
- << " return failure();\n";
+ << " return ::mlir::failure();\n";
} else if (isa<RegionsDirective>(element)) {
body << llvm::formatv(regionListParserCode, "full");
@@ -1197,7 +1197,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
if (allOperands) {
body << " if (parser.resolveOperands(allOperands, allOperandTypes, "
"allOperandLoc, result.operands))\n"
- " return failure();\n";
+ " return ::mlir::failure();\n";
return;
}
@@ -1214,7 +1214,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
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 @@ void OperationFormat::genParserTypeResolution(Operator &op,
}
body << ", allOperandLoc, result.operands))\n"
- << " return failure();\n";
+ << " return ::mlir::failure();\n";
return;
}
@@ -1270,7 +1270,7 @@ void OperationFormat::genParserTypeResolution(Operator &op,
// 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::genParserSuccessorResolution(Operator &op,
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 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
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 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
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::genElementPrinter(Element *element, OpMethodBody &body,
}
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 @@ class FormatParser {
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 @@ LogicalResult FormatParser::parse() {
while (curToken.getKind() != Token::eof) {
std::unique_ptr<Element> element;
if (failed(parseElement(element, /*isTopLevel=*/true)))
- return failure();
+ return ::mlir::failure();
fmt.elements.push_back(std::move(element));
}
@@ -2075,11 +2079,11 @@ LogicalResult FormatParser::parse() {
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 @@ LogicalResult FormatParser::verifyAttributes(llvm::SMLoc loc) {
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 @@ LogicalResult FormatParser::verifyAttributes(
if (auto *optional = dyn_cast<OptionalElement>(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 @@ LogicalResult FormatParser::verifyAttributes(
}
}
iteratorStack.pop_back();
- return success();
+ return ::mlir::success();
}
LogicalResult FormatParser::verifyOperands(
@@ -2193,13 +2197,13 @@ LogicalResult FormatParser::verifyOperands(
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 @@ LogicalResult FormatParser::verifyRegions(llvm::SMLoc loc) {
"' directive to the custom assembly format");
}
}
- return success();
+ return ::mlir::success();
}
LogicalResult FormatParser::verifyResults(
@@ -2219,7 +2223,7 @@ LogicalResult FormatParser::verifyResults(
llvm::StringMap<TypeResolutionInstance> &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 @@ LogicalResult FormatParser::verifyResults(
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 @@ LogicalResult FormatParser::verifySuccessors(llvm::SMLoc loc) {
"' directive to the custom assembly format");
}
}
- return success();
+ return ::mlir::success();
}
void FormatParser::handleAllTypesMatchConstraint(
@@ -2368,7 +2372,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (isTopLevel && !seenAttrs.insert(attr))
return emitError(loc, "attribute '" + name + "' is already bound");
element = std::make_unique<AttributeVariable>(attr);
- return success();
+ return ::mlir::success();
}
/// Operands
if (const NamedTypeConstraint *operand = findArg(op.getOperands(), name)) {
@@ -2377,7 +2381,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
return emitError(loc, "operand '" + name + "' is already bound");
}
element = std::make_unique<OperandVariable>(operand);
- return success();
+ return ::mlir::success();
}
/// Regions
if (const NamedRegion *region = findArg(op.getRegions(), name)) {
@@ -2386,14 +2390,14 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (hasAllRegions || !seenRegions.insert(region).second)
return emitError(loc, "region '" + name + "' is already bound");
element = std::make_unique<RegionVariable>(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<ResultVariable>(result);
- return success();
+ return ::mlir::success();
}
/// Successors.
if (const auto *successor = findArg(op.getSuccessors(), name)) {
@@ -2402,7 +2406,7 @@ LogicalResult FormatParser::parseVariable(std::unique_ptr<Element> &element,
if (hasAllSuccessors || !seenSuccessors.insert(successor).second)
return emitError(loc, "successor '" + name + "' is already bound");
element = std::make_unique<SuccessorVariable>(successor);
- return success();
+ return ::mlir::success();
}
return emitError(loc, "expected variable to refer to an argument, region, "
"result, or successor");
@@ -2450,7 +2454,7 @@ LogicalResult FormatParser::parseLiteral(std::unique_ptr<Element> &element) {
return emitError(literalTok.getLoc(), "expected valid literal");
element = std::make_unique<LiteralElement>(value);
- return success();
+ return ::mlir::success();
}
LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
@@ -2467,11 +2471,11 @@ LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
Optional<unsigned> 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 @@ LogicalResult FormatParser::parseOptional(std::unique_ptr<Element> &element,
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<TypeDirective>(ele.get())) {
if (failed(checkTypeOperand(typeEle->getOperand())))
- return failure();
+ return ::mlir::failure();
} else if (auto *typeEle = dyn_cast<FunctionalTypeDirective>(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<OptionalElement>(std::move(elements), *anchorIdx);
- return success();
+ return ::mlir::success();
}
LogicalResult FormatParser::parseOptionalChildElement(
@@ -2519,7 +2523,7 @@ LogicalResult FormatParser::parseOptionalChildElement(
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 @@ LogicalResult FormatParser::parseOptionalChildElement(
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 @@ LogicalResult FormatParser::parseOptionalChildElement(
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>([&](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 @@ LogicalResult FormatParser::parseOptionalChildElement(
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 @@ FormatParser::parseAttrDictDirective(std::unique_ptr<Element> &element,
hasAttrDict = true;
element = std::make_unique<AttrDictDirective>(withKeyword);
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2592,7 +2596,7 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
// 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 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
"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<std::unique_ptr<Element>> elements;
do {
if (failed(parseCustomDirectiveParameter(elements)))
- return failure();
+ return ::mlir::failure();
if (curToken.getKind() != Token::comma)
break;
consumeToken();
@@ -2615,7 +2619,7 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
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 @@ FormatParser::parseCustomDirective(std::unique_ptr<Element> &element,
element = std::make_unique<CustomDirective>(nameTok.getSpelling(),
std::move(elements));
- return success();
+ return ::mlir::success();
}
LogicalResult FormatParser::parseCustomDirectiveParameter(
@@ -2638,7 +2642,7 @@ LogicalResult FormatParser::parseCustomDirectiveParameter(
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<TypeDirective, AttributeVariable, OperandVariable, RegionVariable,
@@ -2646,7 +2650,7 @@ LogicalResult FormatParser::parseCustomDirectiveParameter(
return emitError(childLoc, "only variables and types may be used as "
"parameters to a custom directive");
}
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2664,10 +2668,10 @@ FormatParser::parseFunctionalTypeDirective(std::unique_ptr<Element> &element,
failed(parseToken(Token::comma, "expected ',' after inputs argument")) ||
failed(parseTypeDirectiveOperand(results)) ||
failed(parseToken(Token::r_paren, "expected ')' after argument list")))
- return failure();
+ return ::mlir::failure();
element = std::make_unique<FunctionalTypeDirective>(std::move(inputs),
std::move(results));
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2679,7 +2683,7 @@ FormatParser::parseOperandsDirective(std::unique_ptr<Element> &element,
fmt.allOperands = true;
}
element = std::make_unique<OperandsDirective>();
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2691,7 +2695,7 @@ FormatParser::parseRegionsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'regions' directive creates overlap in format");
hasAllRegions = true;
element = std::make_unique<RegionsDirective>();
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2701,7 +2705,7 @@ FormatParser::parseResultsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'results' directive can not be used as a "
"top-level directive");
element = std::make_unique<ResultsDirective>();
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2714,7 +2718,7 @@ FormatParser::parseSuccessorsDirective(std::unique_ptr<Element> &element,
return emitError(loc, "'successors' directive creates overlap in format");
hasAllSuccessors = true;
element = std::make_unique<SuccessorsDirective>();
- return success();
+ return ::mlir::success();
}
LogicalResult
@@ -2728,16 +2732,16 @@ FormatParser::parseTypeDirective(std::unique_ptr<Element> &element, Token tok,
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<TypeDirective>(std::move(operand));
- return success();
+ return ::mlir::success();
}
LogicalResult
FormatParser::parseTypeDirectiveOperand(std::unique_ptr<Element> &element) {
llvm::SMLoc loc = curToken.getLoc();
if (failed(parseElement(element, /*isTopLevel=*/false)))
- return failure();
+ return ::mlir::failure();
if (isa<LiteralElement>(element.get()))
return emitError(
loc, "'type' directive operand expects variable or directive operand");
@@ -2765,7 +2769,7 @@ FormatParser::parseTypeDirectiveOperand(std::unique_ptr<Element> &element) {
} 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
index 9884d1ccb077..9b2f35f56624 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -887,8 +887,9 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex,
// 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
More information about the flang-commits
mailing list