Skip to content

Commit 10661ba

Browse files
authored
[CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td
This adds no real content, it just incrementally adds some scaffolding necessary to enable a future patch to just add our first few ops. Test Plan: ``` $ cmake -Sllvm -Bbuild -DCLANG_ENABLE_CIR=1 \ -DLLVM_ENABLE_PROJECTS='clang;mlir' \ -DCMAKE_BUILD_TYPE=Release -GNinja $ ninja -C build check-clang $ ninja -C build MLIRCIROpsIncGen $ ninja -C build MLIRCIR ``` Reviewers: AaronBallman, erichkeane, bcardosolopes Reviewed By: erichkeane, AaronBallman, bcardosolopes Pull Request: #86080
1 parent d6cc8d4 commit 10661ba

File tree

11 files changed

+127
-0
lines changed

11 files changed

+127
-0
lines changed

clang/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ if(CLANG_ENABLE_LIBXML2)
166166
endif()
167167

168168
if(CLANG_ENABLE_CIR)
169+
if (CLANG_BUILT_STANDALONE)
170+
message(FATAL_ERROR
171+
"ClangIR is not yet supported in the standalone build.")
172+
endif()
169173
if (NOT "${LLVM_ENABLE_PROJECTS}" MATCHES "MLIR|mlir")
170174
message(FATAL_ERROR
171175
"Cannot build ClangIR without MLIR in LLVM_ENABLE_PROJECTS")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --includedir
2+
set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
3+
include_directories(${MLIR_INCLUDE_DIR})
4+
include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
5+
6+
add_subdirectory(Dialect)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===- CIRDialect.h - CIR dialect -------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the CIR dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
14+
#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
15+
16+
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===- CIRDialect.td - CIR dialect -------------------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the CIR dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
14+
#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
15+
16+
include "mlir/IR/OpBase.td"
17+
18+
def CIR_Dialect : Dialect {
19+
let name = "cir";
20+
21+
// A short one-line summary of our dialect.
22+
let summary = "A high-level dialect for analyzing and optimizing Clang "
23+
"supported languages";
24+
25+
let cppNamespace = "::mlir::cir";
26+
27+
let useDefaultAttributePrinterParser = 0;
28+
let useDefaultTypePrinterParser = 0;
29+
30+
let extraClassDeclaration = [{
31+
void registerAttributes();
32+
void registerTypes();
33+
34+
Type parseType(DialectAsmParser &parser) const override;
35+
void printType(Type type, DialectAsmPrinter &printer) const override;
36+
37+
Attribute parseAttribute(DialectAsmParser &parser,
38+
Type type) const override;
39+
40+
void printAttribute(Attribute attr, DialectAsmPrinter &os) const override;
41+
}];
42+
}
43+
44+
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- CIROps.td - CIR dialect definition -----------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Definition of the CIR dialect
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIROPS
15+
#define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
16+
17+
include "clang/CIR/Dialect/IR/CIRDialect.td"
18+
19+
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIROPS
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This replicates part of the add_mlir_dialect cmake function from MLIR that
2+
# cannot be used here. This happens because it expects to be run inside MLIR
3+
# directory which is not the case for CIR (and also FIR, both have similar
4+
# workarounds).
5+
6+
# Equivalent to add_mlir_dialect(CIROps cir)
7+
set(LLVM_TARGET_DEFINITIONS CIROps.td)
8+
mlir_tablegen(CIROps.h.inc -gen-op-decls)
9+
mlir_tablegen(CIROps.cpp.inc -gen-op-defs)
10+
mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls)
11+
mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs)
12+
mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls)
13+
mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
14+
add_public_tablegen_target(MLIRCIROpsIncGen)
15+
add_dependencies(mlir-headers MLIRCIROpsIncGen)
16+

clang/lib/CIR/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
2+
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
3+
4+
add_subdirectory(Dialect)

clang/lib/CIR/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements the CIR dialect and its operations.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <clang/CIR/Dialect/IR/CIRDialect.h>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_clang_library(MLIRCIR
2+
CIRDialect.cpp
3+
)

0 commit comments

Comments
 (0)