clang 24.0.0git
CIRGenerator.h
Go to the documentation of this file.
1//===- CIRGenerator.h - CIR Generation from Clang AST ---------------------===//
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 a simple interface to perform CIR generation from Clang
10// AST
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_CIR_CIRGENERATOR_H
15#define LLVM_CLANG_CIR_CIRGENERATOR_H
16
19
20#include "llvm/ADT/IntrusiveRefCntPtr.h"
21#include "llvm/Support/VirtualFileSystem.h"
22
23#include <memory>
24
25namespace clang {
26class DeclGroupRef;
28namespace CIRGen {
29class CIRGenModule;
30} // namespace CIRGen
31} // namespace clang
32
33namespace mlir {
34class MLIRContext;
35class ModuleOp;
36} // namespace mlir
37namespace cir {
39 virtual void anchor();
41 clang::ASTContext *astContext;
42 // Only used for debug info.
44
45 const clang::CodeGenOptions &codeGenOpts;
46
47 unsigned handlingTopLevelDecls;
48
49 /// Use this when emitting decls to block re-entrant decl emission. It will
50 /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl
51 /// emission must be deferred longer, like at the end of a tag definition.
52 struct HandlingTopLevelDeclRAII {
53 CIRGenerator &self;
54 bool emitDeferred;
55 HandlingTopLevelDeclRAII(CIRGenerator &self, bool emitDeferred = true)
56 : self{self}, emitDeferred{emitDeferred} {
57 ++self.handlingTopLevelDecls;
58 }
59 ~HandlingTopLevelDeclRAII() {
60 unsigned Level = --self.handlingTopLevelDecls;
61 if (Level == 0 && emitDeferred)
62 self.emitDeferredDecls();
63 }
64 };
65
66protected:
67 std::unique_ptr<mlir::MLIRContext> mlirContext;
68 std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
69
70private:
71 llvm::SmallVector<clang::FunctionDecl *, 8> deferredInlineMemberFuncDefs;
72
73public:
76 const clang::CodeGenOptions &cgo);
77 ~CIRGenerator() override;
78 void Initialize(clang::ASTContext &astContext) override;
79 bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
80 void HandleTranslationUnit(clang::ASTContext &astContext) override;
83 void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override;
85 void
87 const clang::OpenACCRoutineDecl *RD) override;
89 void HandleVTable(clang::CXXRecordDecl *rd) override;
90
91 mlir::ModuleOp getModule() const;
92 mlir::MLIRContext &getMLIRContext() { return *mlirContext; };
93 const mlir::MLIRContext &getMLIRContext() const { return *mlirContext; };
94
95 bool verifyModule() const;
96
97 void emitDeferredDecls();
98};
99
100} // namespace cir
101
102#endif // LLVM_CLANG_CIR_CIRGENERATOR_H
void HandleTagDeclDefinition(clang::TagDecl *d) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl to (e.g.
CIRGenerator(clang::DiagnosticsEngine &diags, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > fs, const clang::CodeGenOptions &cgo)
mlir::ModuleOp getModule() const
const mlir::MLIRContext & getMLIRContext() const
std::unique_ptr< clang::CIRGen::CIRGenModule > cgm
void HandleTranslationUnit(clang::ASTContext &astContext) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
bool verifyModule() const
void HandleVTable(clang::CXXRecordDecl *rd) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
~CIRGenerator() override
bool HandleTopLevelDecl(clang::DeclGroupRef group) override
HandleTopLevelDecl - Handle the specified top-level declaration.
void CompleteTentativeDefinition(clang::VarDecl *d) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
void HandleOpenACCRoutineReference(const clang::FunctionDecl *FD, const clang::OpenACCRoutineDecl *RD) override
Callback to handle the end-of-translation unit attachment of OpenACC routine declaration information.
void HandleInlineFunctionDefinition(clang::FunctionDecl *d) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *D) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
std::unique_ptr< mlir::MLIRContext > mlirContext
void Initialize(clang::ASTContext &astContext) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
mlir::MLIRContext & getMLIRContext()
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition ASTConsumer.h:35
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
This class organizes the cross-function state that is used while generating CIR code.
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:234
Represents a function declaration or definition.
Definition Decl.h:2058
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3851
Represents a variable declaration or definition.
Definition Decl.h:932
Top level wrappers for InstallAPI frontend operations.