[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)

Nathan Lanza via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 17 12:00:04 PDT 2024


https://github.com/lanza updated https://github.com/llvm/llvm-project/pull/86080

>From 435869501bb0788d8b22d847c3a870dbfbf94126 Mon Sep 17 00:00:00 2001
From: Nathan Lanza <nathanlanza at gmail.com>
Date: Thu, 21 Mar 2024 04:57:16 +0000
Subject: [PATCH 1/3] fix MLIRCIROpsIncGen

Created using spr 1.3.5
---
 .../clang/CIR/Dialect/IR/CIRDialect.td        | 46 +++++++++++++++++++
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 18 ++++++++
 2 files changed, 64 insertions(+)
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRDialect.td

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
new file mode 100644
index 00000000000000..8f756fa422e5f3
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td
@@ -0,0 +1,46 @@
+//===- CIRTypes.td - CIR dialect types ---------------------*- 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 CIR dialect.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_CIR_DIALECT_CIR
+#define MLIR_CIR_DIALECT_CIR
+
+include "mlir/IR/OpBase.td"
+
+def CIR_Dialect : Dialect {
+  let name = "cir";
+
+  // A short one-line summary of our dialect.
+  let summary = "A high-level dialect for analyzing and optimizing Clang "
+                "supported languages";
+
+  let cppNamespace = "::mlir::cir";
+
+  let useDefaultAttributePrinterParser = 0;
+  let useDefaultTypePrinterParser = 0;
+
+  let extraClassDeclaration = [{
+    void registerAttributes();
+    void registerTypes();
+
+    ::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override;
+    void printType(::mlir::Type type,
+                   ::mlir::DialectAsmPrinter &printer) const override;
+
+    ::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser,
+                                     ::mlir::Type type) const override;
+
+    void printAttribute(::mlir::Attribute attr,
+                        ::mlir::DialectAsmPrinter &os) const override;
+  }];
+}
+
+#endif // MLIR_CIR_DIALECT_CIR
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index e69de29bb2d1d6..cfc62986b0b9d1 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -0,0 +1,18 @@
+//===-- CIROps.td - CIR dialect definition -----------------*- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of the CIR dialect
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_CIR_DIALECT_CIR_OPS
+#define MLIR_CIR_DIALECT_CIR_OPS
+
+include "clang/CIR/Dialect/IR/CIRDialect.td"
+#endif // MLIR_CIR_DIALECT_CIR_OPS

>From fe44284534be0752d95634251289a5c74c06afe7 Mon Sep 17 00:00:00 2001
From: Nathan Lanza <nathanlanza at gmail.com>
Date: Thu, 21 Mar 2024 05:12:26 +0000
Subject: [PATCH 2/3] add some guts to CIRDialect.cpp and MLIRCIR lib

Created using spr 1.3.5
---
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 11 +++++++++++
 clang/lib/CIR/Dialect/IR/CMakeLists.txt |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index e69de29bb2d1d6..8abf39119e04f7 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -0,0 +1,11 @@
+//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===//
+//
+// 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 implements the CIR dialect and its operations.
+//
+//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
index e69de29bb2d1d6..0d7476b555705d 100644
--- a/clang/lib/CIR/Dialect/IR/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_clang_library(MLIRCIR
+  CIRDialect.cpp
+  )

>From 0e195548f24fb3748e22141739f914676b1d56d5 Mon Sep 17 00:00:00 2001
From: Nathan Lanza <nathanlanza at gmail.com>
Date: Wed, 17 Apr 2024 18:59:53 +0000
Subject: [PATCH 3/3] include dialect and add include guards

Created using spr 1.3.5
---
 clang/include/clang/CIR/Dialect/IR/CIRDialect.h | 5 +++++
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp         | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
index 3467c3511620f2..d53e5d1663d62a 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h
@@ -9,3 +9,8 @@
 // This file declares the CIR dialect.
 //
 //===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
+#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
+
+#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 8abf39119e04f7..c2829c3ff2af8c 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -9,3 +9,5 @@
 // This file implements the CIR dialect and its operations.
 //
 //===----------------------------------------------------------------------===//
+
+#include <clang/CIR/Dialect/IR/CIRDialect.h>



More information about the llvm-branch-commits mailing list