[MLIR] Specify namespace for standard dialect using cppNamespace field

The `::mlir` namespace for operations from standard is currently
defined by enclosing the header file generated from the ODS in
`Ops.td` in a namespace in `Ops.h`. However, when referencing
operations from `Ops.td` in other TableGen files, this causes the
generated C++ code to refer to classes from the global namespace
instead of `::mlir`.

By defining the namespace through the `cppNamespace` field for
`StandardOps_Dialect` directly in `Ops.td` instead, the ODS
becomes reusable in other TableGen files through simple
inclusion.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D103234
This commit is contained in:
Andi Drebes 2021-05-31 21:23:32 +05:30 committed by Arjun P
parent 2c3afa3237
commit e4034881c3
2 changed files with 3 additions and 1 deletions

View File

@ -41,12 +41,14 @@ class PatternRewriter;
/// with `b` at location `loc`.
SmallVector<Range, 8> getOrCreateRanges(OffsetSizeAndStrideOpInterface op,
OpBuilder &b, Location loc);
} // namespace mlir
#define GET_OP_CLASSES
#include "mlir/Dialect/StandardOps/IR/Ops.h.inc"
#include "mlir/Dialect/StandardOps/IR/OpsDialect.h.inc"
namespace mlir {
/// This is a refinement of the "constant" op for the case where it is
/// returning a float value of FloatType.
///

View File

@ -25,7 +25,7 @@ include "mlir/Interfaces/ViewLikeInterface.td"
def StandardOps_Dialect : Dialect {
let name = "std";
let cppNamespace = "";
let cppNamespace = "::mlir";
let hasConstantMaterializer = 1;
// TODO: This dependency is needed to handle memref ops in the
// canonicalize pass and should be resolved.