clang: lib/CIR/CodeGen/CIRGenerator.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
15#include "mlir/Dialect/OpenACC/OpenACC.h"
16#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
17#include "mlir/IR/MLIRContext.h"
18#include "mlir/Target/LLVMIR/Import.h"
19
24#include "llvm/IR/DataLayout.h"
25
26using namespace cir;
27using namespace clang;
28
29void CIRGenerator::anchor() {}
30
34 : diags(diags), fs(std::move(vfs)), codeGenOpts{cgo},
35 handlingTopLevelDecls{0} {}
37
38 assert(deferredInlineMemberFuncDefs.empty() || diags.hasErrorOccurred());
39}
40
41static void setMLIRDataLayout(mlir::ModuleOp &mod, const llvm::DataLayout &dl) {
42 mlir::MLIRContext *mlirContext = mod.getContext();
43 mlir::DataLayoutSpecInterface dlSpec =
44 mlir::translateDataLayout(dl, mlirContext);
45 mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
46}
47
49 using namespace llvm;
50
51 this->astContext = &astContext;
52
53 mlirContext = std::make_uniquemlir::MLIRContext();
54 mlirContext->loadDialectmlir::DLTIDialect();
55 mlirContext->loadDialectcir::CIRDialect();
56 mlirContext->getOrLoadDialectmlir::acc::OpenACCDialect();
57 mlirContext->getOrLoadDialectmlir::omp::OpenMPDialect();
58
59
60 mlir::DialectRegistry registry;
62 mlirContext->appendDialectRegistry(registry);
63
64 cgm = std::make_uniqueclang::CIRGen::CIRGenModule(
65 *mlirContext.get(), astContext, codeGenOpts, diags);
66 mlir::ModuleOp mod = cgm->getModule();
67 llvm::DataLayout layout =
68 llvm::DataLayout(astContext.getTargetInfo().getDataLayoutString());
70}
71
73
75
77 if (diags.hasUnrecoverableErrorOccurred())
78 return true;
79
80 HandlingTopLevelDeclRAII handlingDecl(*this);
81
83 cgm->emitTopLevelDecl(decl);
84
85 return true;
86}
87
89
90 if (!diags.hasErrorOccurred() && cgm)
91 cgm->release();
92
93
94
96}
97
99 if (diags.hasErrorOccurred())
100 return;
101
103
104
105
106
107
108
109
110
111 deferredInlineMemberFuncDefs.push_back(d);
112
113
114
115
117}
118
120 if (deferredInlineMemberFuncDefs.empty())
121 return;
122
123
124
125
126
127
128 HandlingTopLevelDeclRAII handlingDecls(*this);
129 for (unsigned i = 0; i != deferredInlineMemberFuncDefs.size(); ++i)
130 cgm->emitTopLevelDecl(deferredInlineMemberFuncDefs[i]);
131 deferredInlineMemberFuncDefs.clear();
132}
133
134
135
136
137
139 if (diags.hasErrorOccurred())
140 return;
141
142
143
144 HandlingTopLevelDeclRAII handlingDecl(*this, false);
145
146 cgm->updateCompletedType(d);
147
148
149
150 if (astContext->getTargetInfo().getCXXABI().isMicrosoft())
151 cgm->errorNYI(d->getSourceRange(), "HandleTagDeclDefinition: MSABI");
152
153 if (astContext->getLangOpts().OpenMP)
154 cgm->errorNYI(d->getSourceRange(), "HandleTagDeclDefinition: OpenMP");
155}
156
158 if (diags.hasErrorOccurred())
159 return;
160
162}
163
165 if (diags.hasErrorOccurred())
166 return;
167
168 cgm->handleCXXStaticMemberVarInstantiation(D);
169}
170
173 llvm::StringRef mangledName = cgm->getMangledName(FD);
174 cir::FuncOp entry =
175 mlir::dyn_cast_if_presentcir::FuncOp(cgm->getGlobalValue(mangledName));
176
177
178 if (!entry)
179 return;
181}
182
184 if (diags.hasErrorOccurred())
185 return;
186
187 cgm->emitTentativeDefinition(d);
188}
189
191 if (diags.hasErrorOccurred())
192 return;
193
194 cgm->emitVTable(rd);
195}
static void setMLIRDataLayout(mlir::ModuleOp &mod, const llvm::DataLayout &dl)
Definition CIRGenerator.cpp:41
void HandleTagDeclDefinition(clang::TagDecl *d) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl to (e.g.
Definition CIRGenerator.cpp:138
CIRGenerator(clang::DiagnosticsEngine &diags, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > fs, const clang::CodeGenOptions &cgo)
Definition CIRGenerator.cpp:31
mlir::ModuleOp getModule() const
Definition CIRGenerator.cpp:74
void emitDeferredDecls()
Definition CIRGenerator.cpp:119
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...
Definition CIRGenerator.cpp:88
bool verifyModule() const
Definition CIRGenerator.cpp:72
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...
Definition CIRGenerator.cpp:190
~CIRGenerator() override
Definition CIRGenerator.cpp:36
bool HandleTopLevelDecl(clang::DeclGroupRef group) override
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition CIRGenerator.cpp:76
void CompleteTentativeDefinition(clang::VarDecl *d) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
Definition CIRGenerator.cpp:183
void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
Definition CIRGenerator.cpp:157
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.
Definition CIRGenerator.cpp:171
void HandleInlineFunctionDefinition(clang::FunctionDecl *d) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
Definition CIRGenerator.cpp:98
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *D) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
Definition CIRGenerator.cpp:164
std::unique_ptr< mlir::MLIRContext > mlirContext
void Initialize(clang::ASTContext &astContext) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
Definition CIRGenerator.cpp:48
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 - 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.
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 registerOpenACCExtensions(mlir::DialectRegistry ®istry)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
static bool coverageMapping()
static bool cleanupAfterErrorDiags()
static bool generateDebugInfo()