21#include "mlir/IR/BuiltinOps.h"
22#include "mlir/IR/Location.h"
23#include "mlir/IR/MLIRContext.h"
28CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
32 : builder(mlirContext, *this), astContext(astContext),
33 langOpts(astContext.getLangOpts()),
34 theModule{
mlir::ModuleOp::create(
mlir::UnknownLoc::get(&mlirContext))},
35 diags(diags), target(astContext.getTargetInfo()), genTypes(*this) {
51 assert(cLoc.
isValid() &&
"expected valid source location");
55 return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
60 assert(cRange.
isValid() &&
"expected a valid source range");
63 mlir::Attribute metadata;
64 return mlir::FusedLoc::get({begin, end}, metadata, builder.getContext());
68 const auto *global = cast<ValueDecl>(gd.
getDecl());
70 if (
const auto *fd = dyn_cast<FunctionDecl>(global)) {
73 if (fd->hasAttr<AnnotateAttr>())
74 errorNYI(fd->getSourceRange(),
"deferredAnnotations");
75 if (!fd->doesThisDeclarationHaveABody()) {
76 if (!fd->doesDeclarationForceExternallyVisibleDefinition())
80 "function declaration that forces code gen");
84 assert(cast<VarDecl>(global)->isFileVarDecl() &&
85 "Cannot emit local var decl as global");
93 mlir::Operation *op) {
94 auto const *funcDecl = cast<FunctionDecl>(gd.
getDecl());
96 auto funcOp = builder.create<cir::FuncOp>(
97 getLoc(funcDecl->getSourceRange()), identifier->getName());
98 theModule.push_back(funcOp);
100 errorNYI(funcDecl->getSourceRange().getBegin(),
101 "function definition with a non-identifier for a name");
110 identifier->getName(),
type);
111 theModule.push_back(varOp);
114 "variable definition with a non-identifier for a name");
119 mlir::Operation *op) {
121 if (
const auto *fd = dyn_cast<FunctionDecl>(
decl)) {
125 if (
const auto *method = dyn_cast<CXXMethodDecl>(
decl)) {
129 errorNYI(method->getSourceRange(),
"member function");
133 if (fd->isMultiVersion())
134 errorNYI(fd->getSourceRange(),
"multiversion functions");
139 if (
const auto *vd = dyn_cast<VarDecl>(
decl))
142 llvm_unreachable(
"Invalid argument to CIRGenModule::emitGlobalDefinition");
149 if (
decl->isTemplated())
152 switch (
decl->getKind()) {
155 decl->getDeclKindName());
158 case Decl::Function: {
159 auto *fd = cast<FunctionDecl>(
decl);
161 if (!fd->isConsteval())
167 auto *vd = cast<VarDecl>(
decl);
175 llvm::StringRef feature) {
178 return diags.
Report(loc, diagID) << feature;
182 llvm::StringRef feature) {
Defines the clang::ASTContext interface.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void emitTopLevelDecl(clang::Decl *decl)
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::MLIRContext & getMLIRContext()
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
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.
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Represents a variable declaration or definition.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.