From e4034881c3537d914b3208ddcf8200fb437073c8 Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Mon, 31 May 2021 21:23:32 +0530 Subject: [PATCH] [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 --- mlir/include/mlir/Dialect/StandardOps/IR/Ops.h | 2 ++ mlir/include/mlir/Dialect/StandardOps/IR/Ops.td | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.h b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.h index 7d3c72349bf8..65cac17098c8 100644 --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.h +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.h @@ -41,12 +41,14 @@ class PatternRewriter; /// with `b` at location `loc`. SmallVector 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. /// diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td index 74efd0f7960c..8f863978456c 100644 --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -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.