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 Decl;
27class DeclGroupRef;
29namespace CIRGen {
30class CIRGenModule;
31} // namespace CIRGen
32} // namespace clang
33
34namespace mlir {
35class MLIRContext;
36class ModuleOp;
37} // namespace mlir
38namespace cir {
40 virtual void anchor();
42 clang::ASTContext *astContext;
43 // Only used for debug info.
45
46 const clang::CodeGenOptions &codeGenOpts;
47
48 unsigned handlingTopLevelDecls;
49
50 /// Use this when emitting decls to block re-entrant decl emission. It will
51 /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl
52 /// emission must be deferred longer, like at the end of a tag definition.
53 struct HandlingTopLevelDeclRAII {
54 CIRGenerator &self;
55 bool emitDeferred;
56 HandlingTopLevelDeclRAII(CIRGenerator &self, bool emitDeferred = true)
57 : self{self}, emitDeferred{emitDeferred} {
58 ++self.handlingTopLevelDecls;
59 }
60 ~HandlingTopLevelDeclRAII() {
61 unsigned Level = --self.handlingTopLevelDecls;
62 if (Level == 0 && emitDeferred)
63 self.emitDeferredDecls();
64 }
65 };
66
67protected:
68 std::unique_ptr<mlir::MLIRContext> mlirContext;
69 std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
70
71private:
72 llvm::SmallVector<clang::FunctionDecl *, 8> deferredInlineMemberFuncDefs;
73
74public:
77 const clang::CodeGenOptions &cgo);
78 ~CIRGenerator() override;
79 void Initialize(clang::ASTContext &astContext) override;
80 bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
81 void HandleTranslationUnit(clang::ASTContext &astContext) override;
84 void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override;
86 void
88 const clang::OpenACCRoutineDecl *RD) override;
90 void HandleVTable(clang::CXXRecordDecl *rd) override;
91
92 mlir::ModuleOp getModule() const;
93 mlir::MLIRContext &getMLIRContext() { return *mlirContext; };
94 const mlir::MLIRContext &getMLIRContext() const { return *mlirContext; };
95
96 bool verifyModule() const;
97
98 /// Return the Decl that generated the given mangled name, if known. Used
99 /// to recover a source location for backend diagnostics (e.g. frame-size
100 /// or resource-limit warnings) that lack debug info.
101 const clang::Decl *getDeclForMangledName(llvm::StringRef mangledName);
102
103 void emitDeferredDecls();
104};
105
106} // namespace cir
107
108#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.
const clang::Decl * getDeclForMangledName(llvm::StringRef mangledName)
Return the Decl that generated the given mangled name, if known.
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:245
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...
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:241
Represents a function declaration or definition.
Definition Decl.h:2059
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3856
Represents a variable declaration or definition.
Definition Decl.h:933
Top level wrappers for InstallAPI frontend operations.