[Mlir-commits] [mlir] [mlir][emitc] make CExpression trait into interface (PR #142771)
Simon Camphausen
llvmlistbot at llvm.org
Sat Jun 14 03:49:42 PDT 2025
================
@@ -0,0 +1,48 @@
+//===- EmitCInterfaces.td - EmitC Interfaces ---------------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the interfaces used by EmitC.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_EMITC_IR_EMITCINTERFACES
+#define MLIR_DIALECT_EMITC_IR_EMITCINTERFACES
+
+include "mlir/IR/OpBase.td"
+
+def CExpressionInterface : OpInterface<"CExpressionInterface"> {
+ let description = [{
+ Interface to mark operations that can be part of the CExpression.
+ }];
+
+ let cppNamespace = "::mlir::emitc";
+ let methods = [
+ InterfaceMethod<[{
+ Check whether operation has side effects that may affect the expression
+ evaluation.
+
+ By default operation is marked as not having any side effects.
+
+ ```c++
+ class ConcreteOp ... {
+ public:
+ bool hasSideEffects() {
+ // That way we can override the default implementation.
+ return true;
+ }
+ };
+ ```
+ }],
+ "bool", "hasSideEffects", (ins), /*methodBody=*/[{}],
+ /*defaultImplementation=*/[{
+ return false;
----------------
simon-camp wrote:
Can you make this return true by default? Then you can add and implement the interface directly on `EmitC_UnaryOp` and `EmitC_BinaryOp` to override the default.
https://github.com/llvm/llvm-project/pull/142771
More information about the Mlir-commits
mailing list