clang 22.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 "CIRGenCall.h"
18#include "CIRGenTypeCache.h"
19#include "CIRGenTypes.h"
20#include "CIRGenVTables.h"
21#include "CIRGenValue.h"
22
23#include "clang/AST/CharUnits.h"
26
27#include "TargetInfo.h"
28#include "mlir/IR/Builders.h"
29#include "mlir/IR/BuiltinOps.h"
30#include "mlir/IR/MLIRContext.h"
31#include "clang/AST/Decl.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/TargetParser/Triple.h"
37
38namespace clang {
39class ASTContext;
40class CodeGenOptions;
41class Decl;
42class GlobalDecl;
43class LangOptions;
44class TargetInfo;
45class VarDecl;
46
47namespace CIRGen {
48
49class CIRGenFunction;
50class CIRGenCXXABI;
51
52enum ForDefinition_t : bool { NotForDefinition = false, ForDefinition = true };
53
54/// This class organizes the cross-function state that is used while generating
55/// CIR code.
57 CIRGenModule(CIRGenModule &) = delete;
58 CIRGenModule &operator=(CIRGenModule &) = delete;
59
60public:
61 CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
62 const clang::CodeGenOptions &cgo,
64
66
67private:
68 mutable std::unique_ptr<TargetCIRGenInfo> theTargetCIRGenInfo;
69
70 CIRGenBuilderTy builder;
71
72 /// Hold Clang AST information.
73 clang::ASTContext &astContext;
74
75 const clang::LangOptions &langOpts;
76
77 const clang::CodeGenOptions &codeGenOpts;
78
79 /// A "module" matches a c/cpp source file: containing a list of functions.
80 mlir::ModuleOp theModule;
81
83
84 const clang::TargetInfo &target;
85
86 std::unique_ptr<CIRGenCXXABI> abi;
87
88 CIRGenTypes genTypes;
89
90 /// Holds information about C++ vtables.
91 CIRGenVTables vtables;
92
93 /// Per-function codegen information. Updated everytime emitCIR is called
94 /// for FunctionDecls's.
95 CIRGenFunction *curCGF = nullptr;
96
98
99public:
100 mlir::ModuleOp getModule() const { return theModule; }
101 CIRGenBuilderTy &getBuilder() { return builder; }
102 clang::ASTContext &getASTContext() const { return astContext; }
103 const clang::TargetInfo &getTarget() const { return target; }
104 const clang::CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
105 clang::DiagnosticsEngine &getDiags() const { return diags; }
106 CIRGenTypes &getTypes() { return genTypes; }
107 const clang::LangOptions &getLangOpts() const { return langOpts; }
108
109 CIRGenCXXABI &getCXXABI() const { return *abi; }
110 mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
111
113 // FIXME(cir): instead of creating a CIRDataLayout every time, set it as an
114 // attribute for the CIRModule class.
115 return cir::CIRDataLayout(theModule);
116 }
117
118 /// -------
119 /// Handling globals
120 /// -------
121
122 mlir::Operation *lastGlobalOp = nullptr;
123
124 /// Tell the consumer that this variable has been instantiated.
126
127 llvm::DenseMap<const Decl *, cir::GlobalOp> staticLocalDeclMap;
128
129 mlir::Operation *getGlobalValue(llvm::StringRef ref);
130
131 cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d) {
132 return staticLocalDeclMap[d];
133 }
134
135 void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c) {
137 }
138
139 cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d,
140 cir::GlobalLinkageKind linkage);
141
142 /// If the specified mangled name is not in the module, create and return an
143 /// mlir::GlobalOp value
144 cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty,
145 LangAS langAS, const VarDecl *d,
146 ForDefinition_t isForDefinition);
147
148 cir::GlobalOp getOrCreateCIRGlobal(const VarDecl *d, mlir::Type ty,
149 ForDefinition_t isForDefinition);
150
151 static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc,
152 llvm::StringRef name, mlir::Type t,
153 bool isConstant = false,
154 mlir::Operation *insertPoint = nullptr);
155
156 llvm::StringMap<unsigned> cgGlobalNames;
157 std::string getUniqueGlobalName(const std::string &baseName);
158
159 /// Return the mlir::Value for the address of the given global variable.
160 /// If Ty is non-null and if the global doesn't exist, then it will be created
161 /// with the specified type instead of whatever the normal requested type
162 /// would be. If IsForDefinition is true, it is guaranteed that an actual
163 /// global with type Ty will be returned, not conversion of a variable with
164 /// the same mangled name but some other type.
165 mlir::Value
166 getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
167 ForDefinition_t isForDefinition = NotForDefinition);
168
169 /// Return the mlir::GlobalViewAttr for the address of the given global.
170 cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d);
171
173 const CXXRecordDecl *derivedClass,
174 llvm::iterator_range<CastExpr::path_const_iterator> path);
175
176 /// Get the CIR attributes and calling convention to use for a particular
177 /// function type.
178 ///
179 /// \param calleeInfo - The callee information these attributes are being
180 /// constructed for. If valid, the attributes applied to this decl may
181 /// contribute to the function attributes and calling convention.
183 mlir::NamedAttrList &attrs);
184
185 /// Will return a global variable of the given type. If a variable with a
186 /// different type already exists then a new variable with the right type
187 /// will be created and all uses of the old variable will be replaced with a
188 /// bitcast to the new variable.
190 mlir::Location loc, llvm::StringRef name, mlir::Type ty,
191 cir::GlobalLinkageKind linkage, clang::CharUnits alignment);
192
193 void emitVTable(const CXXRecordDecl *rd);
194
195 /// Return the appropriate linkage for the vtable, VTT, and type information
196 /// of the given class.
197 cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd);
198
199 /// Get the address of the RTTI descriptor for the given type.
200 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty,
201 bool forEH = false);
202
203 /// Return a constant array for the given string.
204 mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
205
206 /// Return a global symbol reference to a constant array for the given string
207 /// literal.
208 cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s,
209 llvm::StringRef name = ".str");
210
211 /// Return a global symbol reference to a constant array for the given string
212 /// literal.
213 cir::GlobalViewAttr
215 llvm::StringRef name = ".str");
216
217 /// Set attributes which are common to any form of a global definition (alias,
218 /// Objective-C method, function, global variable).
219 ///
220 /// NOTE: This should only be called for definitions.
221 void setCommonAttributes(GlobalDecl gd, mlir::Operation *op);
222
224
225 /// Helpers to convert the presumed location of Clang's SourceLocation to an
226 /// MLIR Location.
227 mlir::Location getLoc(clang::SourceLocation cLoc);
228 mlir::Location getLoc(clang::SourceRange cRange);
229
230 /// Return the best known alignment for an unknown pointer to a
231 /// particular class.
233
234 /// FIXME: this could likely be a common helper and not necessarily related
235 /// with codegen.
237 LValueBaseInfo *baseInfo);
238
239 cir::FuncOp
241 const CIRGenFunctionInfo *fnInfo = nullptr,
242 cir::FuncType fnType = nullptr, bool dontDefer = false,
243 ForDefinition_t isForDefinition = NotForDefinition) {
244 return getAddrAndTypeOfCXXStructor(gd, fnInfo, fnType, dontDefer,
245 isForDefinition)
246 .second;
247 }
248
249 std::pair<cir::FuncType, cir::FuncOp> getAddrAndTypeOfCXXStructor(
250 clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo = nullptr,
251 cir::FuncType fnType = nullptr, bool dontDefer = false,
252 ForDefinition_t isForDefinition = NotForDefinition);
253
254 mlir::Type getVTableComponentType();
255 CIRGenVTables &getVTables() { return vtables; }
256
258 return vtables.getItaniumVTableContext();
259 }
261 return vtables.getItaniumVTableContext();
262 }
263
264 /// This contains all the decls which have definitions but which are deferred
265 /// for emission and therefore should only be output if they are actually
266 /// used. If a decl is in this, then it is known to have not been referenced
267 /// yet.
268 std::map<llvm::StringRef, clang::GlobalDecl> deferredDecls;
269
270 // This is a list of deferred decls which we have seen that *are* actually
271 // referenced. These get code generated when the module is done.
272 std::vector<clang::GlobalDecl> deferredDeclsToEmit;
274 deferredDeclsToEmit.emplace_back(GD);
275 }
276
278
279 /// Determine whether the definition must be emitted; if this returns \c
280 /// false, the definition can be emitted lazily if it's used.
281 bool mustBeEmitted(const clang::ValueDecl *d);
282
283 /// Determine whether the definition can be emitted eagerly, or should be
284 /// delayed until the end of the translation unit. This is relevant for
285 /// definitions whose linkage can change, e.g. implicit function
286 /// instantiations which may later be explicitly instantiated.
288
289 bool verifyModule() const;
290
291 /// Return the address of the given function. If funcType is non-null, then
292 /// this function will use the specified type if it has to create it.
293 // TODO: this is a bit weird as `GetAddr` given we give back a FuncOp?
294 cir::FuncOp
295 getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType = nullptr,
296 bool forVTable = false, bool dontDefer = false,
297 ForDefinition_t isForDefinition = NotForDefinition);
298
299 mlir::Operation *
301 ForDefinition_t isForDefinition = NotForDefinition);
302
303 // Return whether RTTI information should be emitted for this target.
304 bool shouldEmitRTTI(bool forEH = false) {
305 return (forEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
306 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
307 getTriple().isNVPTX());
308 }
309
310 /// Emit type info if type of an expression is a variably modified
311 /// type. Also emit proper debug info for cast types.
313 CIRGenFunction *cgf = nullptr);
314
315 /// Emit code for a single global function or variable declaration. Forward
316 /// declarations are emitted lazily.
318
319 void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op,
320 GlobalDecl aliasGD, cir::FuncOp aliasee,
321 cir::GlobalLinkageKind linkage);
322
323 mlir::Type convertType(clang::QualType type);
324
325 /// Set the visibility for the given global.
326 void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const;
327 void setDSOLocal(mlir::Operation *op) const;
328 void setDSOLocal(cir::CIRGlobalValueInterface gv) const;
329
330 /// Set visibility, dllimport/dllexport and dso_local.
331 /// This must be called after dllimport/dllexport is set.
332 void setGVProperties(mlir::Operation *op, const NamedDecl *d) const;
333 void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const;
334
335 /// Set function attributes for a function declaration.
336 void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f,
337 bool isIncompleteFunction, bool isThunk);
338
340 mlir::Operation *op = nullptr);
341 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
343 bool isTentative = false);
344
346
347 // C++ related functions.
348 void emitDeclContext(const DeclContext *dc);
349
350 /// Return the result of value-initializing the given type, i.e. a null
351 /// expression of the given type.
352 mlir::Value emitNullConstant(QualType t, mlir::Location loc);
353
354 llvm::StringRef getMangledName(clang::GlobalDecl gd);
355
356 void emitTentativeDefinition(const VarDecl *d);
357
358 // Make sure that this type is translated.
359 void updateCompletedType(const clang::TagDecl *td);
360
361 // Produce code for this constructor/destructor. This method doesn't try to
362 // apply any ABI rules about which other constructors/destructors are needed
363 // or if they are alias to each other.
365
366 bool supportsCOMDAT() const;
367 void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op);
368
369 static void setInitializer(cir::GlobalOp &op, mlir::Attribute value);
370
371 void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old,
372 cir::FuncOp newFn);
373
374 cir::FuncOp
375 getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType,
376 clang::GlobalDecl gd, bool forVTable,
377 bool dontDefer = false, bool isThunk = false,
378 ForDefinition_t isForDefinition = NotForDefinition,
379 mlir::ArrayAttr extraAttrs = {});
380
381 cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name,
382 cir::FuncType funcType,
383 const clang::FunctionDecl *funcDecl);
384
385 /// Given a builtin id for a function like "__builtin_fabsf", return a
386 /// Function* for "fabsf".
387 cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);
388
389 mlir::IntegerAttr getSize(CharUnits size) {
390 return builder.getSizeFromCharUnits(size);
391 }
392
393 /// Emit any needed decls for which code generation was deferred.
394 void emitDeferred();
395
396 /// Helper for `emitDeferred` to apply actual codegen.
397 void emitGlobalDecl(const clang::GlobalDecl &d);
398
399 const llvm::Triple &getTriple() const { return target.getTriple(); }
400
401 // Finalize CIR code generation.
402 void release();
403
404 /// -------
405 /// Visibility and Linkage
406 /// -------
407
408 static mlir::SymbolTable::Visibility
409 getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK);
410 static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(
411 clang::VisibilityAttr::VisibilityType visibility);
412 cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl);
413 cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd);
414 static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op);
415 cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd,
416 GVALinkage linkage,
417 bool isConstantVariable);
418 void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f) {
419 cir::GlobalLinkageKind l = getFunctionLinkage(gd);
420 f.setLinkageAttr(cir::GlobalLinkageKindAttr::get(&getMLIRContext(), l));
421 mlir::SymbolTable::setSymbolVisibility(f,
423 }
424
425 cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd,
426 bool isConstant);
427
428 void addReplacement(llvm::StringRef name, mlir::Operation *op);
429
430 /// Helpers to emit "not yet implemented" error diagnostics
431 DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
432
433 template <typename T>
434 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
435 const T &name) {
436 unsigned diagID =
438 "ClangIR code gen Not Yet Implemented: %0: %1");
439 return diags.Report(loc, diagID) << feature << name;
440 }
441
442 DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature) {
443 // TODO: Convert the location to a SourceLocation
444 unsigned diagID = diags.getCustomDiagID(
445 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
446 return diags.Report(diagID) << feature;
447 }
448
449 DiagnosticBuilder errorNYI(llvm::StringRef feature) const {
450 // TODO: Make a default location? currSrcLoc?
451 unsigned diagID = diags.getCustomDiagID(
452 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
453 return diags.Report(diagID) << feature;
454 }
455
456 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
457
458 template <typename T>
459 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
460 const T &name) {
461 return errorNYI(loc.getBegin(), feature, name) << loc;
462 }
463
464private:
465 // An ordered map of canonical GlobalDecls to their mangled names.
466 llvm::MapVector<clang::GlobalDecl, llvm::StringRef> mangledDeclNames;
467 llvm::StringMap<clang::GlobalDecl, llvm::BumpPtrAllocator> manglings;
468
469 // FIXME: should we use llvm::TrackingVH<mlir::Operation> here?
470 typedef llvm::StringMap<mlir::Operation *> ReplacementsTy;
471 ReplacementsTy replacements;
472 /// Call replaceAllUsesWith on all pairs in replacements.
473 void applyReplacements();
474
475 /// A helper function to replace all uses of OldF to NewF that replace
476 /// the type of pointer arguments. This is not needed to tradtional
477 /// pipeline since LLVM has opaque pointers but CIR not.
478 void replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF);
479
480 void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op);
481
482 /// Map source language used to a CIR attribute.
483 std::optional<cir::SourceLanguage> getCIRSourceLanguage() const;
484};
485} // namespace CIRGen
486
487} // namespace clang
488
489#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
Defines the SourceManager interface.
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Implements C++ ABI-specific code generation functions.
Definition: CIRGenCXXABI.h:26
Abstract information about a function or function prototype.
Definition: CIRGenCall.h:27
This class organizes the cross-function state that is used while generating CIR code.
Definition: CIRGenModule.h:56
void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old, cir::FuncOp newFn)
This function is called when we implement a function with no prototype, e.g.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)
Definition: CIRGenDecl.cpp:271
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass, llvm::iterator_range< CastExpr::path_const_iterator > path)
void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const
Set the visibility for the given global.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void emitDeferred()
Emit any needed decls for which code generation was deferred.
clang::ASTContext & getASTContext() const
Definition: CIRGenModule.h:102
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Definition: CIRGenModule.h:240
void emitTopLevelDecl(clang::Decl *decl)
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
Definition: CIRGenModule.h:304
cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
bool mustBeEmitted(const clang::ValueDecl *d)
Determine whether the definition must be emitted; if this returns false, the definition can be emitte...
void constructAttributeList(CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs)
Get the CIR attributes and calling convention to use for a particular function type.
Definition: CIRGenCall.cpp:113
mlir::IntegerAttr getSize(CharUnits size)
Definition: CIRGenModule.h:389
DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature, const T &name)
Definition: CIRGenModule.h:459
CIRGenBuilderTy & getBuilder()
Definition: CIRGenModule.h:101
void setDSOLocal(mlir::Operation *op) const
std::string getUniqueGlobalName(const std::string &baseName)
std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
ItaniumVTableContext & getItaniumVTableContext()
Definition: CIRGenModule.h:257
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty, LangAS langAS, const VarDecl *d, ForDefinition_t isForDefinition)
If the specified mangled name is not in the module, create and return an mlir::GlobalOp value.
llvm::DenseMap< const Decl *, cir::GlobalOp > staticLocalDeclMap
Definition: CIRGenModule.h:127
clang::CharUnits getClassPointerAlignment(const clang::CXXRecordDecl *rd)
Return the best known alignment for an unknown pointer to a particular class.
void handleCXXStaticMemberVarInstantiation(VarDecl *vd)
Tell the consumer that this variable has been instantiated.
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
clang::DiagnosticsEngine & getDiags() const
Definition: CIRGenModule.h:105
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty, bool forEH=false)
Get the address of the RTTI descriptor for the given type.
clang::CharUnits getNaturalTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo)
FIXME: this could likely be a common helper and not necessarily related with codegen.
void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f, bool isIncompleteFunction, bool isThunk)
Set function attributes for a function declaration.
static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)
const ItaniumVTableContext & getItaniumVTableContext() const
Definition: CIRGenModule.h:260
const clang::TargetInfo & getTarget() const
Definition: CIRGenModule.h:103
static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op)
cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID)
Given a builtin id for a function like "__builtin_fabsf", return a Function* for "fabsf".
const llvm::Triple & getTriple() const
Definition: CIRGenModule.h:399
void emitTentativeDefinition(const VarDecl *d)
cir::GlobalOp createOrReplaceCXXRuntimeVariable(mlir::Location loc, llvm::StringRef name, mlir::Type ty, cir::GlobalLinkageKind linkage, clang::CharUnits alignment)
Will return a global variable of the given type.
void emitGlobalDecl(const clang::GlobalDecl &d)
Helper for emitDeferred to apply actual codegen.
cir::FuncOp getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType, clang::GlobalDecl gd, bool forVTable, bool dontDefer=false, bool isThunk=false, ForDefinition_t isForDefinition=NotForDefinition, mlir::ArrayAttr extraAttrs={})
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature)
Definition: CIRGenModule.h:442
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd)
void emitExplicitCastExprType(const ExplicitCastExpr *e, CIRGenFunction *cgf=nullptr)
Emit type info if type of an expression is a variably modified type.
const cir::CIRDataLayout getDataLayout() const
Definition: CIRGenModule.h:112
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
Definition: CIRGenModule.h:268
mlir::Value getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty={}, ForDefinition_t isForDefinition=NotForDefinition)
Return the mlir::Value for the address of the given global variable.
static void setInitializer(cir::GlobalOp &op, mlir::Attribute value)
cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d)
Return the mlir::GlobalViewAttr for the address of the given global.
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
void updateCompletedType(const clang::TagDecl *td)
const clang::CodeGenOptions & getCodeGenOpts() const
Definition: CIRGenModule.h:104
const clang::LangOptions & getLangOpts() const
Definition: CIRGenModule.h:107
void addDeferredDeclToEmit(clang::GlobalDecl GD)
Definition: CIRGenModule.h:273
cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType funcType, const clang::FunctionDecl *funcDecl)
const TargetCIRGenInfo & getTargetCIRGenInfo()
void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c)
Definition: CIRGenModule.h:135
void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const
cir::FuncOp codegenCXXStructor(clang::GlobalDecl gd)
Definition: CIRGenCXX.cpp:22
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::Operation * lastGlobalOp
Definition: CIRGenModule.h:122
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
Definition: CIRGenModule.h:156
mlir::Operation * getGlobalValue(llvm::StringRef ref)
mlir::Value emitNullConstant(QualType t, mlir::Location loc)
Return the result of value-initializing the given type, i.e.
mlir::ModuleOp getModule() const
Definition: CIRGenModule.h:100
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage, bool isConstantVariable)
mlir::MLIRContext & getMLIRContext()
Definition: CIRGenModule.h:110
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
DiagnosticBuilder errorNYI(llvm::StringRef feature) const
Definition: CIRGenModule.h:449
static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::Operation *insertPoint=nullptr)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d)
Definition: CIRGenModule.h:131
CIRGenCXXABI & getCXXABI() const
Definition: CIRGenModule.h:109
cir::GlobalViewAttr getAddrOfConstantStringFromLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
void emitDeclContext(const DeclContext *dc)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
bool mayBeEmittedEagerly(const clang::ValueDecl *d)
Determine whether the definition can be emitted eagerly, or should be delayed until the end of the tr...
DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature, const T &name)
Definition: CIRGenModule.h:434
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd, bool isConstant)
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
CIRGenVTables & getVTables()
Definition: CIRGenModule.h:255
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
Definition: CIRGenModule.h:418
std::vector< clang::GlobalDecl > deferredDeclsToEmit
Definition: CIRGenModule.h:272
void emitVTable(const CXXRecordDecl *rd)
This is a callback from Sema to tell us that a particular vtable is required to be emitted in this tr...
cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e)
Return a constant array for the given string.
cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl)
void setCommonAttributes(GlobalDecl gd, mlir::Operation *op)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition: CIRGenTypes.h:48
clang::ItaniumVTableContext & getItaniumVTableContext()
Definition: CIRGenVTables.h:50
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:779
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1233
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:1529
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:904
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3864
Represents a function declaration or definition.
Definition: Decl.h:1999
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:57
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
This represents a decl that may have a name.
Definition: Decl.h:273
A (possibly-)qualified type.
Definition: TypeBase.h:937
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1801
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3710
Exposes information about the current target.
Definition: TargetInfo.h:226
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1288
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
Represents a variable declaration or definition.
Definition: Decl.h:925
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
The JSON file list parser is used to communicate input to InstallAPI.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:72
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
const FunctionProtoType * T
This structure provides a set of types that are commonly used during IR emission.