Remove dependence on <ciso646> (#73273)
[llvm-project.git] / clang / lib / CIR / CodeGen / CIRGenModule.h
blob1c7ed63773900a1e226c23bf7e006d192eaa18ea
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
14 #define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
16 #include "CIRGenBuilder.h"
17 #include "CIRGenTypeCache.h"
18 #include "CIRGenTypes.h"
20 #include "mlir/IR/Builders.h"
21 #include "mlir/IR/BuiltinOps.h"
22 #include "mlir/IR/MLIRContext.h"
23 #include "clang/Basic/SourceManager.h"
24 #include "llvm/ADT/StringRef.h"
26 namespace clang {
27 class ASTContext;
28 class CodeGenOptions;
29 class Decl;
30 class GlobalDecl;
31 class LangOptions;
32 class TargetInfo;
33 class VarDecl;
35 namespace CIRGen {
37 /// This class organizes the cross-function state that is used while generating
38 /// CIR code.
39 class CIRGenModule : public CIRGenTypeCache {
40 CIRGenModule(CIRGenModule &) = delete;
41 CIRGenModule &operator=(CIRGenModule &) = delete;
43 public:
44 CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
45 const clang::CodeGenOptions &cgo,
46 clang::DiagnosticsEngine &diags);
48 ~CIRGenModule() = default;
50 private:
51 CIRGenBuilderTy builder;
53 /// Hold Clang AST information.
54 clang::ASTContext &astContext;
56 const clang::LangOptions &langOpts;
58 /// A "module" matches a c/cpp source file: containing a list of functions.
59 mlir::ModuleOp theModule;
61 clang::DiagnosticsEngine &diags;
63 const clang::TargetInfo &target;
65 CIRGenTypes genTypes;
67 public:
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(); }
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);
79 void emitTopLevelDecl(clang::Decl *decl);
81 /// Emit code for a single global function or variable declaration. Forward
82 /// declarations are emitted lazily.
83 void emitGlobal(clang::GlobalDecl gd);
85 void emitGlobalDefinition(clang::GlobalDecl gd,
86 mlir::Operation *op = nullptr);
87 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
88 void emitGlobalVarDefinition(const clang::VarDecl *vd,
89 bool isTentative = false);
91 /// Helpers to emit "not yet implemented" error diagnostics
92 DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
94 template <typename T>
95 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
96 const T &name) {
97 unsigned diagID =
98 diags.getCustomDiagID(DiagnosticsEngine::Error,
99 "ClangIR code gen Not Yet Implemented: %0: %1");
100 return diags.Report(loc, diagID) << feature << name;
103 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
105 template <typename T>
106 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
107 const T &name) {
108 return errorNYI(loc.getBegin(), feature, name) << loc;
111 } // namespace CIRGen
113 } // namespace clang
115 #endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H