[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: https://github.com/llvm/llvm-project/pull/86080
This commit is contained in:
Nathan Lanza 2024-04-24 22:26:40 -04:00 committed by GitHub
parent d6cc8d45b3
commit 10661ba240
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 127 additions and 0 deletions

View file

@ -166,6 +166,10 @@ if(CLANG_ENABLE_LIBXML2)
endif()
if(CLANG_ENABLE_CIR)
if (CLANG_BUILT_STANDALONE)
message(FATAL_ERROR
"ClangIR is not yet supported in the standalone build.")
endif()
if (NOT "${LLVM_ENABLE_PROJECTS}" MATCHES "MLIR|mlir")
message(FATAL_ERROR
"Cannot build ClangIR without MLIR in LLVM_ENABLE_PROJECTS")

View file

@ -0,0 +1,6 @@
set(MLIR_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --includedir
set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
include_directories(${MLIR_INCLUDE_DIR})
include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
add_subdirectory(Dialect)

View file

@ -0,0 +1 @@
add_subdirectory(IR)

View file

@ -0,0 +1,16 @@
//===- CIRDialect.h - CIR dialect -------------------------------*- C++ -*-===//
//
// 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 LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT_H

View file

@ -0,0 +1,44 @@
//===- CIRDialect.td - CIR dialect -------------------------*- 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 LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT
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();
Type parseType(DialectAsmParser &parser) const override;
void printType(Type type, DialectAsmPrinter &printer) const override;
Attribute parseAttribute(DialectAsmParser &parser,
Type type) const override;
void printAttribute(Attribute attr, DialectAsmPrinter &os) const override;
}];
}
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT

View file

@ -0,0 +1,19 @@
//===-- 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 LLVM_CLANG_CIR_DIALECT_IR_CIROPS
#define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
include "clang/CIR/Dialect/IR/CIRDialect.td"
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIROPS

View file

@ -0,0 +1,16 @@
# This replicates part of the add_mlir_dialect cmake function from MLIR that
# cannot be used here. This happens because it expects to be run inside MLIR
# directory which is not the case for CIR (and also FIR, both have similar
# workarounds).
# Equivalent to add_mlir_dialect(CIROps cir)
set(LLVM_TARGET_DEFINITIONS CIROps.td)
mlir_tablegen(CIROps.h.inc -gen-op-decls)
mlir_tablegen(CIROps.cpp.inc -gen-op-defs)
mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls)
mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs)
mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls)
mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
add_public_tablegen_target(MLIRCIROpsIncGen)
add_dependencies(mlir-headers MLIRCIROpsIncGen)

View file

@ -0,0 +1,4 @@
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
add_subdirectory(Dialect)

View file

@ -0,0 +1 @@
add_subdirectory(IR)

View file

@ -0,0 +1,13 @@
//===- 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.
//
//===----------------------------------------------------------------------===//
#include <clang/CIR/Dialect/IR/CIRDialect.h>

View file

@ -0,0 +1,3 @@
add_clang_library(MLIRCIR
CIRDialect.cpp
)