Thanks to visit codestin.com
Credit goes to clang.llvm.org

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