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.
56class CIRGenModule : public CIRGenTypeCache {
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
157 // In C23 (N3096) $6.7.10:
158 // """
159 // If any object is initialized with an empty initializer, then it is
160 // subject to default initialization:
161 // - if it is an aggregate, every member is initialized (recursively)
162 // according to these rules, and any padding is initialized to zero bits;
163 // - if it is a union, the first named member is initialized (recursively)
164 // according to these rules, and any padding is initialized to zero bits.
165 //
166 // If the aggregate or union contains elements or members that are
167 // aggregates or unions, these rules apply recursively to the subaggregates
168 // or contained unions.
169 //
170 // If there are fewer initializers in a brace-enclosed list than there are
171 // elements or members of an aggregate, or fewer characters in a string
172 // literal used to initialize an array of known size than there are elements
173 // in the array, the remainder of the aggregate is subject to default
174 // initialization.
175 // """
176 //
177 // The standard seems ambiguous in the following two areas:
178 // 1. For a union type with empty initializer, if the first named member is
179 // not the largest member, then the bytes comes after the first named member
180 // but before padding are left unspecified. An example is:
181 // union U { int a; long long b;};
182 // union U u = {}; // The first 4 bytes are 0, but 4-8 bytes are left
183 // unspecified.
184 //
185 // 2. It only mentions padding for empty initializer, but doesn't mention
186 // padding for a non empty initialization list. And if the aggregation or
187 // union contains elements or members that are aggregates or unions, and
188 // some are non empty initializers, while others are empty initializers,
189 // the padding initialization is unclear. An example is:
190 // struct S1 { int a; long long b; };
191 // struct S2 { char c; struct S1 s1; };
192 // // The values for paddings between s2.c and s2.s1.a, between s2.s1.a
193 // and s2.s1.b are unclear.
194 // struct S2 s2 = { 'c' };
195 //
196 // Here we choose to zero initiailize left bytes of a union type because
197 // projects like the Linux kernel are relying on this behavior. If we don't
198 // explicitly zero initialize them, the undef values can be optimized to
199 // return garbage data. We also choose to zero initialize paddings for
200 // aggregates and unions, no matter they are initialized by empty
201 // initializers or non empty initializers. This can provide a consistent
202 // behavior. So projects like the Linux kernel can rely on it.
203 return !getLangOpts().CPlusPlus;
204 }
205
206 llvm::StringMap<unsigned> cgGlobalNames;
207 std::string getUniqueGlobalName(const std::string &baseName);
208
209 /// Return the mlir::Value for the address of the given global variable.
210 /// If Ty is non-null and if the global doesn't exist, then it will be created
211 /// with the specified type instead of whatever the normal requested type
212 /// would be. If IsForDefinition is true, it is guaranteed that an actual
213 /// global with type Ty will be returned, not conversion of a variable with
214 /// the same mangled name but some other type.
215 mlir::Value
216 getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
217 ForDefinition_t isForDefinition = NotForDefinition);
218
219 /// Return the mlir::GlobalViewAttr for the address of the given global.
220 cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d);
221
223 const CXXRecordDecl *derivedClass,
224 llvm::iterator_range<CastExpr::path_const_iterator> path);
225
226 /// Get the CIR attributes and calling convention to use for a particular
227 /// function type.
228 ///
229 /// \param calleeInfo - The callee information these attributes are being
230 /// constructed for. If valid, the attributes applied to this decl may
231 /// contribute to the function attributes and calling convention.
233 mlir::NamedAttrList &attrs);
234
235 /// Will return a global variable of the given type. If a variable with a
236 /// different type already exists then a new variable with the right type
237 /// will be created and all uses of the old variable will be replaced with a
238 /// bitcast to the new variable.
240 mlir::Location loc, llvm::StringRef name, mlir::Type ty,
241 cir::GlobalLinkageKind linkage, clang::CharUnits alignment);
242
243 void emitVTable(const CXXRecordDecl *rd);
244
245 /// Return the appropriate linkage for the vtable, VTT, and type information
246 /// of the given class.
247 cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd);
248
249 /// Get the address of the RTTI descriptor for the given type.
250 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty,
251 bool forEH = false);
252
253 /// Return a constant array for the given string.
254 mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
255
256 /// Return a global symbol reference to a constant array for the given string
257 /// literal.
258 cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s,
259 llvm::StringRef name = ".str");
260
261 /// Return a global symbol reference to a constant array for the given string
262 /// literal.
263 cir::GlobalViewAttr
265 llvm::StringRef name = ".str");
266
267 /// Set attributes which are common to any form of a global definition (alias,
268 /// Objective-C method, function, global variable).
269 ///
270 /// NOTE: This should only be called for definitions.
271 void setCommonAttributes(GlobalDecl gd, mlir::Operation *op);
272
274
275 /// Helpers to convert the presumed location of Clang's SourceLocation to an
276 /// MLIR Location.
277 mlir::Location getLoc(clang::SourceLocation cLoc);
278 mlir::Location getLoc(clang::SourceRange cRange);
279
280 /// Return the best known alignment for an unknown pointer to a
281 /// particular class.
283
284 /// FIXME: this could likely be a common helper and not necessarily related
285 /// with codegen.
287 LValueBaseInfo *baseInfo);
288
289 /// TODO: Add TBAAAccessInfo
291 const CXXRecordDecl *baseDecl,
292 CharUnits expectedTargetAlign);
293
294 /// Returns the assumed alignment of a virtual base of a class.
296 const CXXRecordDecl *derived,
297 const CXXRecordDecl *vbase);
298
299 cir::FuncOp
301 const CIRGenFunctionInfo *fnInfo = nullptr,
302 cir::FuncType fnType = nullptr, bool dontDefer = false,
303 ForDefinition_t isForDefinition = NotForDefinition) {
304 return getAddrAndTypeOfCXXStructor(gd, fnInfo, fnType, dontDefer,
305 isForDefinition)
306 .second;
307 }
308
309 std::pair<cir::FuncType, cir::FuncOp> getAddrAndTypeOfCXXStructor(
310 clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo = nullptr,
311 cir::FuncType fnType = nullptr, bool dontDefer = false,
312 ForDefinition_t isForDefinition = NotForDefinition);
313
314 mlir::Type getVTableComponentType();
315 CIRGenVTables &getVTables() { return vtables; }
316
318 return vtables.getItaniumVTableContext();
319 }
321 return vtables.getItaniumVTableContext();
322 }
323
324 /// This contains all the decls which have definitions but which are deferred
325 /// for emission and therefore should only be output if they are actually
326 /// used. If a decl is in this, then it is known to have not been referenced
327 /// yet.
328 std::map<llvm::StringRef, clang::GlobalDecl> deferredDecls;
329
330 // This is a list of deferred decls which we have seen that *are* actually
331 // referenced. These get code generated when the module is done.
332 std::vector<clang::GlobalDecl> deferredDeclsToEmit;
334 deferredDeclsToEmit.emplace_back(GD);
335 }
336
338
339 /// Determine whether the definition must be emitted; if this returns \c
340 /// false, the definition can be emitted lazily if it's used.
341 bool mustBeEmitted(const clang::ValueDecl *d);
342
343 /// Determine whether the definition can be emitted eagerly, or should be
344 /// delayed until the end of the translation unit. This is relevant for
345 /// definitions whose linkage can change, e.g. implicit function
346 /// instantiations which may later be explicitly instantiated.
348
349 bool verifyModule() const;
350
351 /// Return the address of the given function. If funcType is non-null, then
352 /// this function will use the specified type if it has to create it.
353 // TODO: this is a bit weird as `GetAddr` given we give back a FuncOp?
354 cir::FuncOp
355 getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType = nullptr,
356 bool forVTable = false, bool dontDefer = false,
357 ForDefinition_t isForDefinition = NotForDefinition);
358
359 mlir::Operation *
361 ForDefinition_t isForDefinition = NotForDefinition);
362
363 // Return whether RTTI information should be emitted for this target.
364 bool shouldEmitRTTI(bool forEH = false) {
365 return (forEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
366 !(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
367 getTriple().isNVPTX());
368 }
369
370 /// Emit type info if type of an expression is a variably modified
371 /// type. Also emit proper debug info for cast types.
373 CIRGenFunction *cgf = nullptr);
374
375 /// Emit code for a single global function or variable declaration. Forward
376 /// declarations are emitted lazily.
378
379 void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op,
380 GlobalDecl aliasGD, cir::FuncOp aliasee,
381 cir::GlobalLinkageKind linkage);
382
383 mlir::Type convertType(clang::QualType type);
384
385 /// Set the visibility for the given global.
386 void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const;
387 void setDSOLocal(mlir::Operation *op) const;
388 void setDSOLocal(cir::CIRGlobalValueInterface gv) const;
389
390 /// Set visibility, dllimport/dllexport and dso_local.
391 /// This must be called after dllimport/dllexport is set.
392 void setGVProperties(mlir::Operation *op, const NamedDecl *d) const;
393 void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const;
394
395 /// Set function attributes for a function declaration.
396 void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f,
397 bool isIncompleteFunction, bool isThunk);
398
400 mlir::Operation *op = nullptr);
401 void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
403 bool isTentative = false);
404
406
407 // C++ related functions.
408 void emitDeclContext(const DeclContext *dc);
409
410 /// Return the result of value-initializing the given type, i.e. a null
411 /// expression of the given type.
412 mlir::Value emitNullConstant(QualType t, mlir::Location loc);
413
414 llvm::StringRef getMangledName(clang::GlobalDecl gd);
415
416 void emitTentativeDefinition(const VarDecl *d);
417
418 // Make sure that this type is translated.
419 void updateCompletedType(const clang::TagDecl *td);
420
421 // Produce code for this constructor/destructor. This method doesn't try to
422 // apply any ABI rules about which other constructors/destructors are needed
423 // or if they are alias to each other.
425
426 bool supportsCOMDAT() const;
427 void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op);
428
429 static void setInitializer(cir::GlobalOp &op, mlir::Attribute value);
430
431 void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old,
432 cir::FuncOp newFn);
433
434 cir::FuncOp
435 getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType,
436 clang::GlobalDecl gd, bool forVTable,
437 bool dontDefer = false, bool isThunk = false,
438 ForDefinition_t isForDefinition = NotForDefinition,
439 mlir::ArrayAttr extraAttrs = {});
440
441 cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name,
442 cir::FuncType funcType,
443 const clang::FunctionDecl *funcDecl);
444
445 /// Given a builtin id for a function like "__builtin_fabsf", return a
446 /// Function* for "fabsf".
447 cir::FuncOp getBuiltinLibFunction(const FunctionDecl *fd, unsigned builtinID);
448
449 mlir::IntegerAttr getSize(CharUnits size) {
450 return builder.getSizeFromCharUnits(size);
451 }
452
453 /// Emit any needed decls for which code generation was deferred.
454 void emitDeferred();
455
456 /// Helper for `emitDeferred` to apply actual codegen.
457 void emitGlobalDecl(const clang::GlobalDecl &d);
458
459 const llvm::Triple &getTriple() const { return target.getTriple(); }
460
461 // Finalize CIR code generation.
462 void release();
463
464 /// -------
465 /// Visibility and Linkage
466 /// -------
467
468 static mlir::SymbolTable::Visibility
469 getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK);
470 static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(
471 clang::VisibilityAttr::VisibilityType visibility);
472 cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl);
473 cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd);
474 static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op);
475 cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd,
476 GVALinkage linkage,
477 bool isConstantVariable);
478 void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f) {
479 cir::GlobalLinkageKind l = getFunctionLinkage(gd);
480 f.setLinkageAttr(cir::GlobalLinkageKindAttr::get(&getMLIRContext(), l));
481 mlir::SymbolTable::setSymbolVisibility(f,
483 }
484
485 cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd,
486 bool isConstant);
487
488 void addReplacement(llvm::StringRef name, mlir::Operation *op);
489
490 /// Helpers to emit "not yet implemented" error diagnostics
491 DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
492
493 template <typename T>
494 DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
495 const T &name) {
496 unsigned diagID =
497 diags.getCustomDiagID(DiagnosticsEngine::Error,
498 "ClangIR code gen Not Yet Implemented: %0: %1");
499 return diags.Report(loc, diagID) << feature << name;
500 }
501
502 DiagnosticBuilder errorNYI(mlir::Location loc, llvm::StringRef feature) {
503 // TODO: Convert the location to a SourceLocation
504 unsigned diagID = diags.getCustomDiagID(
505 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
506 return diags.Report(diagID) << feature;
507 }
508
509 DiagnosticBuilder errorNYI(llvm::StringRef feature) const {
510 // TODO: Make a default location? currSrcLoc?
511 unsigned diagID = diags.getCustomDiagID(
512 DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
513 return diags.Report(diagID) << feature;
514 }
515
516 DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
517
518 template <typename T>
519 DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
520 const T &name) {
521 return errorNYI(loc.getBegin(), feature, name) << loc;
522 }
523
524private:
525 // An ordered map of canonical GlobalDecls to their mangled names.
526 llvm::MapVector<clang::GlobalDecl, llvm::StringRef> mangledDeclNames;
527 llvm::StringMap<clang::GlobalDecl, llvm::BumpPtrAllocator> manglings;
528
529 // FIXME: should we use llvm::TrackingVH<mlir::Operation> here?
530 typedef llvm::StringMap<mlir::Operation *> ReplacementsTy;
531 ReplacementsTy replacements;
532 /// Call replaceAllUsesWith on all pairs in replacements.
533 void applyReplacements();
534
535 /// A helper function to replace all uses of OldF to NewF that replace
536 /// the type of pointer arguments. This is not needed to tradtional
537 /// pipeline since LLVM has opaque pointers but CIR not.
538 void replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF);
539
540 void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op);
541
542 /// Map source language used to a CIR attribute.
543 std::optional<cir::SourceLanguage> getCIRSourceLanguage() const;
544};
545} // namespace CIRGen
546
547} // namespace clang
548
549#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
Defines the SourceManager interface.
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
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.
Abstract information about a function or function prototype.
Definition CIRGenCall.h:27
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)
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
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
void emitTopLevelDecl(clang::Decl *decl)
CharUnits getDynamicOffsetAlignment(CharUnits actualBaseAlign, const CXXRecordDecl *baseDecl, CharUnits expectedTargetAlign)
TODO: Add TBAAAccessInfo.
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
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.
mlir::IntegerAttr getSize(CharUnits size)
DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature, const T &name)
CIRGenBuilderTy & getBuilder()
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()
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
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
CharUnits getVBaseAlignment(CharUnits derivedAlign, const CXXRecordDecl *derived, const CXXRecordDecl *vbase)
Returns the assumed alignment of a virtual base of a class.
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
const clang::TargetInfo & getTarget() const
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
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)
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
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
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
const clang::LangOptions & getLangOpts() const
void addDeferredDeclToEmit(clang::GlobalDecl GD)
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)
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
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
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
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage, bool isConstantVariable)
mlir::MLIRContext & getMLIRContext()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
DiagnosticBuilder errorNYI(llvm::StringRef feature) const
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)
CIRGenCXXABI & getCXXABI() const
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)
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd, bool isConstant)
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
CIRGenVTables & getVTables()
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
std::vector< clang::GlobalDecl > deferredDeclsToEmit
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
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.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:231
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...
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:3714
Exposes information about the current target.
Definition TargetInfo.h:226
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.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition Linkage.h:72
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.