15#include "mlir/Dialect/DLTI/DLTI.h"
16#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
17#include "mlir/Dialect/OpenACC/OpenACC.h"
18#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
19#include "mlir/IR/MLIRContext.h"
28#include "llvm/IR/DataLayout.h"
33void CIRGenerator::anchor() {}
38 : diags(diags), fs(
std::move(
vfs)), codeGenOpts{cgo},
39 handlingTopLevelDecls{0} {}
42 assert(deferredInlineMemberFuncDefs.empty() || diags.hasErrorOccurred());
48 this->astContext = &astContext;
50 mlirContext = std::make_unique<mlir::MLIRContext>();
54 mlirContext->loadDialect<mlir::DLTIDialect, mlir::LLVM::LLVMDialect,
56 const LangOptions &langOpts = astContext.getLangOpts();
58 mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
60 mlirContext->getOrLoadDialect<mlir::omp::OpenMPDialect>();
62 cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
63 *
mlirContext.get(), astContext, codeGenOpts, diags);
64 mlir::ModuleOp mod =
cgm->getModule();
65 llvm::DataLayout layout =
66 llvm::DataLayout(astContext.getTargetInfo().getDataLayoutString());
76 if (!
cgm->lookupRepresentativeDecl(mangledName, result))
79 if (
auto *fd = dyn_cast<FunctionDecl>(
decl)) {
82 }
else if (
auto *td = dyn_cast<TagDecl>(
decl)) {
83 if (
auto *def = td->getDefinition())
90 if (diags.hasUnrecoverableErrorOccurred())
93 HandlingTopLevelDeclRAII handlingDecl(*
this);
103 if (!diags.hasErrorOccurred() &&
cgm)
112 if (diags.hasErrorOccurred())
124 deferredInlineMemberFuncDefs.push_back(d);
133 if (deferredInlineMemberFuncDefs.empty())
141 HandlingTopLevelDeclRAII handlingDecls(*
this);
142 for (
unsigned i = 0; i != deferredInlineMemberFuncDefs.size(); ++i)
143 cgm->emitTopLevelDecl(deferredInlineMemberFuncDefs[i]);
144 deferredInlineMemberFuncDefs.clear();
152 if (diags.hasErrorOccurred())
157 HandlingTopLevelDeclRAII handlingDecl(*
this,
false);
159 cgm->updateCompletedType(d);
163 if (astContext->getTargetInfo().getCXXABI().isMicrosoft())
168 if (astContext->getLangOpts().OpenMP) {
170 if (
auto *drd = dyn_cast<OMPDeclareReductionDecl>(member)) {
171 if (astContext->DeclMustBeEmitted(drd))
173 "HandleTagDeclDefinition: OMPDeclareReductionDecl");
174 }
else if (
auto *dmd = dyn_cast<OMPDeclareMapperDecl>(member)) {
175 if (astContext->DeclMustBeEmitted(dmd))
177 "HandleTagDeclDefinition: OMPDeclareMapperDecl");
184 if (diags.hasErrorOccurred())
191 if (diags.hasErrorOccurred())
194 cgm->handleCXXStaticMemberVarInstantiation(D);
199 llvm::StringRef mangledName =
cgm->getMangledName(FD);
201 mlir::dyn_cast_if_present<cir::FuncOp>(
cgm->getGlobalValue(mangledName));
210 if (diags.hasErrorOccurred())
213 cgm->emitTentativeDefinition(d);
217 if (diags.hasErrorOccurred())
This file defines OpenACC nodes for declarative directives.
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
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...
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ struct/union/class.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
Concrete class used by the front-end to report problems and issues.
Represents a function declaration or definition.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
const Decl * getDecl() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
ArrayRef< const OpenACCClause * > clauses() const
Represents the declaration of a struct/union/class/enum.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Represents a variable declaration or definition.
void registerAllDialects(mlir::DialectRegistry ®istry)
void setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl)
Translate dl into a DLTI data-layout spec and attach it to mod.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Top level wrappers for InstallAPI frontend operations.
Diagnostic wrappers for TextAPI types for error reporting.
static bool coverageMapping()
static bool cleanupAfterErrorDiags()
static bool generateDebugInfo()