[Mlir-commits] [mlir] 4ff440b - [mlir] Change custom syntax of emitc.include op to resemble C
Marius Brehler
llvmlistbot at llvm.org
Mon Jul 5 07:42:00 PDT 2021
Author: Simon Camphausen
Date: 2021-07-05T16:40:05+02:00
New Revision: 4ff440b0efb0a9dbfd6786d16e6e5d4dfeca2bde
URL: https://github.com/llvm/llvm-project/commit/4ff440b0efb0a9dbfd6786d16e6e5d4dfeca2bde
DIFF: https://github.com/llvm/llvm-project/commit/4ff440b0efb0a9dbfd6786d16e6e5d4dfeca2bde.diff
LOG: [mlir] Change custom syntax of emitc.include op to resemble C
This changes the custom syntax of the emitc.include operation for standard includes.
Reviewed By: marbre
Differential Revision: https://reviews.llvm.org/D105281
Added:
Modified:
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/test/Dialect/EmitC/ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 78c682a806710..93e67f34547bf 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -126,12 +126,15 @@ def EmitC_IncludeOp
```mlir
// Custom form defining the inclusion of `<myheader>`.
- emitc.include "myheader.h" is_standard_include
+ emitc.include <"myheader.h">
// Generic form of the same operation.
"emitc.include" (){include = "myheader.h", is_standard_include} : () -> ()
- // Generic form defining the inclusion of `"myheader"`.
+ // Custom form defining the inclusion of `"myheader"`.
+ emitc.include "myheader.h"
+
+ // Generic form of the same operation.
"emitc.include" (){include = "myheader.h"} : () -> ()
```
}];
@@ -139,9 +142,8 @@ def EmitC_IncludeOp
Arg<StrAttr, "source file to include">:$include,
UnitAttr:$is_standard_include
);
- let assemblyFormat = [{
- $include attr-dict (`is_standard_include` $is_standard_include^)?
- }];
+ let printer = [{ return ::print(p, *this); }];
+ let parser = [{ return ::parse$cppClass(parser, result); }];
let verifier = ?;
}
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index c0fa74908c40e..e99eb7b9afb2a 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -116,6 +116,41 @@ OpFoldResult emitc::ConstantOp::fold(ArrayRef<Attribute> operands) {
return value();
}
+//===----------------------------------------------------------------------===//
+// IncludeOp
+//===----------------------------------------------------------------------===//
+
+static void print(OpAsmPrinter &p, IncludeOp &op) {
+ bool standardInclude = op.is_standard_include();
+
+ p << IncludeOp::getOperationName() << " ";
+ if (standardInclude)
+ p << "<";
+ p << "\"" << op.include() << "\"";
+ if (standardInclude)
+ p << ">";
+}
+
+static ParseResult parseIncludeOp(OpAsmParser &parser, OperationState &result) {
+ bool standardInclude = !parser.parseOptionalLess();
+
+ StringAttr include;
+ OptionalParseResult includeParseResult =
+ parser.parseOptionalAttribute(include, "include", result.attributes);
+ if (!includeParseResult.hasValue())
+ return parser.emitError(parser.getNameLoc()) << "expected string attribute";
+
+ if (standardInclude && parser.parseOptionalGreater())
+ return parser.emitError(parser.getNameLoc())
+ << "expected trailing '>' for standard include";
+
+ if (standardInclude)
+ result.addAttribute("is_standard_include",
+ UnitAttr::get(parser.getBuilder().getContext()));
+
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/EmitC/ops.mlir b/mlir/test/Dialect/EmitC/ops.mlir
index 3a48ff447e1cb..25d6f2adf90af 100644
--- a/mlir/test/Dialect/EmitC/ops.mlir
+++ b/mlir/test/Dialect/EmitC/ops.mlir
@@ -1,7 +1,7 @@
-// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
-"emitc.include" (){include = "test.h", is_standard_include} : () -> ()
-emitc.include "test.h" is_standard_include
+emitc.include <"test.h">
+emitc.include "test.h"
// CHECK-LABEL: func @f(%{{.*}}: i32, %{{.*}}: !emitc.opaque<"int32_t">) {
func @f(%arg0: i32, %f: !emitc.opaque<"int32_t">) {
More information about the Mlir-commits
mailing list