[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
https://github.com/lanza created https://github.com/llvm/llvm-project/pull/90831 None >From e57548737a72c5308e23fb442774b9bd9eca0bfa Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Thu, 2 May 2024 07:55:36 + Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5 --- clang/include/clang/CIR/CIRGenerator.h| 28 + .../clang/CIRFrontendAction/CIRGenAction.h| 62 +++ clang/lib/CIR/CMakeLists.txt | 2 + clang/lib/CIR/CodeGen/CIRGenModule.cpp| 21 +++ clang/lib/CIR/CodeGen/CIRGenModule.h | 42 + clang/lib/CIR/CodeGen/CIRGenTypeCache.h | 28 + clang/lib/CIR/CodeGen/CIRGenerator.cpp| 26 clang/lib/CIR/CodeGen/CMakeLists.txt | 23 +++ clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 46 ++ clang/lib/CIR/FrontendAction/CMakeLists.txt | 12 clang/lib/FrontendTool/CMakeLists.txt | 9 +++ .../ExecuteCompilerInvocation.cpp | 17 + 12 files changed, 316 insertions(+) create mode 100644 clang/include/clang/CIR/CIRGenerator.h create mode 100644 clang/include/clang/CIRFrontendAction/CIRGenAction.h create mode 100644 clang/lib/CIR/CodeGen/CIRGenModule.cpp create mode 100644 clang/lib/CIR/CodeGen/CIRGenModule.h create mode 100644 clang/lib/CIR/CodeGen/CIRGenTypeCache.h create mode 100644 clang/lib/CIR/CodeGen/CIRGenerator.cpp create mode 100644 clang/lib/CIR/CodeGen/CMakeLists.txt create mode 100644 clang/lib/CIR/FrontendAction/CIRGenAction.cpp create mode 100644 clang/lib/CIR/FrontendAction/CMakeLists.txt diff --git a/clang/include/clang/CIR/CIRGenerator.h b/clang/include/clang/CIR/CIRGenerator.h new file mode 100644 index 00..c910f02698f41f --- /dev/null +++ b/clang/include/clang/CIR/CIRGenerator.h @@ -0,0 +1,28 @@ +//===- CIRGenerator.h - CIR Generation from Clang AST -===// +// +// 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 a simple interface to perform CIR generation from Clang +// AST +// +//===--===// + +#ifndef CLANG_CIRGENERATOR_H_ +#define CLANG_CIRGENERATOR_H_ + +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/DeclGroup.h" + +namespace cir { +class CIRGenerator : public clang::ASTConsumer { +public: + bool HandleTopLevelDecl(clang::DeclGroupRef D) override; +}; + +} // namespace cir + +#endif // CLANG_CIRGENERATOR_H_ diff --git a/clang/include/clang/CIRFrontendAction/CIRGenAction.h b/clang/include/clang/CIRFrontendAction/CIRGenAction.h new file mode 100644 index 00..02c906b173f52b --- /dev/null +++ b/clang/include/clang/CIRFrontendAction/CIRGenAction.h @@ -0,0 +1,62 @@ +//=== CIRGenAction.h - CIR Code Generation Frontend Action -*- 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 +// +//===--===// + +#ifndef LLVM_CLANG_CIR_CIRGENACTION_H +#define LLVM_CLANG_CIR_CIRGENACTION_H + +#include "clang/Frontend/FrontendAction.h" + +namespace mlir { +class MLIRContext; +class ModuleOp; +template class OwningOpRef; +} // namespace mlir + +namespace cir { + +class CIRGenAction : public clang::ASTFrontendAction { +public: + enum class OutputType { +EmitCIR, + }; + +private: + friend class CIRGenConsumer; + + // TODO: this is redundant but just using the OwningModuleRef requires more of + // clang against MLIR. Hide this somewhere else. + std::unique_ptr> mlirModule; + + mlir::MLIRContext *mlirContext; + +protected: + CIRGenAction(OutputType action, mlir::MLIRContext *mlirContext = nullptr); + + void foo() { + + } + + std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &CI, +llvm::StringRef InFile) override; + +public: + ~CIRGenAction() override; + OutputType action; +}; + +class EmitCIRAction : public CIRGenAction { + virtual void anchor(); + +public: + EmitCIRAction(mlir::MLIRContext *mlirCtx = nullptr); +}; + +} // namespace cir + +#endif diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt index d2ff200e0da5f5..11cca734808dfa 100644 --- a/clang/lib/CIR/CMakeLists.txt +++ b/clang/lib/CIR/CMakeLists.txt @@ -2,3 +2,5 @@ include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) add_subdirectory(Dialect) +add_subdirect
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
https://github.com/lanza converted_to_draft https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nathan Lanza (lanza) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/90831.diff 12 Files Affected: - (added) clang/include/clang/CIR/CIRGenerator.h (+28) - (added) clang/include/clang/CIRFrontendAction/CIRGenAction.h (+62) - (modified) clang/lib/CIR/CMakeLists.txt (+2) - (added) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+21) - (added) clang/lib/CIR/CodeGen/CIRGenModule.h (+42) - (added) clang/lib/CIR/CodeGen/CIRGenTypeCache.h (+28) - (added) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+26) - (added) clang/lib/CIR/CodeGen/CMakeLists.txt (+23) - (added) clang/lib/CIR/FrontendAction/CIRGenAction.cpp (+46) - (added) clang/lib/CIR/FrontendAction/CMakeLists.txt (+12) - (modified) clang/lib/FrontendTool/CMakeLists.txt (+9) - (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+17) ``diff diff --git a/clang/include/clang/CIR/CIRGenerator.h b/clang/include/clang/CIR/CIRGenerator.h new file mode 100644 index 00..c910f02698f41f --- /dev/null +++ b/clang/include/clang/CIR/CIRGenerator.h @@ -0,0 +1,28 @@ +//===- CIRGenerator.h - CIR Generation from Clang AST -===// +// +// 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 a simple interface to perform CIR generation from Clang +// AST +// +//===--===// + +#ifndef CLANG_CIRGENERATOR_H_ +#define CLANG_CIRGENERATOR_H_ + +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/DeclGroup.h" + +namespace cir { +class CIRGenerator : public clang::ASTConsumer { +public: + bool HandleTopLevelDecl(clang::DeclGroupRef D) override; +}; + +} // namespace cir + +#endif // CLANG_CIRGENERATOR_H_ diff --git a/clang/include/clang/CIRFrontendAction/CIRGenAction.h b/clang/include/clang/CIRFrontendAction/CIRGenAction.h new file mode 100644 index 00..02c906b173f52b --- /dev/null +++ b/clang/include/clang/CIRFrontendAction/CIRGenAction.h @@ -0,0 +1,62 @@ +//=== CIRGenAction.h - CIR Code Generation Frontend Action -*- 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 +// +//===--===// + +#ifndef LLVM_CLANG_CIR_CIRGENACTION_H +#define LLVM_CLANG_CIR_CIRGENACTION_H + +#include "clang/Frontend/FrontendAction.h" + +namespace mlir { +class MLIRContext; +class ModuleOp; +template class OwningOpRef; +} // namespace mlir + +namespace cir { + +class CIRGenAction : public clang::ASTFrontendAction { +public: + enum class OutputType { +EmitCIR, + }; + +private: + friend class CIRGenConsumer; + + // TODO: this is redundant but just using the OwningModuleRef requires more of + // clang against MLIR. Hide this somewhere else. + std::unique_ptr> mlirModule; + + mlir::MLIRContext *mlirContext; + +protected: + CIRGenAction(OutputType action, mlir::MLIRContext *mlirContext = nullptr); + + void foo() { + + } + + std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &CI, +llvm::StringRef InFile) override; + +public: + ~CIRGenAction() override; + OutputType action; +}; + +class EmitCIRAction : public CIRGenAction { + virtual void anchor(); + +public: + EmitCIRAction(mlir::MLIRContext *mlirCtx = nullptr); +}; + +} // namespace cir + +#endif diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt index d2ff200e0da5f5..11cca734808dfa 100644 --- a/clang/lib/CIR/CMakeLists.txt +++ b/clang/lib/CIR/CMakeLists.txt @@ -2,3 +2,5 @@ include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include) include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include) add_subdirectory(Dialect) +add_subdirectory(CodeGen) +add_subdirectory(FrontendAction) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp new file mode 100644 index 00..c9ed81a749cd2b --- /dev/null +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -0,0 +1,21 @@ +//===- CIRGenModule.cpp - Per-Module state for CIR generation -===// +// +// 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 is the internal per-translation-unit state used for CIR translation. +// +//===--===// + +#include "CIRGenModule.h" + +#include "c
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff e3f42b02a4129947ca2dd820bfb63ffed83027b7 e57548737a72c5308e23fb442774b9bd9eca0bfa -- clang/include/clang/CIR/CIRGenerator.h clang/include/clang/CIRFrontendAction/CIRGenAction.h clang/lib/CIR/CodeGen/CIRGenModule.cpp clang/lib/CIR/CodeGen/CIRGenModule.h clang/lib/CIR/CodeGen/CIRGenTypeCache.h clang/lib/CIR/CodeGen/CIRGenerator.cpp clang/lib/CIR/FrontendAction/CIRGenAction.cpp clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/CIRFrontendAction/CIRGenAction.h b/clang/include/clang/CIRFrontendAction/CIRGenAction.h index 02c906b173..a12f149b82 100644 --- a/clang/include/clang/CIRFrontendAction/CIRGenAction.h +++ b/clang/include/clang/CIRFrontendAction/CIRGenAction.h @@ -37,9 +37,7 @@ private: protected: CIRGenAction(OutputType action, mlir::MLIRContext *mlirContext = nullptr); - void foo() { - - } + void foo() {} std::unique_ptr CreateASTConsumer(clang::CompilerInstance &CI, diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index c9ed81a749..abf3d15dbc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -17,5 +17,4 @@ using namespace cir; // Emit code for a single top level declaration. -void CIRGenModule::buildTopLevelDecl(Decl *decl) { -} +void CIRGenModule::buildTopLevelDecl(Decl *decl) {} diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index 4fbd441b7a..2f07d6ce72 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -15,10 +15,10 @@ #include "CIRGenTypeCache.h" +#include "mlir/IR/MLIRContext.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/Diagnostic.h" -#include "mlir/IR/MLIRContext.h" using namespace clang; namespace cir { diff --git a/clang/lib/CIR/CodeGen/CIRGenTypeCache.h b/clang/lib/CIR/CodeGen/CIRGenTypeCache.h index e23c6b0531..f4e6de5554 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypeCache.h +++ b/clang/lib/CIR/CodeGen/CIRGenTypeCache.h @@ -20,7 +20,6 @@ namespace cir { /// constructor and then copied around into new CIRGenFunction's. struct CIRGenTypeCache { CIRGenTypeCache() {} - }; } // namespace cir diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 5d75ad1c15..c3312e63c5 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -6,8 +6,8 @@ // //===--===// -#include "clang/CIR/CIRGenerator.h" #include "clang/CIRFrontendAction/CIRGenAction.h" +#include "clang/CIR/CIRGenerator.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/MLIRContext.h" diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index ff1216992c..563e8473f4 100644 --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -67,7 +67,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) { case EmitAssembly: return std::make_unique(); case EmitBC: return std::make_unique(); #if CLANG_ENABLE_CIR - case EmitCIR:return std::make_unique<::cir::EmitCIRAction>(); + case EmitCIR: +return std::make_unique<::cir::EmitCIRAction>(); #else case EmitCIR: llvm_unreachable("CIR suppport not built into clang"); `` https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
https://github.com/bcardosolopes edited https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
@@ -0,0 +1,62 @@ +//=== CIRGenAction.h - CIR Code Generation Frontend Action -*- 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 +// +//===--===// + +#ifndef LLVM_CLANG_CIR_CIRGENACTION_H +#define LLVM_CLANG_CIR_CIRGENACTION_H + +#include "clang/Frontend/FrontendAction.h" + +namespace mlir { +class MLIRContext; +class ModuleOp; +template class OwningOpRef; +} // namespace mlir + +namespace cir { + +class CIRGenAction : public clang::ASTFrontendAction { +public: + enum class OutputType { +EmitCIR, + }; + +private: + friend class CIRGenConsumer; + + // TODO: this is redundant but just using the OwningModuleRef requires more of + // clang against MLIR. Hide this somewhere else. + std::unique_ptr> mlirModule; + + mlir::MLIRContext *mlirContext; + +protected: + CIRGenAction(OutputType action, mlir::MLIRContext *mlirContext = nullptr); + + void foo() { bcardosolopes wrote: What is this about? https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
@@ -0,0 +1,42 @@ +//===--- CIRGenModule.h - Per-Module state for CIR gen --*- 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 is the internal per-translation-unit state used for CIR translation. +// +//===--===// + +#ifndef LLVM_CLANG_LIB_CODEGEN_CIRGENMODULE_H +#define LLVM_CLANG_LIB_CODEGEN_CIRGENMODULE_H + +#include "CIRGenTypeCache.h" + +#include "clang/AST/ASTContext.h" +#include "clang/Basic/CodeGenOptions.h" +#include "clang/Basic/Diagnostic.h" +#include "mlir/IR/MLIRContext.h" + +using namespace clang; +namespace cir { +/// Implementation of a CIR/MLIR emission from Clang AST. +/// +/// This will emit operations that are specific to C(++)/ObjC(++) language, +/// preserving the semantics of the language and (hopefully) allow to perform bcardosolopes wrote: perhaps remove the "hopefully" and just have a more solid statement https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
@@ -0,0 +1,62 @@ +//=== CIRGenAction.h - CIR Code Generation Frontend Action -*- 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 +// +//===--===// + +#ifndef LLVM_CLANG_CIR_CIRGENACTION_H +#define LLVM_CLANG_CIR_CIRGENACTION_H + +#include "clang/Frontend/FrontendAction.h" + +namespace mlir { +class MLIRContext; +class ModuleOp; +template class OwningOpRef; +} // namespace mlir + +namespace cir { + +class CIRGenAction : public clang::ASTFrontendAction { +public: + enum class OutputType { +EmitCIR, + }; + +private: + friend class CIRGenConsumer; + + // TODO: this is redundant but just using the OwningModuleRef requires more of + // clang against MLIR. Hide this somewhere else. + std::unique_ptr> mlirModule; bcardosolopes wrote: The original comment is from 2 years ago, any idea why is still relevant? https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
@@ -0,0 +1,28 @@ +//===--- CIRGenTypeCache.h - Commonly used LLVM types and info -*- 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 structure provides a set of common types useful during CIR emission. +// +//===--===// + +#ifndef LLVM_CLANG_LIB_CIR_CODEGENTYPECACHE_H +#define LLVM_CLANG_LIB_CIR_CODEGENTYPECACHE_H + +namespace cir { + +/// This structure provides a set of types that are commonly used +/// during IR emission. It's initialized once in CodeGenModule's +/// constructor and then copied around into new CIRGenFunction's. +struct CIRGenTypeCache { + CIRGenTypeCache() {} + bcardosolopes wrote: Tie this up? https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cirgenmodule buildtopleveldecl husk (PR #90831)
https://github.com/bcardosolopes commented: Perhaps add a `-emit-cir` testcase that doesn't test anything but just proves the wiring works. More comments inline. https://github.com/llvm/llvm-project/pull/90831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits