clang 20.0.0git
CIRGenModule.h
Go to the documentation of this file.
1//===--- CIRGenModule.h - Per-Module state for CIR gen ----------*- C++ -*-===//
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 is the internal per-translation-unit state used for CIR translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
14#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
15
16#include "CIRGenBuilder.h"
17#include "CIRGenTypeCache.h"
18#include "CIRGenTypes.h"
19
20#include "mlir/IR/Builders.h"
21#include "mlir/IR/BuiltinOps.h"
22#include "mlir/IR/MLIRContext.h"
24#include "llvm/ADT/StringRef.h"
25
26namespace clang {
27class ASTContext;
28class CodeGenOptions;
29class Decl;
30class GlobalDecl;
31class LangOptions;
32class TargetInfo;
33class VarDecl;
34
35namespace CIRGen {
36
37/// This class organizes the cross-function state that is used while generating
38/// CIR code.
40 CIRGenModule(CIRGenModule &) = delete;
41 CIRGenModule &operator=(CIRGenModule &) = delete;
42
43public:
44 CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
45 const clang::CodeGenOptions &cgo,
47
48 ~CIRGenModule() = default;
49
50private:
51 CIRGenBuilderTy builder;
52
53 /// Hold Clang AST information.
54 clang::ASTContext &astContext;
55
56 const clang::LangOptions &langOpts;
57
58 /// A "module" matches a c/cpp source file: containing a list of functions.
59 mlir::ModuleOp theModule;
60
62
63 const clang::TargetInfo ⌖
64
65 CIRGenTypes genTypes;
66
67public:
68 mlir::ModuleOp getModule() const { return theModule; }
69 CIRGenBuilderTy &getBuilder() { return builder; }
70 clang::ASTContext &getASTContext() const { return astContext; }
71 CIRGenTypes &getTypes() { return genTypes; }
72 mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
73
74 /// Helpers to convert the presumed location of Clang's SourceLocation to an
75 /// MLIR Location.
76 mlir::Location getLoc(clang::SourceLocation cLoc);
77 mlir::Location getLoc(clang::SourceRange cRange);
78
80
81 /// Emit code for a single global function or variable declaration. Forward
82 /// declarations are emitted lazily.
84
86 mlir::Operation *op = nullptr);
87 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
89 bool isTentative = false);
90
91 /// Helpers to emit "not yet implemented" error diagnostics
93
94 template <typename T>
95 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
96 const T &name) {
97 unsigned diagID =
99 "ClangIR code gen Not Yet Implemented: %0: %1");
100 return diags.Report(loc, diagID) << feature << name;
101 }
102
103 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
104
105 template <typename T>
106 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
107 const T &name) {
108 return errorNYI(loc.getBegin(), feature, name) << loc;
109 }
110};
111} // namespace CIRGen
112
113} // namespace clang
114
115#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
Defines the SourceManager interface.
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:39
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
Definition: CIRGenModule.h:70
void emitTopLevelDecl(clang::Decl *decl)
DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature, const T &name)
Definition: CIRGenModule.h:106
CIRGenBuilderTy & getBuilder()
Definition: CIRGenModule.h:69
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
CIRGenTypes & getTypes()
Definition: CIRGenModule.h:71
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::ModuleOp getModule() const
Definition: CIRGenModule.h:68
mlir::MLIRContext & getMLIRContext()
Definition: CIRGenModule.h:72
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature, const T &name)
Definition: CIRGenModule.h:95
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition: CIRGenTypes.h:38
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
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1220
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1493
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:896
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Exposes information about the current target.
Definition: TargetInfo.h:220
Represents a variable declaration or definition.
Definition: Decl.h:882
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
This structure provides a set of types that are commonly used during IR emission.