clang 22.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;
27class DiagnosticsEngine;
28namespace CIRGen {
29class CIRGenModule;
30} // namespace CIRGen
31} // namespace clang
32
33namespace mlir {
34class MLIRContext;
35} // namespace mlir
36namespace cir {
38 virtual void anchor();
40 clang::ASTContext *astContext;
41 // Only used for debug info.
43
44 const clang::CodeGenOptions &codeGenOpts;
45
46 unsigned handlingTopLevelDecls;
47
48 /// Use this when emitting decls to block re-entrant decl emission. It will
49 /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl
50 /// emission must be deferred longer, like at the end of a tag definition.
51 struct HandlingTopLevelDeclRAII {
52 CIRGenerator &self;
53 bool emitDeferred;
54 HandlingTopLevelDeclRAII(CIRGenerator &self, bool emitDeferred = true)
55 : self{self}, emitDeferred{emitDeferred} {
56 ++self.handlingTopLevelDecls;
57 }
58 ~HandlingTopLevelDeclRAII() {
59 unsigned Level = --self.handlingTopLevelDecls;
60 if (Level == 0 && emitDeferred)
61 self.emitDeferredDecls();
62 }
63 };
64
65protected:
66 std::unique_ptr<mlir::MLIRContext> mlirContext;
67 std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
68
69private:
70 llvm::SmallVector<clang::FunctionDecl *, 8> deferredInlineMemberFuncDefs;
71
72public:
75 const clang::CodeGenOptions &cgo);
76 ~CIRGenerator() override;
77 void Initialize(clang::ASTContext &astContext) override;
78 bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
79 void HandleTranslationUnit(clang::ASTContext &astContext) override;
85 void HandleVTable(clang::CXXRecordDecl *rd) override;
86
87 mlir::ModuleOp getModule() const;
88 mlir::MLIRContext &getMLIRContext() { return *mlirContext; };
89 const mlir::MLIRContext &getMLIRContext() const { return *mlirContext; };
90
91 bool verifyModule() const;
92
93 void emitDeferredDecls();
94};
95
96} // namespace cir
97
98#endif // LLVM_CLANG_CIR_CIRGENERATOR_H
const Decl * D
void HandleTagDeclDefinition(clang::TagDecl *d) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl to (e.g.
mlir::ModuleOp getModule() const
const mlir::MLIRContext & getMLIRContext() const
Definition: CIRGenerator.h:89
std::unique_ptr< clang::CIRGen::CIRGenModule > cgm
Definition: CIRGenerator.h:67
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 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
Definition: CIRGenerator.h:66
void Initialize(clang::ASTContext &astContext) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
mlir::MLIRContext & getMLIRContext()
Definition: CIRGenerator.h:88
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:34
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
This class organizes the cross-function state that is used while generating CIR code.
Definition: CIRGenModule.h:56
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:231
Represents a function declaration or definition.
Definition: Decl.h:1999
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3710
Represents a variable declaration or definition.
Definition: Decl.h:925
Definition: ABIArgInfo.h:22
The JSON file list parser is used to communicate input to InstallAPI.